⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hashset.h

📁 用VC++6.0编写的各种算法大全
💻 H
字号:
// template hash set class

#ifndef  _HASHSET_H_ 
#define  _HASHSET_H_

#include <iostream>
#include <vector>
#include <algorithm>
#include <stdexcept>

using namespace std;

template<class key_type, class hash_func, class key_equal>
class  HashSet {

protected:
    // hashtable entries 
    class Entry {
        public:
        key_type key;
        bool used;

        Entry() : used(false) {}
    };

    int entries;      // number of entries
    int prime;        // index to size table

    vector<Entry> *ht;
    hash_func hf;        // hash function on key_type
    key_equal eq;        // equality predicate on key_type

    int table_size()  const {return prime_list[prime];}
    float load_factor() const {return float(size()) / table_size();}
    int resize();
    
public:

    HashSet()
		  : entries(0), prime(0), 
          ht(new vector<Entry>(prime_list[0]))
          {}
          
    virtual ~HashSet() { 
		delete ht;
	}

    virtual int size() const {return entries;}
    virtual bool search(const key_type& k);
    virtual void insert(const key_type& k);
    virtual void remove(const key_type& k);
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -