Class Array2DHashSet<T>

java.lang.Object
org.antlr.v4.runtime.misc.Array2DHashSet<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, Set<T>
Direct Known Subclasses:
ATNConfigSet.AbstractConfigHashSet

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

    • INITAL_CAPACITY

      public static final int INITAL_CAPACITY
      See Also:
    • INITAL_BUCKET_CAPACITY

      public static final int INITAL_BUCKET_CAPACITY
      See Also:
    • LOAD_FACTOR

      public static final double LOAD_FACTOR
      See Also:
    • comparator

      protected final AbstractEqualityComparator<? super T> comparator
    • buckets

      protected T[][] buckets
    • n

      protected int n
      How many elements in set
    • currentPrime

      protected int currentPrime
    • threshold

      protected int threshold
      when to expand
    • initialCapacity

      protected final int initialCapacity
    • initialBucketCapacity

      protected final int initialBucketCapacity
  • Constructor Details

  • Method Details

    • 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 Collection<T>
      Specified by:
      hashCode in interface Set<T>
      Overrides:
      hashCode in class Object
    • equals

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

      protected void expand()
    • add

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

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

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

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

      public boolean containsFast(T obj)
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface Set<T>
    • toArray

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

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

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

      public boolean removeFast(T obj)
    • containsAll

      public boolean containsAll(Collection<?> collection)
      Specified by:
      containsAll in interface Collection<T>
      Specified by:
      containsAll in interface Set<T>
    • addAll

      public boolean addAll(Collection<? extends T> c)
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface Set<T>
    • retainAll

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

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T>
      Specified by:
      removeAll in interface Set<T>
    • clear

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

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

      public String toTableString()
    • asElementType

      protected T asElementType(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