Package org.elasticsearch.common.collect
Class CopyOnWriteHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
org.elasticsearch.common.collect.CopyOnWriteHashMap<K,V>
- All Implemented Interfaces:
Map<K,V>
An immutable map whose writes result in a new copy of the map to be created.
This is essentially a hash array mapped trie: inner nodes use a bitmap in
order to map hashes to slots by counting ones. In case of a collision (two
values having the same 32-bits hash), a leaf node is created which stores
and searches for values sequentially.
Reads and writes both perform in logarithmic time. Null keys and values are
not supported.
This structure might need to perform several object creations per write so
it is better suited for work-loads that are not too write-intensive.
- See Also:
- the wikipedia page
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]
appendElement(T[] array, T element)
boolean
containsKey(Object key)
copyAndPut(K key, V value)
Associatekey
withvalue
and return a new copy of the hash table.<K1 extends K, V1 extends V>
CopyOnWriteHashMap<K,V>copyAndPutAll(Iterable<Map.Entry<K1,V1>> entries)
copyAndPutAll(Map<? extends K,? extends V> other)
Same ascopyAndPut(Object, Object)
but for an arbitrary number of entries.<K1 extends K, V1 extends V>
CopyOnWriteHashMap<K,V>copyAndPutAll(Stream<Map.Entry<K1,V1>> entries)
copyAndRemove(Object key)
Remove the given key from this map.copyAndRemoveAll(Collection<?> keys)
Same ascopyAndRemove(Object)
but for an arbitrary number of entries.static <K, V> CopyOnWriteHashMap<K,V>
Return a copy of the provided map.entrySet()
static <T> T[]
insertElement(T[] array, T element, int index)
int
size()
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, isEmpty, keySet, put, putAll, remove, toString, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
CopyOnWriteHashMap
public CopyOnWriteHashMap()Create a new empty map.
-
-
Method Details
-
copyOf
Return a copy of the provided map. -
appendElement
public static <T> T[] appendElement(T[] array, T element) -
insertElement
public static <T> T[] insertElement(T[] array, T element, int index) -
containsKey
- Specified by:
containsKey
in interfaceMap<K,V>
- Overrides:
containsKey
in classAbstractMap<K,V>
-
get
-
size
public int size() -
copyAndPut
Associatekey
withvalue
and return a new copy of the hash table. The current hash table is not modified. -
copyAndPutAll
Same ascopyAndPut(Object, Object)
but for an arbitrary number of entries. -
copyAndPutAll
-
copyAndPutAll
-
copyAndRemove
Remove the given key from this map. The current hash table is not modified. -
copyAndRemoveAll
Same ascopyAndRemove(Object)
but for an arbitrary number of entries. -
entrySet
-