Question: Please help with this JAVA program. It can only use Queue and LinkedList Packages . The Map Class interface is included. Thank you! Write a

Please help with this JAVA program. It can only use Queue and LinkedList Packages. The Map Class interface is included. Thank you!

Write a class called TwoProbeChainMap that implements a two-probe chaining hash-based map. Two- probe hashing means that you will hash to two positions, and insert the key in the shorter of the two chains at those two positions. The easiest way to implement this class is to spend some time understanding ChainMap, and then redesign it to use the two probe technique.

Proper hash calculations. ? For the rst hash function, use: hash(k)=(k.hashCode() & 0x7 f) % M.

? For the second hash function, use: hash2(k)= (((k.hashCode() & 0x7 f) % M) * 31) % M.void put(Key key, Value val) - see interface. [10 points] Value get(Key key) - see interface. void remove(Key key) - see interface.

Write a class called LinearProbingMap that implements a linear probe hash-based map.

Proper hash calculations.

? An decent way to structure the hash function is: hash(k, i) = ((k.hashCode() & 0x7 f) + i) % M, where k is the key and i is the number of collisions. Each time there is a collision, i should be incremented so that the hash increases by 1. An example hash sequence might look like: 587, 588, 589, 590, 581...

LinearProbingMap() - a constructor that defaults to an array of size 997 .

void put(Key key, Value val) - see interface.

Value get(Key key) - see interface.

void remove(Key key) - although the interface has this function, you are not required to implement it. [0 points]

boolean contains(Key key) - see interface. [3 points]

boolean isEmpty() - see interface. [3 points]

int size() - see interface. [3 points]

Iterable keys() - see interface. [3 points]

There is no requirement to support array resizing.

Both classes must implement the provided Map interface.

Do not import any packages other than Queue or LinkedList in your map implementations.

public interface Map { /** * Puts a key-value pair into the map. * * @param key Key to use. * @param val Value to associate. */ void put(Key key, Value val); /** * Gets the value paired with a key. If the key doesn't exist in map, * returns null. * * @param key Key to use. * @return Value associated with key. */ Value get(Key key); /** * Removes a key (and its associated value) from the map. * * @param key Key to use. */ void remove(Key key); /** * Checks if the map contains a particular key. * * @param key True if map contains key, false otherwise. * @return Result of check. */ boolean contains(Key key); /** * Returns true if there are no key-vale pairs stored in the map, and false * otherwise. * * @return True if map is empty, false otherwise. */ boolean isEmpty(); /** * Returns the number of key-value pairs in the map. * * @return Number of key-value pairs. */ int size(); /** * Returns an Iterable object containing all keys in the table. Keys not * guaranteed to be in any particular order. * * @return Iterable object containing all keys. */ Iterable keys(); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!