BKDR Hash
unsigned int BKDRHash(char *str)
{
unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
unsigned int hash = 0;
while (*str)
{
hash = hash * seed + (*str++);
}
return (hash & 0x7FFFFFFF);
}
AP Hash
unsigned int APHash(char *str)
{
unsigned int hash = 0;
int i;
for (i=0; *str; i++)
{
if ((i & 1) == 0)
{
hash ^= ((hash << 7) ^ (*str++) ^ (hash >> 3));
}
else
{
hash ^= (~((hash << 11) ^ (*str++) ^ (hash >> 5)));
}
}
return (hash & 0x7FFFFFFF);
}
Universal Hash
UINT HashUniversal(const CHAR* key, SIZE_T len)
{
UINT hash = 0, a = 31415, b = 27183;
for(UINT i = 0; i < len; ++i)
{
hash = a * hash + key[i];
a *= b;
}
return hash;
}
unsigned int ReHashKey(char *key,int Level)
{
unsigned int a=31415,b=27183;
for(unsigned int vHash=0;*key;key++)
{
vHash=(a*vHash*Level+*key);
a*=b;
}
return vHash;
}
DJB Hash
unsigned int DJBHash(char *str)
{
unsigned int hash = 5381;
while (*str)
{
hash += (hash << 5) + (*str++);
}
return (hash & 0x7FFFFFFF);
}