public class IdHashSet extends AbstractIdHashCollection implements IdSet
Provides an implementation of IdSet
based on a hash table. Uses
double hashing. The table size is always a prime number.
You MUST NOT try to add Long.MAX_VALUE
or Long.MIN_VALUE
to the
set, because these value are reserved for unused table entries.
This set is a lot faster than List<Long>
and even
a little bit faster than trove4j's implementation.
_capacity, _deleted, _overloadFactor, _size, _table, DEFAULT_EXPECTED_SIZE, DEFAULT_LOAD_FACTOR, DELETED, FREE, MINIMUM_CAPACITY
Constructor and Description |
---|
IdHashSet()
Constructs a new set with the default number of
expected elements (DEFAULT_EXPECTED_SIZE) and
the default load factor (DEFAULT_LOAD_FACTOR)
|
IdHashSet(int expectedSize)
Constructs a new set with the given number of
expected elements and the default load
factor (DEFAULT_LOAD_FACTOR)
|
IdHashSet(int expectedSize,
float loadFactor)
Constructs a new set with the given number of
expected elements and load factor
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(long value)
Inserts a value into the set.
|
boolean |
contains(long value)
Checks if the set contains a given value
|
protected long[] |
ensureCapacity(int elements)
Ensures that the table can hold a given number of elements.
|
IdSetIterator |
iterator() |
boolean |
remove(long value)
Removes a value from the set
|
long[] |
toArray() |
clear, clearArray, hash, makeTable, size
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clear, size
public IdHashSet()
public IdHashSet(int expectedSize)
expectedSize
- the number of expected elementspublic IdHashSet(int expectedSize, float loadFactor)
expectedSize
- the number of expected elementsloadFactor
- the load factorprotected long[] ensureCapacity(int elements)
AbstractIdHashCollection
ensureCapacity
in class AbstractIdHashCollection
elements
- the number of expected elementspublic boolean add(long value)
IdSet
public boolean contains(long value)
IdSet
public boolean remove(long value)
IdSet
public long[] toArray()
public IdSetIterator iterator()