K - the type of keys maintained by this mapV - the type of mapped valuespublic class CompactHashMap<K,V> extends Object implements Map<K,V>, Serializable
This implementation provides constant access time for the basic operations (get and put). The get operation does not create objects. put creates array objects when resizing is required.
The expected runtime is as follows (measured in hashmap and array accesses): best case worst case get 1 hashmap + 1 array 2 hashmap put 1 hashmap + 1 array 6 hashmap
The expected memory consumption (8u40, 64 bit, compressed references) is as follows: # of elements CompactHashMap HashMap (with 1.0 fillFactor) 0 32 48 1 32 104 2 32 136 3 32 176 4 64 208 5 64 256 6 64 288 7 72 320 8 72 352 In other words, the first three non default values consume the same 32 bytes, then map grows as 32 + 16 + 4 * (n-2) == 40 + 4 * n. Regular HashMap grows as 64 + 36 * n.
Note that map keys must be reused (you should not use unique objects for keys), otherwise you will run out of memory.
Note that this implementation is not synchronized If multiple threads access the map concurrently, and at least one of the threads modifies the map, it must be synchronized externally.
| Constructor and Description |
|---|
CompactHashMap() |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object key) |
boolean |
isEmpty() |
Set<K> |
keySet() |
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> m) |
V |
putOrRemove(K key,
Object value) |
V |
remove(Object key) |
int |
size() |
Collection<V> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllCopyright © 2015. All rights reserved.