哈希桶用于哈希冲突的解决,也叫做开链法或拉链法。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template<class K, class V>
struct HashBucketNode
{
K _key;
V _value;
HashBucketNode<K, V>* _next;
HashBucketNode(const K& key, const V& value)
:_key(key)
,_value(value)
,_next(NULL)
{}
};
template<class K>
struct __HashFunc
{
size_t operator()(const K& key)
{
return key;
}
};
//特化
template<>
struct __HashFunc<string>
{
static size_t BKDRHash(const char*str)
{
unsigned int seed= 131;// 31 131 1313 13131 131313
unsigned int hash= 0;
while(*str)
{
hash = hash * seed + (*str++);
}
re