Class HashFunction

java.lang.Object
dsa.lib.DSAObject
dsa.lab05.exercises.HashFunction
All Implemented Interfaces:
dsa.lib.DSAInterface

public class HashFunction extends dsa.lib.DSAObject
A randomly-chosen hash function from a universal family.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HashFunction(int size)
    Construct a hash function, randomly choosing its parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    hash(Object object)
    Hash the given object to a non-negative int less than size().
    int
    Get the size of the range of hashes.
    toString(String indent)
     

    Methods inherited from class dsa.lib.DSAObject

    toDebugString, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • HashFunction

      public HashFunction(int size)
      Construct a hash function, randomly choosing its parameters.
      Parameters:
      size - the range of hashes that hash(Object) should return
  • Method Details

    • size

      public int size()
      Get the size of the range of hashes.
      Returns:
      the range of hashes that hash(Object) should return
    • hash

      public int hash(Object object)
      Hash the given object to a non-negative int less than size().
      Parameters:
      object - an object
      Returns:
      a hash of that object
    • toString

      public String toString(String indent)