Class IdentityHashSet<KType>
- java.lang.Object
-
- com.carrotsearch.randomizedtesting.rules.IdentityHashSet<KType>
-
- All Implemented Interfaces:
java.lang.Iterable<KType>
final class IdentityHashSet<KType> extends java.lang.Object implements java.lang.Iterable<KType>An identity hash set implemented using open addressing. No null keys are allowed.
-
-
Field Summary
Fields Modifier and Type Field Description intassignedCached number of assigned slots.static floatDEFAULT_LOAD_FACTORDefault load factor.java.lang.Object[]keysAll of set entries.floatloadFactorThe load factor for this set (fraction of allocated or deleted slots before the buffers must be rehashed or reallocated).static intMIN_CAPACITYMinimum capacity for the set.private intresizeThresholdCached capacity threshold at which we must resize the buffers.
-
Constructor Summary
Constructors Constructor Description IdentityHashSet()Creates a hash set with the default capacity of 16.IdentityHashSet(int initialCapacity)Creates a hash set with the given capacity, load factor of 0.75f.IdentityHashSet(int initialCapacity, float loadFactor)Creates a hash set with the given capacity and load factor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(KType e)Adds a reference to the set.private voidallocateBuffers(int capacity)Allocate internal buffers for a given capacity.voidclear()booleancontains(KType e)Checks if the set contains a given ref.private voidexpandAndRehash()Expand the internal storage buffers (capacity) or rehash current keys and values if there are a lot of deleted slots.booleanisEmpty()java.util.Iterator<KType>iterator()protected intnextCapacity(int current)Return the next possible capacity, counting from the current buffers' size.private static intrehash(java.lang.Object o)Rehash via MurmurHash.protected introundCapacity(int requestedCapacity)Round the capacity to the next allowed value.intsize()
-
-
-
Field Detail
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTOR
Default load factor.- See Also:
- Constant Field Values
-
MIN_CAPACITY
public static final int MIN_CAPACITY
Minimum capacity for the set.- See Also:
- Constant Field Values
-
keys
public java.lang.Object[] keys
All of set entries. Always of power of two length.
-
assigned
public int assigned
Cached number of assigned slots.
-
loadFactor
public final float loadFactor
The load factor for this set (fraction of allocated or deleted slots before the buffers must be rehashed or reallocated).
-
resizeThreshold
private int resizeThreshold
Cached capacity threshold at which we must resize the buffers.
-
-
Constructor Detail
-
IdentityHashSet
public IdentityHashSet()
Creates a hash set with the default capacity of 16. load factor of 0.75f. `
-
IdentityHashSet
public IdentityHashSet(int initialCapacity)
Creates a hash set with the given capacity, load factor of 0.75f.
-
IdentityHashSet
public IdentityHashSet(int initialCapacity, float loadFactor)Creates a hash set with the given capacity and load factor.
-
-
Method Detail
-
add
public boolean add(KType e)
Adds a reference to the set. Null keys are not allowed.
-
contains
public boolean contains(KType e)
Checks if the set contains a given ref.
-
rehash
private static int rehash(java.lang.Object o)
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()
-
-