Question: Java The method enlargeHashTable does not retain the instances of Entry that were in the old hash table. It could if the method add had
Java
The method enlargeHashTable does not retain the instances of Entry that were in the old hash table. It could if the method add had an entry as its parameter instead of the search key and value. Write such a method as an additional but private add method, and then revise enlargeHashTable so it retains the instances of Entry that were in the old hash table.
Old add method:
public V addK key, V value
if key nullvalue null
throw new NoSuchElementExceptionKey or value not found.";
int index getHashIndexkey;
V oldValue;
if containskey
hashTableindex new Entrykey value;
numberOfEntries;
oldValue null;
else
oldValue hashTableindexgetValue;
hashTableindexsetValuevalue;
if isHashTableTooFull
enlargeHashTable;
return oldValue;
private void enlargeHashTable
Entry oldTable hashTable;
int oldSize hashTable.length;
int newSize getNextPrimeoldSize oldSize;
checkSizenewSize;
Entry temp Entry new EntrynewSize;
hashTable temp;
numberOfEntries ;
for int index ; index oldSize; index
if oldTableindex null && oldTableindex AVAILABLE
addoldTableindexgetKey oldTableindexgetValue;
end for
end enlargeHashTable
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
