Class HashTable<T>

  • Type Parameters:
    T - The type of elements stored in each bucket.
    All Implemented Interfaces:
    Iterable<T>
    Direct Known Subclasses:
    ModuloHashTable, RangeHashTable

    public abstract class HashTable<T>
    extends Object
    implements Iterable<T>
    A hash table, i.e. a mapping between keys and values involving a HashFunction.
    • Method Detail

      • size

        public final int size()
        Returns:
        The size of this hash table, i.e. the number of buckets.
      • get

        public final T get​(CharSequence key)
        Parameters:
        key - A key to hash in order to compute an index.
        Returns:
        The content of the bucket assigned to the given key.
      • get

        public final T get​(int index)
        Parameters:
        index - The index of a bucket in this hash table.
        Returns:
        The content of the bucket at index index.
        Throws:
        ArrayIndexOutOfBoundsException - If the given index is negative or higher than the table's size.
      • set

        public final void set​(int index,
                              T value)
        Parameters:
        index - The index of a bucket in this hash table.
        value - The value to set for the bucket at index index.
        Throws:
        ArrayIndexOutOfBoundsException - If the given index is negative or higher than the table's size.
      • computeIndex

        public abstract int computeIndex​(CharSequence key)
        Hashes a key and computes an array index based on that hash.

        The maximum index is defined by constructor parameters passed to the hash function.

        Parameters:
        key - A key to hash in order to compute an index.
        Returns:
        The index to use for the given key in a hash table of size size.