参考:https://en.wikipedia.org/wiki/List_of_hash_functions
fnv hash
返回值:一个 int
整数
unsigned int fnv_hash (void* key, int len)
{
unsigned char* p = key;
unsigned int h = 2166136261;
int i;
for (i = 0; i < len; i++)
h = (h*16777619) ^ p[i];
return h;
}
Jenkins hash function
uint32_t jenkins_one_at_a_time_hash(char *key, size_t len)
{
uint32_t hash, i;
for(hash = i = 0; i < len; ++i)
{
hash += key[i];
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
}
djb2
http://www.cse.yorku.ca/~oz/hash.html
unsigned long hash(unsigned char *str)
{
unsigned long hash = 5381;
int c;
while (c = *str++)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}
sdbm
unsigned long sdbm(unsigned char *str)
{
unsigned long hash = 0;
int c;
while (c = *str++)
hash = c + (hash << 6) + (hash << 16) - hash;
return hash;
}
lose lose
unsigned long hash(unsigned char *str)
{
unsigned int hash = 0;
int c;
while (c = *str++)
hash += c;
return hash;
}