/* HashTableChained.java */ package dict; /** * HashTableChained implements a Dictionary as a hash table with chaining. * All objects used as keys must have a valid hashCode() method, which is * used to determine which bucket of the hash table an item is stored in. * Each object's hashCode() is presumed to return an int between * Integer.MIN_VLAUE and Integer.MAX_VALUE; the code herein hashes the hash * code to select a bucket within the table's range. * * DO NOT CHANGE ANY PROTOTYPES IN THIS FILE. **/ public class HashTableChained implements Dictionary { /** * Place any data fields here. **/ /** * Construct a new hash table intended to hold roughly sizeEstimate items. * (The precise number of buckets is up to you, but we recommend you use * a prime number, and shoot for a load factor between 0.5 and 1.) **/ public HashTableChained(int sizeEstimate) { // Your solution here. } /** * Construct a new hash table with a default size. **/ public HashTableChained() { // Your solution here. } /** * Converts a hash code in the range Integer.MIN_VALUE...Integer.MAX_VALUE * to a value in the range 0...size of hash table - 1. * * This function should have package protection (so we can test it), and * should be used by insert, find, and remove. **/ int compFunction(int code) { // Replace the following line with your solution. return 88; } /** * Returns the number of items stored in the dictionary, where each item * is counted according to its multiplicity. * @return number of items in the dictionary. **/ public int size() { // Replace the following line with your solution. return 0; } /** * Tests if the dictionary is empty. * * @return true if the dictionary has no items, false otherwise. **/ public boolean isEmpty() { // Replace the following line with your solution. return true; } /** * Insert an item (a key and an associated element). Multiple items with * the same key can coexist in the dictionary. * * @param key the key by which the item can be retrieved. * @param element an arbitrary object. **/ public void insert(Object key, Object element) { // Your solution here. } /** * Search for an item with the specified key. If such an item is found, * return its element; otherwise return the special element NO_SUCH_KEY. * If several items have the specified key, one is chosen arbitrarily and * returned. * * @param key the search key. * @return element an element associated with the key, or NO_SUCH_KEY if no * item is associated with the specified key. **/ public Object find(Object key) { // Replace the following line with your solution. return null; } /** * Remove an item with the specified key. If such an item is found, return * its element and remove it from the table; otherwise return the special * element NO_SUCH_KEY. If several items have the specified key, one * is chosen arbitrarily, removed, and returned. * * @param key the search key. * @return element an element associated with the key, or NO_SUCH_KEY if no * item is associated with the specified key. */ public Object remove(Object key) { // Replace the following line with your solution. return null; } /** * Remove all items from the dictionary. */ public void makeEmpty() { // Your solution here. } }