Class UniversalHash

java.lang.Object
src.UniversalHash

public class UniversalHash extends Object
Class for implementing a universal hash function.
See Also:
  • Constructor Details

    • UniversalHash

      public UniversalHash()
  • Method Details

    • hashFunction

      public int hashFunction(Object key, int size)
      Calculates the index of the hash table for a given key.
      Parameters:
      key - The key to hash.
      size - The size of the hash table.
      Returns:
      The index of the hash table for the given key.
    • checkCollisionThreshold

      public boolean checkCollisionThreshold(int collisions, int size)
      Checks if the number of collisions exceeds the threshold and increments the number of collisions ocurred.
      Parameters:
      collisions - The number of collisions to add.
      size - The size of the hash table.
      Returns:
      True if the number of collisions exceeds the threshold, false otherwise.
    • changeHashFunction

      public void changeHashFunction(int nKeys)
      Changes the hash function parameters to a new prime number and resets the collisions.
      Parameters:
      nKeys - The number of keys in the hash table.