Package org.antlr.v4.runtime.misc
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>
Setimplementation with closed hashing (open addressing).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classArray2DHashSet.SetIterator
-
Field Summary
Fields Modifier and Type Field Description protected T[][]bucketsprotected AbstractEqualityComparator<? super T>comparatorprotected intcurrentPrimestatic intINITAL_BUCKET_CAPACITYstatic intINITAL_CAPACITYprotected intinitialBucketCapacityprotected intinitialCapacitystatic doubleLOAD_FACTORprotected intnHow many elements in setprotected intthresholdwhen to expand
-
Constructor Summary
Constructors Constructor Description Array2DHashSet()Array2DHashSet(AbstractEqualityComparator<? super T> comparator)Array2DHashSet(AbstractEqualityComparator<? super T> comparator, int initialCapacity, int initialBucketCapacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T t)booleanaddAll(Collection<? extends T> c)protected TasElementType(Object o)Returnoas an instance of the element typeT.voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> collection)booleancontainsFast(T obj)protected T[]createBucket(int capacity)Return an array ofTwith lengthcapacity.protected T[][]createBuckets(int capacity)Return an array ofT[]with lengthcapacity.booleanequals(Object o)protected voidexpand()Tget(T o)protected intgetBucket(T o)TgetOrAdd(T o)Addoto set if not there; return existing value if already there.protected TgetOrAddImpl(T o)inthashCode()booleanisEmpty()Iterator<T>iterator()booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanremoveFast(T obj)booleanretainAll(Collection<?> c)intsize()T[]toArray()<U> U[]toArray(U[] a)StringtoString()StringtoTableString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
spliterator
-
-
-
-
Field Detail
-
INITAL_CAPACITY
public static final int INITAL_CAPACITY
- See Also:
- Constant Field Values
-
INITAL_BUCKET_CAPACITY
public static final int INITAL_BUCKET_CAPACITY
- See Also:
- Constant Field Values
-
LOAD_FACTOR
public static final double LOAD_FACTOR
- See Also:
- Constant Field Values
-
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 Detail
-
Array2DHashSet
public Array2DHashSet()
-
Array2DHashSet
public Array2DHashSet(AbstractEqualityComparator<? super T> comparator)
-
Array2DHashSet
public Array2DHashSet(AbstractEqualityComparator<? super T> comparator, int initialCapacity, int initialBucketCapacity)
-
-
Method Detail
-
getOrAdd
public final T getOrAdd(T o)
Addoto set if not there; return existing value if already there. This method performs the same operation asadd(T)aside from the return value.
-
getBucket
protected final int getBucket(T o)
-
hashCode
public int hashCode()
-
equals
public boolean equals(Object o)
-
expand
protected void expand()
-
add
public final boolean add(T t)
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
contains
public final boolean contains(Object o)
-
containsFast
public boolean containsFast(T obj)
-
toArray
public T[] toArray()
-
toArray
public <U> U[] toArray(U[] a)
-
remove
public final boolean remove(Object o)
-
removeFast
public boolean removeFast(T obj)
-
containsAll
public boolean containsAll(Collection<?> collection)
- Specified by:
containsAllin interfaceCollection<T>- Specified by:
containsAllin interfaceSet<T>
-
addAll
public boolean addAll(Collection<? extends T> c)
-
retainAll
public boolean retainAll(Collection<?> c)
-
removeAll
public boolean removeAll(Collection<?> c)
-
clear
public void clear()
-
toTableString
public String toTableString()
-
asElementType
protected T asElementType(Object o)
Returnoas an instance of the element typeT. Ifois non-null but known to not be an instance ofT, this method returnsnull. The base implementation does not perform any type checks; override this method to provide strong type checks for thecontains(java.lang.Object)andremove(java.lang.Object)methods to ensure the arguments to theEqualityComparatorfor the set always have the expected types.- Parameters:
o- the object to try and cast to the element type of the set- Returns:
oif it could be an instance ofT, otherwisenull.
-
createBuckets
protected T[][] createBuckets(int capacity)
Return an array ofT[]with lengthcapacity.- Parameters:
capacity- the length of the array to return- Returns:
- the newly constructed array
-
createBucket
protected T[] createBucket(int capacity)
Return an array ofTwith lengthcapacity.- Parameters:
capacity- the length of the array to return- Returns:
- the newly constructed array
-
-