Class ConcurrentLongLongHashMap
- java.lang.Object
-
- org.apache.bookkeeper.util.collections.ConcurrentLongLongHashMap
-
public class ConcurrentLongLongHashMap extends java.lang.Object
Concurrent hash map from primitive long to long.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.Keys MUST be >= 0.
WARN: method forEach do not guarantee thread safety, nor do the keys, values and asMap 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, values, and asMap 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 interface
ConcurrentLongLongHashMap.BiConsumerLong
A Long-Long BiConsumer.static class
ConcurrentLongLongHashMap.Builder
Builder of ConcurrentLongLongHashMap.static interface
ConcurrentLongLongHashMap.LongLongFunction
A Long-Long function.static interface
ConcurrentLongLongHashMap.LongLongPredicate
A Long-Long predicate.
-
Constructor Summary
Constructors Constructor Description ConcurrentLongLongHashMap()
Deprecated.ConcurrentLongLongHashMap(int expectedItems)
Deprecated.ConcurrentLongLongHashMap(int expectedItems, int concurrencyLevel)
Deprecated.ConcurrentLongLongHashMap(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
addAndGet(long key, long delta)
Atomically add the specified delta to a current value identified by the key.java.util.Map<java.lang.Long,java.lang.Long>
asMap()
long
capacity()
void
clear()
boolean
compareAndSet(long key, long currentValue, long newValue)
Change the value for a specific key only if it matches the current value.long
computeIfAbsent(long key, ConcurrentLongLongHashMap.LongLongFunction provider)
boolean
containsKey(long key)
void
forEach(ConcurrentLongLongHashMap.BiConsumerLong processor)
long
get(long key)
(package private) long
getUsedBucketCount()
(package private) static long
hash(long key)
boolean
isEmpty()
java.util.List<java.lang.Long>
keys()
static ConcurrentLongLongHashMap.Builder
newBuilder()
long
put(long key, long value)
long
putIfAbsent(long key, long value)
long
remove(long key)
Remove an existing entry if found.boolean
remove(long key, long value)
int
removeIf(java.util.function.LongPredicate filter)
int
removeIf(ConcurrentLongLongHashMap.LongLongPredicate filter)
(package private) static int
signSafeMod(long n, int max)
long
size()
long
sizeInBytes()
java.lang.String
toString()
java.util.List<java.lang.Long>
values()
-
-
-
Constructor Detail
-
ConcurrentLongLongHashMap
@Deprecated public ConcurrentLongLongHashMap()
Deprecated.
-
ConcurrentLongLongHashMap
@Deprecated public ConcurrentLongLongHashMap(int expectedItems)
Deprecated.
-
ConcurrentLongLongHashMap
@Deprecated public ConcurrentLongLongHashMap(int expectedItems, int concurrencyLevel)
Deprecated.
-
ConcurrentLongLongHashMap
public ConcurrentLongLongHashMap(int expectedItems, int concurrencyLevel, float mapFillFactor, float mapIdleFactor, boolean autoShrink, float expandFactor, float shrinkFactor)
-
-
Method Detail
-
newBuilder
public static ConcurrentLongLongHashMap.Builder newBuilder()
-
size
public long size()
-
sizeInBytes
public long sizeInBytes()
-
capacity
public long capacity()
-
isEmpty
public boolean isEmpty()
-
getUsedBucketCount
long getUsedBucketCount()
-
get
public long get(long key)
- Parameters:
key
-- Returns:
- the value or -1 if the key was not present
-
containsKey
public boolean containsKey(long key)
-
put
public long put(long key, long value)
-
putIfAbsent
public long putIfAbsent(long key, long value)
-
computeIfAbsent
public long computeIfAbsent(long key, ConcurrentLongLongHashMap.LongLongFunction provider)
-
addAndGet
public long addAndGet(long key, long delta)
Atomically add the specified delta to a current value identified by the key. If the entry was not in the map, a new entry with default value 0 is added and then the delta is added.- Parameters:
key
- the entry keydelta
- the delta to add- Returns:
- the new value of the entry
- Throws:
java.lang.IllegalArgumentException
- if the delta was invalid, such as it would have caused the value to be < 0
-
compareAndSet
public boolean compareAndSet(long key, long currentValue, long newValue)
Change the value for a specific key only if it matches the current value.- Parameters:
key
-currentValue
-newValue
-- Returns:
-
remove
public long remove(long key)
Remove an existing entry if found.- Parameters:
key
-- Returns:
- the value associated with the key or -1 if key was not present
-
remove
public boolean remove(long key, long value)
-
removeIf
public int removeIf(java.util.function.LongPredicate filter)
-
removeIf
public int removeIf(ConcurrentLongLongHashMap.LongLongPredicate filter)
-
clear
public void clear()
-
forEach
public void forEach(ConcurrentLongLongHashMap.BiConsumerLong processor)
-
keys
public java.util.List<java.lang.Long> keys()
- Returns:
- a new list of all keys (makes a copy)
-
values
public java.util.List<java.lang.Long> values()
-
asMap
public java.util.Map<java.lang.Long,java.lang.Long> asMap()
-
hash
static final long hash(long key)
-
signSafeMod
static final int signSafeMod(long n, int max)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-