public class IdHashMap extends AbstractIdHashCollection implements IdMap
Provides an implementation of IdMap
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
as keys to the map, because these value are reserved for unused table entries.
This set is a lot faster than Map<Long, 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 |
---|
IdHashMap()
Constructs a new map with the default number of
expected elements (DEFAULT_EXPECTED_SIZE) and
the default load factor (DEFAULT_LOAD_FACTOR)
|
IdHashMap(int expectedSize)
Constructs a new map with the given number of
expected elements and the default load
factor (DEFAULT_LOAD_FACTOR)
|
IdHashMap(int expectedSize,
float loadFactor)
Constructs a new map with the given number of
expected elements and load factor
|
Modifier and Type | Method and Description |
---|---|
protected void |
clearArray(long[] arr)
Clears the given array--i.e. fills it with
AbstractIdHashCollection.FREE values |
boolean |
containsKey(long key)
Checks if the map contains a given key
|
protected long[] |
ensureCapacity(int elements)
Ensures that the table can hold a given number of elements.
|
long |
get(long key)
Retrieves the value for a given key
|
IdMapIterator |
iterator() |
long[] |
keys() |
protected void |
makeTable(int capacity)
Creates a new, cleared hash table with the given capacity
|
long |
put(long key,
long value)
Puts a key-value pair into the map.
|
long |
remove(long key)
Removes a key-value pair from the map
|
long[] |
values() |
clear, hash, size
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clear, size
public IdHashMap()
public IdHashMap(int expectedSize)
expectedSize
- the number of expected elementspublic IdHashMap(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 elementsprotected void makeTable(int capacity)
AbstractIdHashCollection
makeTable
in class AbstractIdHashCollection
capacity
- the capacityprotected void clearArray(long[] arr)
AbstractIdHashCollection
AbstractIdHashCollection.FREE
valuesclearArray
in class AbstractIdHashCollection
arr
- the array to clearpublic long put(long key, long value)
IdMap
public boolean containsKey(long key)
IdMap
containsKey
in interface IdMap
key
- the keypublic long remove(long key)
IdMap
public long get(long key)
IdMap
public long[] values()
public IdMapIterator iterator()