Question: Can you implement MyMap using open addressing with linear probing. Create a new concrete class named MyHashMap that implements MyMap using open addressing with linear
Can you implement MyMap using open addressing with linear probing. Create a new concrete class named MyHashMap that implements MyMap using open addressing with linear probing. For simplicity, use fkey key size as the hash function, where size is the hashtable size. Initially, the hashtable size is The table size is doubled whenever the load factor exceeds the threshold
Modify TestMyHashMap.java slightly and use it to test MyHashMap. Your output should be as follows:
Entries in map: LewisCookAndersonSmith
The age for Lewis is
Is Smith in the map? true
Is age in the map? false
Entries in map after removing Smith: LewisCookAnderson
Entries after clearing map:
TestMyHashMap class:
public class TestMyHashMap
public static void mainString args
Create a map
MyMap map new MyHashMap;
map.putSmith;
map.putAnderson;
map.putLewis;
map.putCook;
map.putSmith; Add Smith with age to map
System.out.printlnEntries in map: map;
System.out.printlnThe age for "Lewis is
map.getLewis;
System.out.printlnIs Smith in the map?
map.containsKeySmith;
System.out.printlnIs age in the map?
map.containsValue;
map.removeSmith; Remove Smith from map
System.out.printlnEntries in map: map;
map.clear;
System.out.printlnEntries in map: map;
MyMap class:
public interface MyMap
Remove all of the entries from this map
public void clear;
Return true if the specified key is in the map
public boolean containsKeyK key;
Return true if this map contains the specified value
public boolean containsValueV value;
Return a set of entries in the map
public java.util.Set entrySet;
Return the first value that matches the specified key
public V getK key;
Return true if this map contains no entries
public boolean isEmpty;
Return a set consisting of the keys in this map
public java.util.Set keySet;
Add an entry key value into the map
public V putK key, V value;
Remove the entries for the specified key
public void removeK key;
Return the number of mappings in this map
public int size;
Return a set consisting of the values in this map
public java.util.Set values;
Define inner class for Entry
public static class Entry
K key;
V value;
public EntryK key, V value
this.key key;
this.value value;
public K getKey
return key;
public V getValue
return value;
@Override
public String toString
return key value ;
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
