实例一:
int hash(const char* str, int M)
{
int i, l = (strlen(str)+1) / 2;
unsigned int ret = 0;
unsigned short *s = (unsigned short*)str;
for (i = 0; i < l; i++)
{
ret ^= (s[i] << (i & 0x0F));
}
return ret % M;
}
实例二: Follow/Noll/Vo Hash
inline uint32_t hash_value(uint8_t *key,uint32_t len)
{
uint32_t hash_value_ = 0;
uint8_t *begin = key;
uint8_t *end = ken+len;
for(hash_value_ = 0; begin < end; ++begin)
{
hash_value_ *= 16777619;
hash_value_ ^= (uint32_t)*begin;
}
return hash_value_;
}
int BKDRHash(char * str)
{
unsigned int seed = 13131313; /* 31 131 1313 13131 131313 etc.. */
unsigned int hash = 0;
while (*str)
{
hash = hash * seed + (*str++);
}
return (hash & 0x7FFFFFFF);
}