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
Set
implementation with closed hashing (open addressing).-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected T[][]
protected final AbstractEqualityComparator
<? super T> protected int
static final int
static final int
protected final int
protected final int
static final double
protected int
How many elements in setprotected int
when to expand -
Constructor Summary
ConstructorsConstructorDescriptionArray2DHashSet
(AbstractEqualityComparator<? super T> comparator) Array2DHashSet
(AbstractEqualityComparator<? super T> comparator, int initialCapacity, int initialBucketCapacity) -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
boolean
addAll
(Collection<? extends T> c) protected T
Returno
as an instance of the element typeT
.void
clear()
final boolean
boolean
containsAll
(Collection<?> collection) boolean
containsFast
(T obj) protected T[]
createBucket
(int capacity) Return an array ofT
with lengthcapacity
.protected T[][]
createBuckets
(int capacity) Return an array ofT[]
with lengthcapacity
.boolean
protected void
expand()
protected final int
final T
Addo
to set if not there; return existing value if already there.protected T
getOrAddImpl
(T o) int
hashCode()
final boolean
isEmpty()
iterator()
final boolean
boolean
removeAll
(Collection<?> c) boolean
removeFast
(T obj) boolean
retainAll
(Collection<?> c) final int
size()
T[]
toArray()
<U> U[]
toArray
(U[] a) toString()
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 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
-
buckets
-
n
protected int nHow many elements in set -
currentPrime
protected int currentPrime -
threshold
protected int thresholdwhen to expand -
initialCapacity
protected final int initialCapacity -
initialBucketCapacity
protected final int initialBucketCapacity
-
-
Constructor Details
-
Array2DHashSet
public Array2DHashSet() -
Array2DHashSet
-
Array2DHashSet
public Array2DHashSet(AbstractEqualityComparator<? super T> comparator, int initialCapacity, int initialBucketCapacity)
-
-
Method Details
-
getOrAdd
Addo
to set if not there; return existing value if already there. This method performs the same operation asadd(T)
aside from the return value. -
getOrAddImpl
-
get
-
getBucket
-
hashCode
public int hashCode() -
equals
-
expand
protected void expand() -
add
-
size
public final int size() -
isEmpty
public final boolean isEmpty() -
contains
-
containsFast
-
iterator
-
toArray
-
toArray
public <U> U[] toArray(U[] a) -
remove
-
removeFast
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceSet<T>
-
addAll
-
retainAll
-
removeAll
-
clear
public void clear() -
toString
-
toTableString
-
asElementType
Returno
as an instance of the element typeT
. Ifo
is 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 theEqualityComparator
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 ofT
, otherwisenull
.
-
createBuckets
Return an array ofT[]
with lengthcapacity
.- Parameters:
capacity
- the length of the array to return- Returns:
- the newly constructed array
-
createBucket
Return an array ofT
with lengthcapacity
.- Parameters:
capacity
- the length of the array to return- Returns:
- the newly constructed array
-