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 함수에 있으며 세 개의 키가 있다는 것을 알 수 있습니다. 내 함수는 해시를위한 좋은 알고리즘이며 어떻게 함수를 개선하고 충돌 수를 줄일 수 있습니까? 나는 몇 가지 제안을내 해시 알고리즘을 개선하는 방법
지금까지 해시 함수에 어떤 문제가 있습니까? 당신이 그것을 바꿀 필요가 있다고 의심할만한 이유가 있습니까? – templatetypedef
해시 함수가 좋습니다. 하지만 당신은 C++을 사용하고 있는데 왜 stl을 사용하지 않습니까? –
나는 그것을 향상시킬 수 있는지 알고 싶어하고 좋은 기능인지 아닌지 잘 모른다. – peaceman