package cop3530; public interface MyHashTableand:{ void insert (AnyType x); void remove (AnyType x); boolean contains (AnyType x); boolean isEmpty ( ); void makeEmpty ( ); void showLengthDist ( ); }
package cop3530; public interface HashFunctionThe two classes SeparateChainingHashTable and TwoChoiceChainingHashTable should implement the interface MyHashTable and they would look like this:{ int hashCode( AnyType x ); }
package cop3530; public class SeparateChainingHashTableand:> implements MyHashTable { public SeparateChainingHashTable( int size ) { /* Implement */ } public void showLengthDist( ) { /* Implement */ } /* Implement other public methods from interface here */ private int myhash( AnyType x ) /* Figure 5.7 from Weiss' book */ private List [ ] theLists; private int currentSize; }
package cop3530; public class TwoChoiceChainingHashTableYou must use the following implementation for the second hash function to be used by the class TwoChoiceChainingHashTable:> implements MyHashTable { public TwoChoiceChainingHashTable(int size, HashFunction hash2 ) { /* Implement */ } /* Implement public methods from interface here */ private int myhash( AnyType x ) /* Figure 5.7 from Weiss' book */ /* To be used as the first hash function */ private List [ ] theLists; private int currentSize; private HashFunction hash2; }
package cop3530; public class hashF2Duplicates should not be inserted. It should merely elicit an error message before moving on to the next command. The implementation of the method toString and the Iterator are optional. If the contains method is invoked on an empty MyHashTable, then you should simply return false. The output format for the method showLengthDist should be as shown below in the sample output:implements HashFunction { public int hashCode( AnyType key ) { return key.hashCode() * key.hashCode(); } }
Hash Table Size = 43 Number of items in Table = 192 Average chain length = 4.46 Maximum chain length = 14 Standard Deviation = 2.36 -------------------------------As in the previous assignment, the test program will be provided as a .class file, without any Java source, so it is important that you write sufficient test cases on your own to convince yourself that your logic works.
Assignments/ build/ classes/ cop3530/ MyHashTable.class HashFunction.class SeparateChainingHashTable.class TwoChoiceChainingHashTable.class TestForAssign4.class src/ cop3530/ MyHashTable.java HashFunction.java SeparateChainingHashTable.java TwoChoiceChainingHashTable.javaNow open a shell window or a command prompt window, cd to directory classes mentioned above, and run the following command from the command line:
java -cp . TestForAssign4The option -cp . suggests that the classpath is at . (i.e., the current directory). Remember not to include .class when referring to your tester class.