Implementing HashMap: Avoid collisions caused by compress function : <p>I'm implementing a hashmap to contain all words in a word file (e.g <code>dictionary.txt</code>, <code>bible.txt</code>) and I am having a collision problem. I know that there are many good hash functions out there but when I try compressing the hash code using this compression function, the number of collisions raises significantly (I'm using <a href="http://www.cse.yorku.ca/~oz/hash.html" rel="nofollow noreferrer" title="dbj2">dbj2</a> for my hash function).</p>

<p>My hashmap basically converts a key to its hash value and compresses that hash value to the index of the entry in the internal hash table, which is an array. It resizes itself to <code>2 * capacity - 1</code> if the <code>load factor</code> of <code>0.5</code> is reached. When collisions happen, my hashmap generates new indexes using quadratic probing.</p>

<p>This is what my current compress function looks like:</p>

<pre><code>private int compress(int hashCode) {
    return Math.abs(hashCode) % capacity;
}
</code></pre>

<p>Is there any (efficient) way I can do to avoid collisions? Changing the structure of the hashmap itself is also accepted.</p>
