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>
Set
implementation with closed hashing (open addressing).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
Array2DHashSet.SetIterator
-
Field Summary
Fields Modifier and Type Field Description protected T[][]
buckets
protected AbstractEqualityComparator<? super T>
comparator
protected int
currentPrime
static int
INITAL_BUCKET_CAPACITY
static int
INITAL_CAPACITY
protected int
initialBucketCapacity
protected int
initialCapacity
static double
LOAD_FACTOR
protected int
n
How many elements in setprotected int
threshold
when 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 boolean
add(T t)
boolean
addAll(Collection<? extends T> c)
protected T
asElementType(Object o)
Returno
as an instance of the element typeT
.void
clear()
boolean
contains(Object o)
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
equals(Object o)
protected void
expand()
T
get(T o)
protected int
getBucket(T o)
T
getOrAdd(T o)
Addo
to set if not there; return existing value if already there.protected T
getOrAddImpl(T o)
int
hashCode()
boolean
isEmpty()
Iterator<T>
iterator()
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
removeFast(T obj)
boolean
retainAll(Collection<?> c)
int
size()
T[]
toArray()
<U> U[]
toArray(U[] a)
String
toString()
String
toTableString()
-
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)
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.
-
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:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in 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)
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
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 ofT
with lengthcapacity
.- Parameters:
capacity
- the length of the array to return- Returns:
- the newly constructed array
-
-