What would a compress method do in a hash table?
- by Bradley Oesch
For an assignment I have to write the code for a generic Hash Table. In an example Put method, there are two lines:
int hash = key.hashCode(); // get the hashcode of the key
int index = compress(hash); // compress it to an index
I was of the understanding that the hashCode method used the key to return an index, and you would place the key/value pair in the array at that index. But here we "compress" the hash code to get the index. What does this method do? How does it "compress" the hash code? Is it necessary and/or preferred?