QUESTION 24 Map that implements a linear probe hash-based map. This class contai
ID: 3721548 • Letter: Q
Question
QUESTION 24 Map that implements a linear probe hash-based map. This class contains three member variables (N. M. and entries), as well as a Entry Consider writing a class called L class that pairs Keys and Values. Implement the put() method shown below. Do not use the other Map methods (e.g. get, contains, remove) when implementing put). It must be self-contained. (Hint remember that every object in Java will have a hashcode0 method available on it) publie class LinearBrobingMapimplements MapKKey, Valu private class EntrycEncrykey, Enryvalue> pablie Entrykey key: pablie Enryvalue value public Entry (Encrykey key. EntryValue value this.keyke this,valu? value : private int : / number of elements private int : 1/ size of hash table private Entryckey, Value eneries: //arzay of entries entziesew Entry[] * Puts ? key-ralue psar ?to the map eparam key Key to use void put (Rey key, Value val) IMPLEHENT THISExplanation / Answer
public class HashTable<Key, Value> {
private class HashTableNode {
private Key key;
private Value value;
private boolean active;
private boolean tombstoned;
public HashTableNode() {
key = null;
value = null;
active = false;
tombstoned = false;
}
public HashTableNode(Key initKey, Value initData) {
key = initKey;
value = initData;
active = true;
tombstoned = false;
}
}
private final static int TABLE_SIZE = 9;
private Object[] table;
public HashTable() {
table = new Object[TABLE_SIZE];
for (int j = 0; j < TABLE_SIZE; j++)
table[j] = new HashTableNode();
}
public Value put(Key key, Value value)
private static int TABLE_SIZE = 309;
public int hashCode(String s) {
if(s.length() == 0)
return 0;
int sum = 0;
int n = s.length();
for(int i = 0; i < n-1; i++) {
sum += s.charAt(i)*(int)Math.pow(31, n-i-1);
}
sum += s.charAt(n-1);
return index = Math.abs(sum) % TABLE_SIZE;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.