Class UniversalHash
java.lang.Object
src.UniversalHash
Class for implementing a universal hash function.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeHashFunction(int nKeys) Changes the hash function parameters to a new prime number and resets the collisions.booleancheckCollisionThreshold(int collisions, int size) Checks if the number of collisions exceeds the threshold and increments the number of collisions ocurred.inthashFunction(Object key, int size) Calculates the index of the hash table for a given key.
-
Constructor Details
-
UniversalHash
public UniversalHash()
-
-
Method Details
-
hashFunction
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.
-