将字符串Hash成整型存储经常用到BKDRHash算法
uint64_t BKDRHash(const char *pszKey)
{
uint64_t seed = 131;
register uint64_t uCode=0;
while(pszKey[0])
{
uCode = uCode *seed + (unsigned char)pszKey[0];
pszKey++;
}
return uCode;
}
选择了64位的key,减少冲突的概率。
将字符串Hash成整型存储经常用到BKDRHash算法
uint64_t BKDRHash(const char *pszKey)
{
uint64_t seed = 131;
register uint64_t uCode=0;
while(pszKey[0])
{
uCode = uCode *seed + (unsigned char)pszKey[0];
pszKey++;
}
return uCode;
}
选择了64位的key,减少冲突的概率。
转载于:https://www.cnblogs.com/gmark/archive/2012/12/21/2827407.html