Class Array2DHashSet<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.Set<T>
    Direct Known Subclasses:
    ATNConfigSet.AbstractConfigHashSet

    public class Array2DHashSet<T>
    extends java.lang.Object
    implements java.util.Set<T>
    Set implementation with closed hashing (open addressing).
    • Field Detail

      • buckets

        protected T[][] buckets
      • n

        protected int n
        How many elements in set
      • threshold

        protected int threshold
      • currentPrime

        protected int currentPrime
      • initialBucketCapacity

        protected int initialBucketCapacity
    • Constructor Detail

      • Array2DHashSet

        public Array2DHashSet()
      • Array2DHashSet

        public Array2DHashSet​(AbstractEqualityComparator<? super T> comparator,
                              int initialCapacity,
                              int initialBucketCapacity)
    • Method Detail

      • getOrAdd

        public final T getOrAdd​(T o)
        Add o to set if not there; return existing value if already there. This method performs the same operation as add(T) aside from the return value.
      • getOrAddImpl

        protected T getOrAddImpl​(T o)
      • get

        public T get​(T o)
      • getBucket

        protected final int getBucket​(T o)
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<T>
        Specified by:
        hashCode in interface java.util.Set<T>
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Collection<T>
        Specified by:
        equals in interface java.util.Set<T>
        Overrides:
        equals in class java.lang.Object
      • expand

        protected void expand()
      • add

        public final boolean add​(T t)
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.Set<T>
      • size

        public final int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in interface java.util.Set<T>
      • isEmpty

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

        public final boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<T>
        Specified by:
        contains in interface java.util.Set<T>
      • containsFast

        public boolean containsFast​(T obj)
      • 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>
      • toArray

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

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

        public final boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<T>
        Specified by:
        remove in interface java.util.Set<T>
      • removeFast

        public boolean removeFast​(T obj)
      • containsAll

        public boolean containsAll​(java.util.Collection<?> collection)
        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>
      • 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>
      • 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>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<T>
        Specified by:
        clear in interface java.util.Set<T>
      • toString

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

        public java.lang.String toTableString()
      • asElementType

        protected T asElementType​(java.lang.Object o)
        Return o as an instance of the element type T. If o is non-null but known to not be an instance of T, this method returns null. The base implementation does not perform any type checks; override this method to provide strong type checks for the contains(java.lang.Object) and remove(java.lang.Object) methods to ensure the arguments to the EqualityComparator for the set always have the expected types.
        Parameters:
        o - the object to try and cast to the element type of the set
        Returns:
        o if it could be an instance of T, otherwise null.
      • createBuckets

        protected T[][] createBuckets​(int capacity)
        Return an array of T[] with length capacity.
        Parameters:
        capacity - the length of the array to return
        Returns:
        the newly constructed array
      • createBucket

        protected T[] createBucket​(int capacity)
        Return an array of T with length capacity.
        Parameters:
        capacity - the length of the array to return
        Returns:
        the newly constructed array