Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with choosing ENUM on my hashtable function? There is three different

ID: 3866060 • Letter: N

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 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.

Explanation / Answer

Answer for the question:

I have an observation from your code you can use the
HashType euem while inserting elements and remove the elements
like you can use
See the below code type

public enum HashType
{
ONE, TWO, THREE
};

How the data is inserted with help enum HashType
public static void main(String[] args)
{
EnumMap<HashType, String> map =
new EnumMap<HashType, String>(HashType.class);

// assosiate values in map
map.put(HashType.ONE, "1");
map.put(HashType.TWO, "2");
map.put(HashType.THREE, "3");
map.put(HashType.FOUR, "4");

}