Question: Need help with choosing ENUM on my hashtable function? There is three different types but idk what to do... //You will need a HashTable of
Need help with choosing ENUM on my hashtable function? There is three different types but idk what to do...
//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;
private int capacity; // size of the hashtable
private LinkedList[] hashtable;
private int longestchain;
private double LoadFactor;
/**
* Constructor for hash table
*
* @param size Initial dimensions of the hash table
* @param type Specified hash function
*/
public HashTable(int size, HashType type) {
this.capacity = size;
this.type = type;
hashtable = new LinkedList[size];
nelems = 0;
}
/**
* 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) {
this.capacity = size;
this.hashtable = new LinkedList[size];
this.printStats = true;
this.statsFileName = fileName;
}
/**
* 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;
}
}
// I also have Add method, contains, remove, and get nelems method, but thats all.
I'm using this file to sort out dictionary words (randomly with random size) so does anyone know what to do/how to do it. or what would be the best fit for the option? if you can let me know and write out the code in java i will appreciate it.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
