Question: HashTable help with 3 differnt HashType!! java! package hw5; public class HashTable implements IHashTable { //You will need a HashTable of LinkedLists. public enum HashType
HashTable help with 3 differnt HashType!! java!
package hw5;
public class HashTable implements IHashTable {
//You will need a HashTable of LinkedLists. public enum HashType { ONE, TWO, THREE }
private int nelems; //Number of element stored in the hash table private int expand; //Number of times that the table has been expanded private int collision; //Number of collisions since last expansion private String statsFileName; //FilePath for the file to write statistics upon every rehash private boolean printStats = false; //Boolean to decide whether to write statistics to file or not after rehashing private HashType type;
//You are allowed to add more :)
/** * Constructor for hash table * * @param size Initial dimensions of the hash table * @param type Specified hash function */ public HashTable(int size, HashType type) { //Initialize }
/** * Constructor for hash table * * @param size Initial dimensions of the hash table * @param type Specified hash function * @param fileName path to write file statistics */ public HashTable(int size, HashType type, String fileName) { //Set printStats to true and statsFileName to fileName }
@Override public boolean insert(String value) { return false; //TODO }
@Override public boolean delete(String value) { return false; //TODO }
@Override public boolean contains(String value) { return false; //TODO }
@Override public void printTable() { //TODO }
@Override public int getSize() { return 0; //TODO }
/** * This is a wrapper method to allow you to swap hash functions without * cluttering up your other code. * * @param value String to hash * @return Hash value based upon the enum */ protected int hash(String value) { //replace the specified return statements with calls to your hash // functions, passing through the string to hash switch (type) { case ONE: return 0; //first function here, ex: FVN1A(value); case TWO: return 0; //second hash case THREE: return 0; //third hash default: return 0; } }
//TODO - Helper methods can make your code more efficient and look neater. //We expect AT LEAST the following helper methods in your code //rehash() to expand and rehash the items into the table when load factor goes over the threshold. //printStatistics() to print the statistics after each expansion. This method will be called from insert/rehash only if printStats=true }
here are the three hashtypes I'm using.
/** Hash Function 1 **/
private int hashFun1(String key){
int hashVal = 0;
int pow27 = 1;
for(int j = key.length()-1; j >= 0; j-- ){
int letter = key.charAt(j) - 96;
hashVal += pow27 * letter;
pow27 *= 27;
}
return hashVal % hashtable.length;
}
/** Hash function 2 **/
private int hashFun2(String key){
int hashVal = key.charAt(0) - 96;
for (int j =1; j int letter = key.charAt(j) - 96; hashVal = hashVal*27+letter; } return hashVal % hashtable.length; } /** Hash Function 3**/ private int hasFun3(String key){ int hashVal = 0; for(int j=0; j int letter = key.charAt(j) - 96; hashVal = (hashVal*27+letter) % hashtable.length; } return hashVal; } and then the normal one Or default, private int hashFun(String key,int hashSize) { int hashValue = 0; for(int i=0;i int letter = key.charAt(i); hashValue = (hashValue*27 + letter)%hashSize; return hashValue; } Here is more descrption about the keeping stasts method and hashtable Please show a screen shot of your output. Thanks you!

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
