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

HashTable help with 3 differnt HashType!! java! package hw5; public class HashTable

implements IHashTable { //You will need a HashTable of LinkedLists. public enum

Please show a screen shot of your output.

Thanks you!

Part 1 Hash Table (50 points) In this part, you will implement a basic Hash Table. We have provided you with an interface and starter code that implements that interface. Fill in the blanks to complete given methods. Implementation Details You will be implementing the IHashTable interface, as additional required private helper methods. See method descriptions for details. The benefits of a hash table are a result of the ability to hash a value and then immediately locate its position if there are no collisions, or vastly narrow down the search space if there are. As such, you shouldn't need to search through the entire table to find an element for your contains() and delete() methods. Your hash table will be used exclusively to store strings, as this is the type of hash table that would be used to store a dictionary of words for uses such as spell check. To resolve collisions, use will be using separate chaining. One way of implementing this would be to have your backing storage be an array of LinkedLists. Then you would simply add to the LinkedList at the specified index when inserting elements into your hash table. The performance of hash tables degrades if there are too many collisions. As such, you will keep track of the load factor of the table (the ratio of the size of the table to the number of elements) and once this value exceeds %, you must double the size of the table and rehash all of the values. You will be implementing a private helper method rehash() to accomplish this. You will be implementing three different hash functions. You must implement a rolling hash using Horner's Method, as well as two other hash functions of your choosing. A list of possible hash functions are provided in the starter files, but feel free to use other hash functions as well. Remember, at the minimum your hash functions must be deterministic, although your goal is for them to be uniform and fast. You will later compare the performance of the hash functions and record your results in HW5.txt. You must actually implement the algorithms in your HashTable class. If you use String.hashCode(), you not receive any credit for this assignment

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!