I am trying to implement a hash set but I have some trouble for the hash function. I want to add in the set, persons that have name and phone number:
class Person{
string name;
long long int phoneNumber;
}
And my indexes in the set are calculated by summing the digits of the phoneNumber. The problem is that I dont want my functions to be something like this:
int add(long long int nr, Element e) - the function that adds an Element to the set
{
int hashCode = hash(nr);;
...
}
where the long long int nr
should be the phoneNumber and Element e
should be the Person. I mean, it's pretty stupid. If I already have the person as parameter, why have it's phoneNumber too? As you can see I am using templates, and my teacher advised me to do a virtual class for the hashFunction to force it to be the respective type(something like the HashSet in Java). The thing is I have NO IDEA how to do that. Do you have any ideas that could help me?