What would a compress method do in a hash table?
        Posted  
        
            by 
                Bradley Oesch
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Bradley Oesch
        
        
        
        Published on 2012-10-02T03:33:42Z
        Indexed on 
            2012/10/02
            3:37 UTC
        
        
        Read the original article
        Hit count: 196
        
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?
© Stack Overflow or respective owner