Class AtomicHashStore<K,V>
- java.lang.Object
-
- io.arxila.atomichash.AtomicHashStore<K,V>
-
- Type Parameters:
K- the type of keys maintained by this mapV- the type of mapped values
- All Implemented Interfaces:
java.io.Serializable
public final class AtomicHashStore<K,V> extends java.lang.Object implements java.io.SerializableA 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 ofAtomicHashStorecontaining 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
-
-
Field Summary
Fields Modifier and Type Field Description private Rootrootprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description AtomicHashStore()AtomicHashStore(Root root)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AtomicHashStore<K,V>clear()AtomicHashStore<K,V>compute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)AtomicHashStore<K,V>computeIfAbsent(K key, java.util.function.Function<? super K,? extends V> mappingFunction)AtomicHashStore<K,V>computeIfPresent(K key, java.util.function.BiFunction<? super K,? super V,? extends V> remappingFunction)booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)private static Entryentry(int hash, java.lang.Object key, java.lang.Object value)private static Entryentry(java.lang.Object key, java.lang.Object value)java.util.Set<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object other)voidforEach(java.util.function.BiConsumer<? super K,? super V> action)Vget(java.lang.Object key)java.util.Map<K,V>getAll(java.lang.Object... keys)VgetOrDefault(java.lang.Object key, V defaultValue)inthashCode()(package private) RootinnerRoot()booleanisEmpty()java.util.Set<K>keySet()AtomicHashStore<K,V>merge(K key, V newValue, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)static <K,V>
AtomicHashStore<K,V>of()static <K,V>
AtomicHashStore<K,V>of(K k1, V v1)static <K,V>
AtomicHashStore<K,V>of(K k1, V v1, K k2, V v2)static <K,V>
AtomicHashStore<K,V>of(K k1, V v1, K k2, V v2, K k3, V v3)static <K,V>
AtomicHashStore<K,V>of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)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)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)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)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)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)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)AtomicHashStore<K,V>put(K key, V newValue)AtomicHashStore<K,V>putAll(java.util.Map<? extends K,? extends V> newMappings)AtomicHashStore<K,V>putIfAbsent(K key, V newValue)AtomicHashStore<K,V>remove(java.lang.Object key)AtomicHashStore<K,V>remove(java.lang.Object key, java.lang.Object oldValue)AtomicHashStore<K,V>replace(K key, V newValue)AtomicHashStore<K,V>replace(K key, V oldValue, V newValue)AtomicHashStore<K,V>replaceAll(java.util.function.BiFunction<? super K,? super V,? extends V> function)intsize()AtomicHashStore<K,V>toStore()java.lang.StringtoString()java.util.Collection<V>values()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
root
private final Root root
-
-
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()
-
of
public static <K,V> AtomicHashStore<K,V> of(K k1, V v1)
-
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()
-
toStore
public AtomicHashStore<K,V> toStore()
-
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)
-
put
public AtomicHashStore<K,V> put(K key, V newValue)
-
putIfAbsent
public AtomicHashStore<K,V> putIfAbsent(K key, V newValue)
-
putAll
public AtomicHashStore<K,V> putAll(java.util.Map<? extends K,? extends V> newMappings)
-
remove
public AtomicHashStore<K,V> remove(java.lang.Object key)
-
remove
public AtomicHashStore<K,V> remove(java.lang.Object key, java.lang.Object oldValue)
-
clear
public AtomicHashStore<K,V> clear()
-
keySet
public java.util.Set<K> keySet()
-
values
public java.util.Collection<V> values()
-
replace
public AtomicHashStore<K,V> replace(K key, V newValue)
-
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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-