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. ...

Get Beginning Java Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.