Class CopyOnWriteHashMap<K,​V>

java.lang.Object
java.util.AbstractMap<K,​V>
org.elasticsearch.common.collect.CopyOnWriteHashMap<K,​V>
All Implemented Interfaces:
java.util.Map<K,​V>

public final class CopyOnWriteHashMap<K,​V>
extends java.util.AbstractMap<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

    java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>

    Nested classes/interfaces inherited from interface java.util.Map

    java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
  • Constructor Summary

    Constructors 
    Constructor Description
    CopyOnWriteHashMap()
    Create a new empty map.
  • Method Summary

    Modifier and Type Method Description
    static <T> T[] appendElement​(T[] array, T element)  
    boolean containsKey​(java.lang.Object key)  
    CopyOnWriteHashMap<K,​V> copyAndPut​(K key, V value)
    Associate key with value and return a new copy of the hash table.
    <K1 extends K,​ V1 extends V>
    CopyOnWriteHashMap<K,​V>
    copyAndPutAll​(java.lang.Iterable<java.util.Map.Entry<K1,​V1>> entries)  
    CopyOnWriteHashMap<K,​V> copyAndPutAll​(java.util.Map<? extends K,​? extends V> other)
    Same as copyAndPut(Object, Object) but for an arbitrary number of entries.
    <K1 extends K,​ V1 extends V>
    CopyOnWriteHashMap<K,​V>
    copyAndPutAll​(java.util.stream.Stream<java.util.Map.Entry<K1,​V1>> entries)  
    CopyOnWriteHashMap<K,​V> copyAndRemove​(java.lang.Object key)
    Remove the given key from this map.
    CopyOnWriteHashMap<K,​V> copyAndRemoveAll​(java.util.Collection<?> keys)
    Same as copyAndRemove(Object) but for an arbitrary number of entries.
    static <K,​ V> CopyOnWriteHashMap<K,​V> copyOf​(java.util.Map<? extends K,​? extends V> map)
    Return a copy of the provided map.
    java.util.Set<java.util.Map.Entry<K,​V>> entrySet()  
    V get​(java.lang.Object key)  
    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

  • Method Details

    • copyOf

      public static <K,​ V> CopyOnWriteHashMap<K,​V> copyOf​(java.util.Map<? extends K,​? extends V> map)
      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

      public boolean containsKey​(java.lang.Object key)
      Specified by:
      containsKey in interface java.util.Map<K,​V>
      Overrides:
      containsKey in class java.util.AbstractMap<K,​V>
    • get

      public V get​(java.lang.Object key)
      Specified by:
      get in interface java.util.Map<K,​V>
      Overrides:
      get in class java.util.AbstractMap<K,​V>
    • size

      public int size()
      Specified by:
      size in interface java.util.Map<K,​V>
      Overrides:
      size in class java.util.AbstractMap<K,​V>
    • copyAndPut

      public CopyOnWriteHashMap<K,​V> copyAndPut​(K key, V value)
      Associate key with value and return a new copy of the hash table. The current hash table is not modified.
    • copyAndPutAll

      public CopyOnWriteHashMap<K,​V> copyAndPutAll​(java.util.Map<? extends K,​? extends V> other)
      Same as copyAndPut(Object, Object) but for an arbitrary number of entries.
    • copyAndPutAll

      public <K1 extends K,​ V1 extends V> CopyOnWriteHashMap<K,​V> copyAndPutAll​(java.lang.Iterable<java.util.Map.Entry<K1,​V1>> entries)
    • copyAndPutAll

      public <K1 extends K,​ V1 extends V> CopyOnWriteHashMap<K,​V> copyAndPutAll​(java.util.stream.Stream<java.util.Map.Entry<K1,​V1>> entries)
    • copyAndRemove

      public CopyOnWriteHashMap<K,​V> copyAndRemove​(java.lang.Object key)
      Remove the given key from this map. The current hash table is not modified.
    • copyAndRemoveAll

      public CopyOnWriteHashMap<K,​V> copyAndRemoveAll​(java.util.Collection<?> keys)
      Same as copyAndRemove(Object) but for an arbitrary number of entries.
    • entrySet

      public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
      Specified by:
      entrySet in interface java.util.Map<K,​V>
      Specified by:
      entrySet in class java.util.AbstractMap<K,​V>