public class IntOpenHashSet extends AbstractWritableIntSet implements WritableIntSet
int
's, implemented using using open
addressing with linear probing for collision resolution.
Important note. The implementation uses power-of-two tables and linear probing, which may cause poor performance (many collisions) if hash values are not properly distributed.
As a hash function, this implementation uses the finalization step from
Austin Appleby's MurmurHash3
.
To use a custom hash function, override hash(int)
.
Differencies from IntChainHashSet
by performance:
AbstractWritableIntSet.include(int)
and contains(int)
are faster if hash values are properly distributed
AbstractWritableIntSet.remove(int)
is slower
AbstractIntSet.toArray()
is slower
iterator()
is slower
IntChainHashSet
takes M*(1+2*f)
memory
where M
- memory for IntOpenHashSet
, f
- loadFactor.
LongChainHashSet
takes M*(1+3*f)/2
memory, where M
- memory for LongOpenHashSet
IntChainHashSet
,
IntTreeSet
IntCollector.Dummy
myModCount
DUMMY
Constructor and Description |
---|
IntOpenHashSet()
Creates new hashset with default load factor and default capacity
|
IntOpenHashSet(int initialCapacity)
Creates new hashset with default load factor
|
IntOpenHashSet(int initialCapacity,
float loadFactor)
No guarantees are made regarding the number of elements that can be added to the created set without rehash.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all of the elements from this set.
|
boolean |
contains(int value) |
static IntOpenHashSet |
createForAdd(int count)
Creates new hashset with default load factor
|
static IntOpenHashSet |
createForAdd(int count,
float loadFactor)
Creates new hashset with the specified load factor
that is garanteed to not invoke
resize after adding count elements |
static IntOpenHashSet |
createFrom(int... keys) |
static IntOpenHashSet |
createFrom(IntIterable keys) |
boolean |
exclude0(int value)
exclude element without invocation of
AbstractWritableIntSet#modified() |
int |
getThreshold() |
protected int |
hash(int value) |
protected boolean |
include0(int value)
include element without invocation of
AbstractWritableIntSet#modified() |
IntIterator |
iterator() |
int |
size() |
protected void |
toNativeArrayImpl(int[] dest,
int destPos) |
add, add0, addAll, addAll, addAll, exclude, failFast, include, modified, remove, remove0, removeAll, removeAll, retain
containsAll, equals, hashCode, isEmpty, toArray, toNativeArray, toNativeArray, toString, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
exclude, include, remove, removeAll, removeAll, retain
add, addAll, addAll, addAll
containsAll, equals, hashCode, isEmpty, toArray, toNativeArray, toNativeArray
public IntOpenHashSet(int initialCapacity, float loadFactor)
initialCapacity
influences only the amount of memory initially allocated.
If you need such guarantees, use createForAdd(int, float)
.public IntOpenHashSet(int initialCapacity)
IntOpenHashSet(int, float)
public IntOpenHashSet()
public static IntOpenHashSet createForAdd(int count, float loadFactor)
resize
after adding count
elementscount
and loadFactor
public static IntOpenHashSet createForAdd(int count)
createForAdd(int, float)
public static IntOpenHashSet createFrom(IntIterable keys)
public static IntOpenHashSet createFrom(int... keys)
protected int hash(int value)
protected boolean include0(int value)
AbstractWritableIntSet
AbstractWritableIntSet#modified()
include0
in class AbstractWritableIntSet
public boolean exclude0(int value)
AbstractWritableIntSet
AbstractWritableIntSet#modified()
exclude0
in class AbstractWritableIntSet
public void clear()
WritableIntSet
clear
in interface WritableIntSet
public boolean contains(int value)
public int size()
size
in interface IntSet
size
in interface IntSizedIterable
public int getThreshold()
protected void toNativeArrayImpl(int[] dest, int destPos)
toNativeArrayImpl
in class AbstractIntSet
@NotNull public IntIterator iterator()
iterator
in interface IntIterable
iterator
in interface java.lang.Iterable<IntIterator>
IntIterator.EMPTY