stper** pages;
int tableSize;
struct Person{
string name;
int age;
string homeTown;
};
void fonk1 (int numberOfBuckets)
{
pages = new stper*[numberOfBuckets]();
tableSize = numberOfBuckets;
}
int hashPerson(Person& person)
{
int hashVal = 0;
for (int i=0; i < (person.getName()).length() ; i++)
hashVal = 37*hashVal + (person.getName())[i];
for (int i=0; i < (person.getHomeTown()).length() ; i++)
hashVal = 37*hashVal + (person.getHomeTown())[i];
hashVal+= person.getAge();
hashVal %= tableSize;
if(hashVal < 0)
hashVal += tableSize;
return hashVal;
}
大家好,我是哈希新手。我的散列函数在 hashPerson 函数的上面,你可以看到有三个键。我的函数是一个很好的散列算法吗?如何改进函数并减少碰撞次数?(如有语法错误请忽略)