Class IdentityHashSet<KType>
java.lang.Object
com.carrotsearch.randomizedtesting.rules.IdentityHashSet<KType>
- All Implemented Interfaces:
Iterable<KType>
An identity hash set implemented using open addressing. No null keys are allowed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionint
Cached number of assigned slots.static final float
Default load factor.Object[]
All of set entries.final float
The load factor for this set (fraction of allocated or deleted slots before the buffers must be rehashed or reallocated).static final int
Minimum capacity for the set.private int
Cached capacity threshold at which we must resize the buffers. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a hash set with the default capacity of 16.IdentityHashSet
(int initialCapacity) IdentityHashSet
(int initialCapacity, float loadFactor) Creates a hash set with the given capacity and load factor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds a reference to the set.private void
allocateBuffers
(int capacity) Allocate internal buffers for a given capacity.void
clear()
boolean
Checks if the set contains a given ref.private void
Expand the internal storage buffers (capacity) or rehash current keys and values if there are a lot of deleted slots.boolean
isEmpty()
iterator()
protected int
nextCapacity
(int current) Return the next possible capacity, counting from the current buffers' size.private static int
Rehash via MurmurHash.protected int
roundCapacity
(int requestedCapacity) Round the capacity to the next allowed value.int
size()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTORDefault load factor.- See Also:
-
MIN_CAPACITY
public static final int MIN_CAPACITYMinimum capacity for the set.- See Also:
-
keys
All of set entries. Always of power of two length. -
assigned
public int assignedCached number of assigned slots. -
loadFactor
public final float loadFactorThe load factor for this set (fraction of allocated or deleted slots before the buffers must be rehashed or reallocated). -
resizeThreshold
private int resizeThresholdCached capacity threshold at which we must resize the buffers.
-
-
Constructor Details
-
IdentityHashSet
public IdentityHashSet() -
IdentityHashSet
public IdentityHashSet(int initialCapacity) -
IdentityHashSet
public IdentityHashSet(int initialCapacity, float loadFactor) Creates a hash set with the given capacity and load factor.
-
-
Method Details
-
add
Adds a reference to the set. Null keys are not allowed. -
contains
Checks if the set contains a given ref. -
rehash
Rehash via MurmurHash. -
expandAndRehash
private void expandAndRehash()Expand the internal storage buffers (capacity) or rehash current keys and values if there are a lot of deleted slots. -
allocateBuffers
private void allocateBuffers(int capacity) Allocate internal buffers for a given capacity.- Parameters:
capacity
- New capacity (must be a power of two).
-
nextCapacity
protected int nextCapacity(int current) Return the next possible capacity, counting from the current buffers' size. -
roundCapacity
protected int roundCapacity(int requestedCapacity) Round the capacity to the next allowed value. -
clear
public void clear() -
size
public int size() -
isEmpty
public boolean isEmpty() -
iterator
-