[C/C++]BKDRHash

将字符串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,减少冲突的概率。

posted @ 2012-12-21 09:14  gmark  阅读(727)  评论(0)    收藏  举报