Package org.antlr.v4.runtime.misc
Class Array2DHashSet<T>
- java.lang.Object
-
- org.antlr.v4.runtime.misc.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>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(java.util.Collection<? extends T> c)protected TasElementType(java.lang.Object o)Returnoas an instance of the element typeT.voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.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(java.lang.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()java.util.Iterator<T>iterator()booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanremoveFast(T obj)booleanretainAll(java.util.Collection<?> c)intsize()T[]toArray()<U> U[]toArray(U[] a)java.lang.StringtoString()java.lang.StringtoTableString()
-
-
-
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(java.lang.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(java.lang.Object o)
-
containsFast
public boolean containsFast(T obj)
-
iterator
public java.util.Iterator<T> iterator()
-
toArray
public T[] toArray()
-
toArray
public <U> U[] toArray(U[] a)
-
remove
public final boolean remove(java.lang.Object o)
-
removeFast
public boolean removeFast(T obj)
-
containsAll
public boolean containsAll(java.util.Collection<?> collection)
-
addAll
public boolean addAll(java.util.Collection<? extends T> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
clear
public void clear()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toTableString
public java.lang.String toTableString()
-
asElementType
protected T asElementType(java.lang.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
-
-