Class ConcurrentLongLongHashMap
- java.lang.Object
-
- org.apache.bookkeeper.util.collections.ConcurrentLongLongHashMap
-
public class ConcurrentLongLongHashMap extends java.lang.ObjectConcurrent 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 interfaceConcurrentLongLongHashMap.BiConsumerLongA Long-Long BiConsumer.static classConcurrentLongLongHashMap.BuilderBuilder of ConcurrentLongLongHashMap.static interfaceConcurrentLongLongHashMap.LongLongFunctionA Long-Long function.static interfaceConcurrentLongLongHashMap.LongLongPredicateA 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 longaddAndGet(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()longcapacity()voidclear()booleancompareAndSet(long key, long currentValue, long newValue)Change the value for a specific key only if it matches the current value.longcomputeIfAbsent(long key, ConcurrentLongLongHashMap.LongLongFunction provider)booleancontainsKey(long key)voidforEach(ConcurrentLongLongHashMap.BiConsumerLong processor)longget(long key)(package private) longgetUsedBucketCount()(package private) static longhash(long key)booleanisEmpty()java.util.List<java.lang.Long>keys()static ConcurrentLongLongHashMap.BuildernewBuilder()longput(long key, long value)longputIfAbsent(long key, long value)longremove(long key)Remove an existing entry if found.booleanremove(long key, long value)intremoveIf(java.util.function.LongPredicate filter)intremoveIf(ConcurrentLongLongHashMap.LongLongPredicate filter)(package private) static intsignSafeMod(long n, int max)longsize()longsizeInBytes()java.lang.StringtoString()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:
toStringin classjava.lang.Object
-
-