Class Obj2IntIdentityHashMap<T>


  • public class Obj2IntIdentityHashMap<T>
    extends Common_hash_support
    A Map from non-null Objects of type T to ints int value 0 reserved to mean object is not in the table. This impl is for use in a single thread case only, for table updates Multiple reader threads are OK if there's no writing. Supports shrinking (reallocating the big table) Removed objects replaced with special marker object in the table so find operations continue to work (they can't stop upon finding this object).
    • Field Detail

      • removedMarker

        private final T removedMarker
      • componentType

        private final java.lang.Class<T> componentType
      • keys

        private T[] keys
      • values

        private int[] values
    • Constructor Detail

      • Obj2IntIdentityHashMap

        public Obj2IntIdentityHashMap​(java.lang.Class<T> clazz,
                                      T removedMarker)
      • Obj2IntIdentityHashMap

        public Obj2IntIdentityHashMap​(int initialCapacity,
                                      java.lang.Class<T> clazz,
                                      T removedMarker)
        Parameters:
        initialCapacity - - you can add this many before expansion
        clazz - - a superclass of the stored items
        removedMarker - - a unique value never stored in the table, used to mark removed items
    • Method Detail

      • findPosition

        private int findPosition​(T obj)
        returns a position in the key/value table if the key is not found, then the position will be to the place where the key would be put upon adding (without reusing REMOVED, and the current internal value of keys[position] would be 0. if the key is found, then keys[position] == key
        Parameters:
        obj - the object to find
        Returns:
        the probeAddr in keys array - might reference a slot holding null, or the key value if found
      • contains

        public boolean contains​(java.lang.Object obj)
      • find

        public int find​(T obj)
        Parameters:
        obj - the object to find in the table (if it is there)
        Returns:
        the position of obj in the table, or -1 if not in the table
      • get

        public int get​(T obj)
      • put

        public int put​(T obj,
                       int value)
        Parameters:
        obj - the key
        value - the value
        Returns:
        the previous value, or 0 if this map did not already contain the specified key
      • putInner

        private void putInner​(T obj,
                              int value)
        used for increasing table size
        Parameters:
        rawKey -
      • remove

        public int remove​(java.lang.Object rawKey)
        Can't replace the item with a null because other keys that were stored in the table which previously collided with the removed item won't be found. UIMA-4204
        Parameters:
        rawKey - the value to remove
        Returns:
        the value previously associated with the key, or 0 if none
      • getKeys

        public T[] getKeys()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object