Class SimpleChainHashFunction<E>

  • All Implemented Interfaces:
    ChainHashFunction<E>

    public class SimpleChainHashFunction<E>
    extends java.lang.Object
    implements ChainHashFunction<E>
    Provides an implementation of a ChainHashFunction — that is, a class providing a hash function for a hash table with chaining — by making a straightforward use of Java’s hashCode function
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleChainHashFunction​(int T)
      Provides a hash function for a hash table with chaining, for a given table size

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int hashValue​(E e)
      Reports the hash value for a given value
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleChainHashFunction

        public SimpleChainHashFunction​(int T)
                                throws java.lang.IllegalArgumentException
        Provides a hash function for a hash table with chaining, for a given table size

        Parameters:
        T - table size
        Throws:
        java.lang.IllegalArgumentException - if the input table size is not positive

        Precondition: An integer T is given as input.
        Postcondition: If T is positive then a ChainHasFunction that can be used with a hash table of size T is created. An IllegalArgumentException is thrown otherwise.
    • Method Detail

      • hashValue

        public int hashValue​(E e)
        Description copied from interface: ChainHashFunction
        Reports the hash value for a given value
        Specified by:
        hashValue in interface ChainHashFunction<E>
        Parameters:
        e - the element whose has value is to be provided
        Returns:
        the hash value for this element

        Precondition:

        1. An element e of type E has been given as input.
        Postcondition:

        1. The has value of e — an integer between zero and one less than the size of the supported has table — is returned as output.