Implementing the Multiplication Method for a Hash Table

The aim here is to develop a code in Java for implementing the multiplication method for a hash table.

Perform the following steps:

  1. Implement a class with a method which accepts an integer and returns a hash value using the multiplication method shown in this section. The constant k is passed in as the class constructor. The method signature should be:
 int hashKey(int key, int tableSize) 
  1. The following code shows an implementation for the multiplication hash function:
private double k;
public MultiplicationHashing(double k) {
this.k = k;
}
public int hashKey(Integer key, int tableSize) {
return (int) (tableSize * (k * key % 1));
}
Snippet 3.6: Solution for the multiplication method. Source class name: MultiplicationHashing.

Go to https://goo.gl/xJ7i1b to access this code.

In this section, we have seen two basic techniques on how to compute hash values, the remainder method and the multiplication method. Both of these strategies are widely used in hash tables.

In the next section, we will examine yet another mechanism, called universal hashing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.158.165