Class ObjHashSet<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>

    public class ObjHashSet<T>
    extends Common_hash_support
    implements java.util.Set<T>
    A set of Objects of type T This impl is for use in a single thread case only, when table is being updated. 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
        the object of type T indicating key is removed
      • clazz

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

        private T[] keys
    • Constructor Detail

      • ObjHashSet

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

        public ObjHashSet​(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
      • ObjHashSet

        public ObjHashSet​(ObjHashSet<T> ohs)
        Copy constructor
        Parameters:
        ohs - -
      • ObjHashSet

        public ObjHashSet​(ObjHashSet<T> ohs,
                          boolean readOnly)
    • Method Detail

      • findPosition

        private int findPosition​(T key)
        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)
        Specified by:
        contains in interface java.util.Collection<T>
        Specified by:
        contains in interface java.util.Set<T>
      • 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
      • add

        public boolean add​(T obj)
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.Set<T>
        Parameters:
        obj - - the object to add
        Returns:
        true if this set did not already contain the specified element
      • addInner

        private void addInner​(T obj)
        used for increasing table size
        Parameters:
        rawKey -
      • remove

        public boolean 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
        Specified by:
        remove in interface java.util.Collection<T>
        Specified by:
        remove in interface java.util.Set<T>
        Parameters:
        rawKey - the value to remove
        Returns:
        true if the key was present
      • removeAtPosition

        private void removeAtPosition​(int pos)
      • get

        public T get​(int index)
        For iterator use
        Parameters:
        index - - a magic number returned by the internal find
        Returns:
        the T at that spot, or null if nothing there
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in interface java.util.Set<T>
      • moveToFirst

        private int moveToFirst()
      • moveTo

        public int moveTo​(FeatureStructure fs)
        if the fs is in the set, the iterator should return it. if not, return -1 (makes iterator invalid)
        Parameters:
        fs - position to this fs
        Returns:
        the index if present, otherwise -1;
      • toArray

        public <T2> T2[] toArray​(T2[] a)
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.Set<T>
      • toArray

        public T[] toArray()
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.Set<T>
      • toString

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

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<T>
        Specified by:
        isEmpty in interface java.util.Set<T>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<T>
        Specified by:
        containsAll in interface java.util.Set<T>
      • addAll

        public boolean addAll​(java.util.Collection<? extends T> c)
        Specified by:
        addAll in interface java.util.Collection<T>
        Specified by:
        addAll in interface java.util.Set<T>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<T>
        Specified by:
        removeAll in interface java.util.Set<T>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<T>
        Specified by:
        retainAll in interface java.util.Set<T>