public class LongLongHashMap
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
LongLongHashMap.MapElement
Implements a map element storing the contents of the buckets.
|
| Modifier and Type | Field and Description |
|---|---|
private int |
capacity
Stores the current capacity.
|
private int |
contents
Stores the number of elements.
|
static int |
DEFAULT_CAPACITY
The default capacity for hash map instances.
|
static float |
DEFAULT_LOADFACTOR
The default load factor for hash map instances.
|
private float |
loadFactor
Stores the load factor.
|
private LongLongHashMap.MapElement[] |
map
Stores the first bucket for each key.
|
private static ArrayList<LongLongHashMap.MapElement> |
mapElementPool
Stores the
LongLongHashMap.MapElement pool. |
static int |
MAXIMUM_CAPACITY
The maximum allowed capacity for hash map instances.
|
private int |
maxLoad
Stores the maximum load.
|
private int |
objectCounter
Stores the counter for objects created.
|
private boolean |
rehashing
Stores if rehashing is permitted.
|
| Constructor and Description |
|---|
LongLongHashMap()
Constructs an empty instance with the default initial capacity and the
default load factor.
|
LongLongHashMap(int initialCapacity)
Constructs an empty instance with the given initial capacity and the
default load factor.
|
LongLongHashMap(int initialCapacity,
float loadFactor)
Constructs an empty instance with the given initial capacity and the
given load factor.
|
LongLongHashMap(LongLongHashMap map)
Constructs a new LongHashMap with the same mappings as the specified Map.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Cleans up this map by removing all entries.
|
private void |
construct(int initialCapacity,
float loadFactor)
Construction helper method.
|
boolean |
containsKey(long key)
Returns
true if this map contains a mapping for the
specified key. |
private LongLongHashMap.MapElement |
exists(long key)
Helper method: returns the element matching the key, or
null
if no such element exists. |
protected void |
finalize()
Clean and finalize.
|
long |
get(long key)
Returns the value to which the specified key is mapped in this identity
hash map, or
null if the map contains no mapping for this
key. |
long |
get(long key,
long deflt)
Returns the value to which the specified key is mapped in this identity
hash map, or
null if the map contains no mapping for this
key. |
int |
getCapacity()
Return the current capacity of the instance.
|
float |
getLoadFactor()
Return the load factor of the instance.
|
private static LongLongHashMap.MapElement |
getMapElementFromPool(long key,
long value)
Returns a
LongLongHashMap.MapElement from the shared pool. |
int |
getObjectCounter()
Return the number of objects created in / by this instance.
|
boolean |
isEmpty()
Returns
true if this map contains no key-value mappings. |
long[] |
keySet()
Return the keys in the hash map.
|
void |
put(long key,
long value)
Associates the specified value with the specified key in this map.
|
void |
putAll(LongLongHashMap map)
Puts all the keys and values in the specified hash
map into this hash map.
|
void |
read(java.io.DataInputStream in)
Reads contents of this map from the given input stream.
|
private void |
rehash()
Increase the capacity of the map to improve performance.
|
private static void |
releaseMapElement(LongLongHashMap.MapElement mapElement)
Releases and clears the specified
LongLongHashMap.MapElement
to the shared pool. |
void |
remove(long key)
Removes the mapping for this key from this map if present.
|
void |
setRehash(boolean rehashing)
Enable/disable rehashing (defaults to
true). |
int |
size()
Return the current number of mappings in the hash map.
|
void |
write(java.io.DataOutputStream out)
Writes the map to the given stream.
|
public static final int DEFAULT_CAPACITY
public static final int MAXIMUM_CAPACITY
public static final float DEFAULT_LOADFACTOR
private static ArrayList<LongLongHashMap.MapElement> mapElementPool
LongLongHashMap.MapElement pool.private LongLongHashMap.MapElement[] map
private int contents
private int objectCounter
private int capacity
private float loadFactor
private int maxLoad
private boolean rehashing
public LongLongHashMap()
public LongLongHashMap(int initialCapacity)
initialCapacity - The initial capacity for this hash map.public LongLongHashMap(int initialCapacity,
float loadFactor)
initialCapacity - The initial capacity for this hash map.loadFactor - The load factor for this hash map.public LongLongHashMap(LongLongHashMap map)
map - The map whose mappings are to be placed in this map. Throws:java.lang.NullPointerException - if the specified map is null.public void putAll(LongLongHashMap map)
map - the source mappublic int size()
public boolean isEmpty()
true if this map contains no key-value mappings.true in case of no elements, false elsepublic int getObjectCounter()
public int getCapacity()
public float getLoadFactor()
public long[] keySet()
public void write(java.io.DataOutputStream out)
throws java.io.IOException
out - the stream to write tojava.io.IOException - in case of any I/O problempublic void read(java.io.DataInputStream in)
throws java.io.IOException
in - the stream to read fromjava.io.IOException - in case of any I/O problempublic void setRehash(boolean rehashing)
true).rehashing - A boolean indicating the desired rehashing status.public void put(long key,
long value)
key - The key with which the specified value is to be associated.value - The value to be associated with the specified key.public long get(long key)
null if the map contains no mapping for this
key. A return value of null does not necessarily indicate
that the map contains no mapping for the key; it is also possible that
the map explicitly maps the key to null. The
containsKey method may be used to distinguish these two
cases.key - The key whose associated value is to be returned.null if the map contains no mapping for this key.public long get(long key,
long deflt)
null if the map contains no mapping for this
key. A return value of null does not necessarily indicate
that the map contains no mapping for the key; it is also possible that
the map explicitly maps the key to null. The
containsKey method may be used to distinguish these two
cases.key - The key whose associated value is to be returned.deflt - the default value to be return if key is not
foundnull if the map contains no mapping for this key
or deflt.public boolean containsKey(long key)
true if this map contains a mapping for the
specified key.key - The key whose presence in this map is to be tested.true if this map contains a mapping for the
specified key.public void remove(long key)
key - The key whose mapping is to be removed from the map.private LongLongHashMap.MapElement exists(long key)
null
if no such element exists.key - the key to search forprivate void rehash()
private void construct(int initialCapacity,
float loadFactor)
initialCapacity - The initial capacity for this hash map.loadFactor - The load factor for this hash map.public void clear()
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable - any exception that may occur during finalizationprivate static final LongLongHashMap.MapElement getMapElementFromPool(long key, long value)
LongLongHashMap.MapElement from the shared pool.key - the key value the resulting element should be initialized withvalue - the value the resulting element should be initialized withreleaseMapElement(MapElement).private static final void releaseMapElement(LongLongHashMap.MapElement mapElement)
LongLongHashMap.MapElement
to the shared pool.mapElement - the LongLongHashMap.MapElement to be released (must not
be null)