Class ConcurrentLongHashMap<V>
- java.lang.Object
-
- org.apache.bookkeeper.util.collections.ConcurrentLongHashMap<V>
-
- Type Parameters:
V
-
public class ConcurrentLongHashMap<V> extends java.lang.Object
Map from long to an Object.Provides similar methods as a
ConcurrentMap<long,Object>
with 2 differences:- No boxing/unboxing from long -> Long
- Open hash map with linear probing, no node allocations to store the values
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
ConcurrentLongHashMap.Builder<T>
Builder of ConcurrentLongHashMap.static interface
ConcurrentLongHashMap.EntryProcessor<V>
An entry processor.static interface
ConcurrentLongHashMap.LongObjectPredicate<V>
Predicate specialization for (long, V) types.
-
Constructor Summary
Constructors Constructor Description ConcurrentLongHashMap()
Deprecated.ConcurrentLongHashMap(int expectedItems)
Deprecated.ConcurrentLongHashMap(int expectedItems, int concurrencyLevel)
Deprecated.ConcurrentLongHashMap(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(long key, java.util.function.LongFunction<V> provider)
boolean
containsKey(long key)
void
forEach(ConcurrentLongHashMap.EntryProcessor<V> processor)
Iterate over all the entries in the map and apply the processor function to each of them.V
get(long key)
(package private) long
getUsedBucketCount()
(package private) static long
hash(long key)
boolean
isEmpty()
java.util.List<java.lang.Long>
keys()
static <V> ConcurrentLongHashMap.Builder<V>
newBuilder()
V
put(long key, V value)
V
putIfAbsent(long key, V value)
V
remove(long key)
boolean
remove(long key, java.lang.Object value)
int
removeIf(ConcurrentLongHashMap.LongObjectPredicate<V> predicate)
(package private) static int
signSafeMod(long n, int max)
long
size()
java.util.List<V>
values()
-
-
-
Constructor Detail
-
ConcurrentLongHashMap
@Deprecated public ConcurrentLongHashMap()
Deprecated.
-
ConcurrentLongHashMap
@Deprecated public ConcurrentLongHashMap(int expectedItems)
Deprecated.
-
ConcurrentLongHashMap
@Deprecated public ConcurrentLongHashMap(int expectedItems, int concurrencyLevel)
Deprecated.
-
ConcurrentLongHashMap
public ConcurrentLongHashMap(int expectedItems, int concurrencyLevel, float mapFillFactor, float mapIdleFactor, boolean autoShrink, float expandFactor, float shrinkFactor)
-
-
Method Detail
-
newBuilder
public static <V> ConcurrentLongHashMap.Builder<V> newBuilder()
-
size
public long size()
-
getUsedBucketCount
long getUsedBucketCount()
-
capacity
public long capacity()
-
isEmpty
public boolean isEmpty()
-
get
public V get(long key)
-
containsKey
public boolean containsKey(long key)
-
remove
public V remove(long key)
-
remove
public boolean remove(long key, java.lang.Object value)
-
removeIf
public int removeIf(ConcurrentLongHashMap.LongObjectPredicate<V> predicate)
-
clear
public void clear()
-
forEach
public void forEach(ConcurrentLongHashMap.EntryProcessor<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 processor to apply to each entry
-
keys
public java.util.List<java.lang.Long> keys()
- Returns:
- a new list of all keys (makes a copy)
-
values
public java.util.List<V> values()
- Returns:
- a new list of all keys (makes a copy)
-
hash
static final long hash(long key)
-
signSafeMod
static final int signSafeMod(long n, int max)
-
-