Question: JAVA Modify the HashTable class, implementing a double hashing function to help reduce collisions. Here is the code: public class HashTable { private int key;

JAVA

Modify the HashTable class, implementing a double hashing function to help reduce collisions.

Here is the code:

public class HashTable { private int key; private string value; HashEntry(int key, string value) { this.key = key; this.value = value; } public int getKey() { return key; } public string getValue() { return value; } }

public class HashMap { private final static int TABLE_SIZE = 128; HashEntry[] table; HashMap() { table = new HashEntry[TABLE_SIZE]; for (int i = 0; i < TABLE_SIZE; i++) table[i] = null; } public int get(int key) { int hash = (key % TABLE_SIZE); while (table[hash] != null && table[hash].getKey() != key) hash = (hash + 1) % TABLE_SIZE; if (table[hash] == null) return -1; else return table[hash].getValue(); } public void put(int key, string value) { int hash = (key % TABLE_SIZE); while (table[hash] != null && table[hash].getKey() != key) hash = (hash + 1) % TABLE_SIZE; table[hash] = new HashEntry(key, value); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!