Question: Hello who can help me with this program . we have to make our own Hash map class with buckets . Here is the Code

Hello who can help me with this program . we have to make our own Hash map class with buckets .

Here is the Code :

we want you to take those ideas and extend them into a map implementation that can be used with arbitrary types for keys and values. Since there already is a HashMap class, your class will be called BrownieMap.

Create the class in a package called programming.set11.brownies. It should be a generic class that accepts two type parameters:

  • K is the type of the map's keys.
  • V is the type of the map's values.

Implement the following constructors and methods using the bucket hashing strategy:

/** * The capacity sets the length of the bucket array. * * @param numberOfBuckets * bucket array length * @throws IllegalArgumentException * if the number of buckets is smaller than one. */ public BrownieMap(int numberOfBuckets) { // Implement the constructor! } /** * Put an item into the map. * * @param key * the key of the item. * @param value * the value of the item. * @throws IllegalArgumentException * if the key or the value is {@code null}. */ public void put(K key, V value) { // Implement this! } /** * Returns the value of a given key. * * @param key * the key of the item. * @return the value belonging to that key or {@code null} if no value is mapped * to that key. * @throws IllegalArgumentException * if the key is {@code null}. */ public V get(K key) { // Implement me! return null; } /** * Removes one key and its value from the map. If the key does not exist in the * map, nothing happens. * * @param key * the key. * @throws IllegalArgumentException * if the key is {@code null}. */ public void remove(K key) { // Implement me! } /** * Clears the entire map. */ public void clear() { // Implement me! }

To get started, familiarize yourself with how the SimpleStringMap works that you saw in the lecture. In particular, you will want to implement some sort of class that represents an entry in your map. You can simply add that class to the same file as your map itself. However, you can also define the class as a private static entry of your map class.

Whatever you do, your entry class will be generic, which may cause a problem: you cannot create an array of a generic type in Java. However, there is a workaround. Remember our LinkedElement class. We can create an array of linked elements as follows:

LinkedElement[] elements = new LinkedElement[10];

Note that we omitted the type arguments when creating the array. Java will issue a warning there. If you end up in a similar situation, simply ignore that warning; your array will work just fine.

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!