Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. Enrolling employees in courses and programs.

Answered: 1 week ago

Question

1. Communicating courses and programs to employees.

Answered: 1 week ago

Question

6. Testing equipment that will be used in instruction.

Answered: 1 week ago