Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with this JAVA program. Write a class called LinearProbingMap that implements a linear probe hash-based map. Proper hash calculations. An decent way to

Please help with this JAVA program.

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.

boolean contains(Key key) - see interface.

boolean isEmpty() - see interface.

int size() - see interface.

Iterable keys() - see interface.

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.

Please find Map interface below

/** * Map interface. 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

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions