Class ConcurrentOpenHashMap<K,V>
- java.lang.Object
-
- org.apache.bookkeeper.util.collections.ConcurrentOpenHashMap<K,V>
-
- Type Parameters:
V
-
public class ConcurrentOpenHashMap<K,V> extends java.lang.Object
Concurrent hash map.Provides similar methods as a
ConcurrentMap<K,V>
but since it's an open hash map with linear probing, no node allocations are required to store the values
WARN: method forEach do not guarantee thread safety, nor do the keys and values method.
The forEach method is specifically designed for single-threaded usage. When iterating over a map with concurrent writes, it becomes possible for new values to be either observed or not observed. There is no guarantee that if we write value1 and value2, and are able to see value2, then we will also see value1. In some cases, it is even possible to encounter two mappings with the same key, leading the keys method to return a List containing two identical keys.
It is crucial to understand that the results obtained from aggregate status methods such as keys and values are typically reliable only when the map is not undergoing concurrent updates from other threads. When concurrent updates are involved, the results of these methods reflect transient states that may be suitable for monitoring or estimation purposes, but not for program control.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConcurrentOpenHashMap.Builder<K,V>
Builder of ConcurrentOpenHashMap.
-
Constructor Summary
Constructors Constructor Description ConcurrentOpenHashMap()
Deprecated.ConcurrentOpenHashMap(int expectedItems)
Deprecated.ConcurrentOpenHashMap(int expectedItems, int concurrencyLevel)
Deprecated.ConcurrentOpenHashMap(int expectedItems, int concurrencyLevel, float mapFillFactor, float mapIdleFactor, boolean autoShrink, float expandFactor, float shrinkFactor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
capacity()
void
clear()
V
computeIfAbsent(K key, java.util.function.Function<K,V> provider)
boolean
containsKey(K key)
void
forEach(java.util.function.BiConsumer<? super K,? super V> processor)
Iterate over all the entries in the map and apply the processor function to each of them.V
get(K key)
(package private) long
getUsedBucketCount()
(package private) static <K> long
hash(K key)
boolean
isEmpty()
java.util.List<K>
keys()
static <K,V>
ConcurrentOpenHashMap.Builder<K,V>newBuilder()
V
put(K key, V value)
V
putIfAbsent(K key, V value)
V
remove(K key)
boolean
remove(K key, java.lang.Object value)
int
removeIf(java.util.function.BiPredicate<K,V> filter)
(package private) static int
signSafeMod(long n, int max)
long
size()
java.util.List<V>
values()
-
-
-
Constructor Detail
-
ConcurrentOpenHashMap
@Deprecated public ConcurrentOpenHashMap()
Deprecated.
-
ConcurrentOpenHashMap
@Deprecated public ConcurrentOpenHashMap(int expectedItems)
Deprecated.
-
ConcurrentOpenHashMap
@Deprecated public ConcurrentOpenHashMap(int expectedItems, int concurrencyLevel)
Deprecated.
-
ConcurrentOpenHashMap
public ConcurrentOpenHashMap(int expectedItems, int concurrencyLevel, float mapFillFactor, float mapIdleFactor, boolean autoShrink, float expandFactor, float shrinkFactor)
-
-
Method Detail
-
newBuilder
public static <K,V> ConcurrentOpenHashMap.Builder<K,V> newBuilder()
-
getUsedBucketCount
long getUsedBucketCount()
-
size
public long size()
-
capacity
public long capacity()
-
isEmpty
public boolean isEmpty()
-
containsKey
public boolean containsKey(K key)
-
remove
public boolean remove(K key, java.lang.Object value)
-
clear
public void clear()
-
forEach
public void forEach(java.util.function.BiConsumer<? super K,? super V> processor)
Iterate over all the entries in the map and apply the processor function to each of them.Warning: Do Not Guarantee Thread-Safety.
- Parameters:
processor
- the function to apply to each entry
-
keys
public java.util.List<K> keys()
- Returns:
- a new list of all keys (makes a copy)
-
values
public java.util.List<V> values()
-
hash
static final <K> long hash(K key)
-
signSafeMod
static final int signSafeMod(long n, int max)
-
-