散列函数的三种简单实现

散列函数一

unsigned int Hash(const char *Key,int TableSize)
{
	unsigned int HashVal = 0;
	while(*Key != '\0')
		HashVal += *Key++;
	return HashVal % TableSize;
}

散列函数二

unsigned int Hash(const char *Key,int TableSize)
{
	return (Key[0] + 27*Key[1]+729*Key[2]) % TableSize;
}

散列函数三

unsigned int Hash(const char *Key,int TableSize)
{
	unsigned int HashVal = 0;
	while(*Key != '\0')
		HashVal = (HashVal << 5) + *Key++;
	return HashVal % TableSize;
}
posted @ 2017-02-04 13:39  梁月唯  阅读(303)  评论(0编辑  收藏  举报