Class CopyOnWriteHashMap<K,​V>

<K,​V>
org.elasticsearch.common.collect.CopyOnWriteHashMap<K,​V>
All Implemented Interfaces:
<K,​V>

public final class CopyOnWriteHashMap<K,​V> extends <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:
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.util.

    < extends ,​ extends >, < extends ,​ extends >

    Nested classes/interfaces inherited from interface java.util.

    < extends ,​ extends >
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    static <T> T[]
    appendElement​(T[] array, T element)
     
    boolean
     key)
     
    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>
    <<K1,​V1>> entries)
     
    <? 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>
    <<K1,​V1>> entries)
     
     key)
    Remove the given key from this map.
    <?> keys)
    Same as copyAndRemove(Object) but for an arbitrary number of entries.
    static <K,​ V> CopyOnWriteHashMap<K,​V>
    <? extends K,​? extends V> map)
    Return a copy of the provided map.
    <<K,​V>>
     
     key)
     
    static <T> T[]
    insertElement​(T[] array, T element, int index)
     
    int
     

    Methods inherited from class java.util.

    , , , , , , , , , , ,

    Methods inherited from class java.lang.

    , , , , , ,

    Methods inherited from interface java.util.

    , , , , , , , , , ,
  • Constructor Details

    • CopyOnWriteHashMap

      public CopyOnWriteHashMap()
      Create a new empty map.
  • Method Details

    • copyOf

      public static <K,​ V> <? 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( key)
      Specified by:
       in interface <K,​V>
      Overrides:
       in class <K,​V>
    • get

      public  key)
      Specified by:
       in interface <K,​V>
      Overrides:
       in class <K,​V>
    • size

      public int size()
      Specified by:
       in interface <K,​V>
      Overrides:
       in class <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 <? 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> <<K1,​V1>> entries)
    • copyAndPutAll

      public <K1 extends K,​ V1 extends V> <<K1,​V1>> entries)
    • copyAndRemove

      public  key)
      Remove the given key from this map. The current hash table is not modified.
    • copyAndRemoveAll

      public <?> keys)
      Same as copyAndRemove(Object) but for an arbitrary number of entries.
    • entrySet

      public <<K,​V>> entrySet()
      Specified by:
       in interface <K,​V>
      Specified by:
       in class <K,​V>