Class AtomicHashStore<K,​V>

  • Type Parameters:
    K - the type of keys maintained by this map
    V - the type of mapped values
    All Implemented Interfaces:
    java.io.Serializable

    public final class AtomicHashStore<K,​V>
    extends java.lang.Object
    implements java.io.Serializable
    A thread-safe, immutable key-value store.

    This class corresponds to the internal data store used by AtomicHashMap. All of its operations are thread-safe, atomic and non-blocking, including both reads and writes. All modifications return a new instance of AtomicHashStore containing the modified data.

    This class internall implements an immutable variation of a CTRIE (Concurrent Hash-Trie). This structure is composed of a tree of compact (bitmap-managed) arrays that map keys to positions in each of the tree levels depending on the value of a range of bits of its (modified) hash code.

    Key hash codes (32-bit ints) are divided into five 6-bit segments plus one final 2-bit segment. Each of these segments is used, at each level of depth, to compute the position assigned to the key in the compact array (node) living at that level of depth in the ctrie structure. These are compact arrays with a maximum of 64 positions (bitmaps are long values), each of which can contain either a data entry or a link to another node at level + 1. A maximum of 6 levels can exist (0 to 5), and hash collisions only need to be managed at the deepest level.

    New instances of this class can be created by either calling its constructor AtomicHashStore() or by calling any of its static convenience factory AtomicHashStore.of(...) methods: of(), of(k1, v1), of(k1, v1, k2, v2), of(k1, v1, k2, v2, k3, v3), etc.

    Note that this implementation does not keep the insertion order. Iteration order is not guaranteed to be consistent.

    See Also:
    Serialized Form
    • Constructor Detail

      • AtomicHashStore

        public AtomicHashStore()
      • AtomicHashStore

        AtomicHashStore​(Root root)
    • Method Detail

      • entry

        private static Entry entry​(java.lang.Object key,
                                   java.lang.Object value)
      • entry

        private static Entry entry​(int hash,
                                   java.lang.Object key,
                                   java.lang.Object value)
      • of

        public static <K,​V> AtomicHashStore<K,​V> of​(K k1,
                                                                V v1,
                                                                K k2,
                                                                V v2)
      • of

        public static <K,​V> AtomicHashStore<K,​V> of​(K k1,
                                                                V v1,
                                                                K k2,
                                                                V v2,
                                                                K k3,
                                                                V v3)
      • of

        public static <K,​V> AtomicHashStore<K,​V> of​(K k1,
                                                                V v1,
                                                                K k2,
                                                                V v2,
                                                                K k3,
                                                                V v3,
                                                                K k4,
                                                                V v4)
      • of

        public static <K,​V> AtomicHashStore<K,​V> of​(K k1,
                                                                V v1,
                                                                K k2,
                                                                V v2,
                                                                K k3,
                                                                V v3,
                                                                K k4,
                                                                V v4,
                                                                K k5,
                                                                V v5)
      • of

        public static <K,​V> AtomicHashStore<K,​V> of​(K k1,
                                                                V v1,
                                                                K k2,
                                                                V v2,
                                                                K k3,
                                                                V v3,
                                                                K k4,
                                                                V v4,
                                                                K k5,
                                                                V v5,
                                                                K k6,
                                                                V v6)
      • of

        public static <K,​V> AtomicHashStore<K,​V> of​(K k1,
                                                                V v1,
                                                                K k2,
                                                                V v2,
                                                                K k3,
                                                                V v3,
                                                                K k4,
                                                                V v4,
                                                                K k5,
                                                                V v5,
                                                                K k6,
                                                                V v6,
                                                                K k7,
                                                                V v7)
      • of

        public static <K,​V> AtomicHashStore<K,​V> of​(K k1,
                                                                V v1,
                                                                K k2,
                                                                V v2,
                                                                K k3,
                                                                V v3,
                                                                K k4,
                                                                V v4,
                                                                K k5,
                                                                V v5,
                                                                K k6,
                                                                V v6,
                                                                K k7,
                                                                V v7,
                                                                K k8,
                                                                V v8)
      • of

        public static <K,​V> AtomicHashStore<K,​V> of​(K k1,
                                                                V v1,
                                                                K k2,
                                                                V v2,
                                                                K k3,
                                                                V v3,
                                                                K k4,
                                                                V v4,
                                                                K k5,
                                                                V v5,
                                                                K k6,
                                                                V v6,
                                                                K k7,
                                                                V v7,
                                                                K k8,
                                                                V v8,
                                                                K k9,
                                                                V v9)
      • of

        public static <K,​V> AtomicHashStore<K,​V> of​(K k1,
                                                                V v1,
                                                                K k2,
                                                                V v2,
                                                                K k3,
                                                                V v3,
                                                                K k4,
                                                                V v4,
                                                                K k5,
                                                                V v5,
                                                                K k6,
                                                                V v6,
                                                                K k7,
                                                                V v7,
                                                                K k8,
                                                                V v8,
                                                                K k9,
                                                                V v9,
                                                                K k10,
                                                                V v10)
      • innerRoot

        Root innerRoot()
      • size

        public int size()
      • isEmpty

        public boolean isEmpty()
      • containsKey

        public boolean containsKey​(java.lang.Object key)
      • containsValue

        public boolean containsValue​(java.lang.Object value)
      • get

        public V get​(java.lang.Object key)
      • getOrDefault

        public V getOrDefault​(java.lang.Object key,
                              V defaultValue)
      • getAll

        public java.util.Map<K,​V> getAll​(java.lang.Object... keys)
      • putAll

        public AtomicHashStore<K,​V> putAll​(java.util.Map<? extends K,​? extends V> newMappings)
      • remove

        public AtomicHashStore<K,​V> remove​(java.lang.Object key,
                                                 java.lang.Object oldValue)
      • keySet

        public java.util.Set<K> keySet()
      • values

        public java.util.Collection<V> values()
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
      • forEach

        public void forEach​(java.util.function.BiConsumer<? super K,​? super V> action)
      • replaceAll

        public AtomicHashStore<K,​V> replaceAll​(java.util.function.BiFunction<? super K,​? super V,​? extends V> function)
      • compute

        public AtomicHashStore<K,​V> compute​(K key,
                                                  java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction)
      • computeIfAbsent

        public AtomicHashStore<K,​V> computeIfAbsent​(K key,
                                                          java.util.function.Function<? super K,​? extends V> mappingFunction)
      • computeIfPresent

        public AtomicHashStore<K,​V> computeIfPresent​(K key,
                                                           java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction)
      • merge

        public AtomicHashStore<K,​V> merge​(K key,
                                                V newValue,
                                                java.util.function.BiFunction<? super V,​? super V,​? extends V> remappingFunction)
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object