如何理解下列函数,分析其功能,思考可否应用该函数实现某班同学的分组。 Hash函数的代码如下:
const int HASHSIZE = 10;
unsigned Hash(char* s)
{
unsigned hashValue;
for (hashValue = 0; *s != '\0'; ++s)
hashValue = *s + 31 * hashValue;
return hashValue % HASHSIZE;
}
如何理解下列函数,分析其功能,思考可否应用该函数实现某班同学的分组。 Hash函数的代码如下:
const int HASHSIZE = 10;
unsigned Hash(char* s)
{
unsigned hashValue;
for (hashValue = 0; *s != '\0'; ++s)
hashValue = *s + 31 * hashValue;
return hashValue % HASHSIZE;
}