Class IndexHashTable<T>


  • public class IndexHashTable<T>
    extends java.lang.Object
    The IndexHashTable is a hash table which maps entries of an array to their index in the array. All entries in the array must be unique otherwise a well-defined mapping is not possible.

    The entry objects must implement Object.equals(Object) and Object.hashCode() otherwise the behavior of this class is undefined.

    The implementation uses a hash table with open addressing and linear probing.

    The table is thread safe and can concurrently accessed by multiple threads, thread safety is achieved through immutability. Though its not strictly immutable which means, that the table must still be safely published to other threads.

    • Constructor Summary

      Constructors 
      Constructor Description
      IndexHashTable​(T[] mapping, double loadfactor)
      Initializes the current instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int get​(T key)
      Retrieves the index for the specified key.
      int size()
      Retrieves the size.
      T[] toArray​(T[] array)  
      • Methods inherited from class java.lang.Object

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

      • IndexHashTable

        public IndexHashTable​(T[] mapping,
                              double loadfactor)
        Initializes the current instance. The specified array is copied into the table and later changes to the array do not affect this table in any way.
        Parameters:
        mapping - the values to be indexed, all values must be unique otherwise a well-defined mapping of an entry to an index is not possible
        loadfactor - the load factor, usually 0.7
        Throws:
        java.lang.IllegalArgumentException - if the entries are not unique
    • Method Detail

      • get

        public int get​(T key)
        Retrieves the index for the specified key.
        Parameters:
        key -
        Returns:
        the index or -1 if there is no entry to the keys
      • size

        public int size()
        Retrieves the size.
        Returns:
        the number of elements in this map.
      • toArray

        public T[] toArray​(T[] array)