Question: IHash has the interface to the hashing implementation, and HashTable is the file with your implementation. Implement all of the methods in the interface. Conceptually,
IHash has the interface to the hashing implementation, and HashTable is the file with your implementation. Implement all of the methods in the interface.
Conceptually,
Each hashTable is a table (implemented as an array list) indexed by hashCode % size.
Each entry in the table contains a hashBucket.
You will need to decide which data structure you wish to use for the hashBuckets. Good candidates include an ArrayList or LinkedList.
If you are ambitious, you may want to create a custom list class. Implement the methods in the interface to produce the data structure shown below, in which we used a LinkedList for each hashBucket, but you can use whatever you would like:
I needed help in implementing the methods
// HashInterface.java - interface for hashing assignment
// Author: Chris Wilcox/Fritz Sieker
// Date: 3/29/2017
// Class: CS165
// Email: wilcox@cs.colostate.edu
import java.util.Iterator;
public interface IHash {
/** Add a key to the hash table, if it is not currently in the table
* @param key - the key to add
* @return true on success, false on failure (duplicate)
*/
public abstract boolean insert(String key);
/** Remove a key from the hash table
* @param key - the key to remove
* @return true on success, false on failure (not in table)
*/
public abstract boolean remove(String key);
/** Search for a key in the hash table
* @param key - the key to search for
* @return the key on success, null on failure (not in table)
*/
public abstract String search(String key);
/** Get the number of elements in the hash table
* @return the number of elements in the table
*/
public abstract int size();
/** Get the number of elements in the hash table at the given index
* @param i the index in the hash table (0 to size-1)
* @return the size of the list in the ith bucket
*/
public abstract int size(int i);
/** Get an iterator that return the Strings stored in
* the hash table one at a time. The order should be in order of entries in
* the hash table itself and for a given bucket, the order in that list.
* @return an Interator
*/
public abstract Iterator
/** Get an iterator for the ith bucket
* @param i the index in the hash table (0 to size-1)
* @return null if the bucket is empty, otherwise an iterator for the bucket
*/
public abstract Iterator
/** Print the entire hash table.
*/
public abstract void print();
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
