散列函数的三种简单实现

散列函数一

unsigned int Hash(const char *Key,int TableSize)
{
	unsigned int HashVal = 0;
	while(*Key != '')
		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 != '')
		HashVal = (HashVal << 5) + *Key++;
	return HashVal % TableSize;
}
原文地址:https://www.cnblogs.com/y3w3l/p/6364748.html