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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started