Question
// TO DO: add your implementation and JavaDocs. // ONLY need to implement these THREE METHODS: put(), get(), and delete() // Keep other code AS
// TO DO: add your implementation and JavaDocs.
// ONLY need to implement these THREE METHODS: put(), get(), and delete() // Keep other code AS IS but you will need to add JavaDocs
import java.util.Iterator;
public class ThreeTenHashMap
@Override public String toString(){ return "<"+key.toString()+","+value.toString()+">"; }
@Override @SuppressWarnings("unchecked") public boolean equals(Object o) { // return true if two pairs have matching keys // i.e. <"Alice", 1> is considered as equal to <"Alice", 2> if(o instanceof Pair) { Pair
@Override public int hashCode(){ //hashCode is determined by key only return key.hashCode(); } }
// This HashMap implementation uses an array of ThreeTenDLList // where each list will be composed of Node
// will fix the capacity to 11 final static private int DEFAULT_CAPACITY = 11;
// track how many elements in HashMap private int size; @SuppressWarnings("unchecked") public ThreeTenHashMap() { buckets = (ThreeTenDLList
public int size() { return size; }
private int capacity() { return buckets.length; }
private int getHash(K key) { return Math.abs(key.hashCode()); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (int i=0; i
} return "{" + sb.toString() + "}"; }
//****************************************************** //******* BELOW THIS LINE IS YOUR CODE ******* //******************************************************
// ADD PRIVATE METHODS HERE IF NEEDED! // YOU CANNOT ADD MORE DATA MEMBERS public void put(K key, V value) { // mapping key to value in the hashmap // - do not change hashmap for null key or null value // - if key is new, add a new entry (key, value) // - if key is present, make sure (key, value) is in record // Note: Implement the hash table with separate chaining. // - when a new (key,value) pair is added, add it to the end (tail) of the chain // O(load) on average, and O(n) worst case }
public V get(K key) { // return the current mapping of key // if key is null or not present, return null // // O(load) on average, and O(n) worst case
//default return, remove or update as needed return null; }
public V delete(K key){
// return the current mapping of key from hashmap and delete it // -if key is null or not present, return null // // O(load) on average, and O(n) worst case //default return, remove or update as needed return null; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started