- Jul 23, 2006
- 3,934
- 0
- 76
A couple weeks ago I did an assignment that involved making a phone book out of a BST. Now the assignement is to modify that program to take use a hash table, and we have to make that hash table. The small part he gave us has it as a template class that takes two data types, a KeyType and a DataType (this is the same way our BST was defined). So in the phonebook, the KeyType is int (phone number) and the DataType is a struct containing things like Address and Name etc.
My question is mainly about the hashing function, and how to get it to work properly with this data type. I'm aware of how my classmates are doing it, and they're pretty much all doing index = phone_number % table_capacity, and sure that gets the job done, but if you would try to reuse this class, and define KeyType as anything but int it's not going to compile. So is there a good way of implementing a hashing function that will work for any generic type?
My question is mainly about the hashing function, and how to get it to work properly with this data type. I'm aware of how my classmates are doing it, and they're pretty much all doing index = phone_number % table_capacity, and sure that gets the job done, but if you would try to reuse this class, and define KeyType as anything but int it's not going to compile. So is there a good way of implementing a hashing function that will work for any generic type?