hash table(开放寻址法-双重散列实现的哈希表)
#ifndef C11LEARN_HASHDOUBLE_H
#define C11LEARN_HASHDOUBLE_H
#include "HashLiner.h"
template<typename T>
class HashDouble:public HashLiner<T>{
protected:virtual int hashing(int key,int index);virtual int auxiliary_hashing2(int key);
};template<typename T>
int HashDouble<T>::hashing(int key,int index){return (HashLiner<T>::auxiliary_hashing(key) + index * auxiliary_hashing2(index))%HashLiner<T>::capacity;
}
template<typename T>
int HashDouble<T>::auxiliary_hashing2(int key){return key%2 == 0?key+1:key;
}
#endif //C11LEARN_HASHDOUBLE_H
测试代码
HashDouble<string> hashDouble;hashDouble[2] = "hello";hashDouble[123456] = "world";cout << hashDouble[2] << endl;cout << hashDouble[123456] << endl;HashDouble<string> hashDouble1 = hashDouble;cout << hashDouble1[2] << endl;cout << hashDouble1[123456] << endl;HashDouble<string> hashDouble2;hashDouble2 = hashDouble;cout << hashDouble2[2] << endl;cout << hashDouble2[123456] << endl;
辅助类
HashLiner地址链接