Class ConcurrentLongLongHashMap
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 ClassesModifier and TypeClassDescriptionstatic interfaceA Long-Long BiConsumer.static classBuilder of ConcurrentLongLongHashMap.static interfaceA Long-Long function.static interfaceA Long-Long predicate. -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.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
Modifier and TypeMethodDescriptionlongaddAndGet(long key, long delta) Atomically add the specified delta to a current value identified by the key.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) long(package private) static final longhash(long key) booleanisEmpty()keys()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(LongPredicate filter) int(package private) static final intsignSafeMod(long n, int max) longsize()longtoString()values()
-
Constructor Details
-
ConcurrentLongLongHashMap
Deprecated. -
ConcurrentLongLongHashMap
Deprecated. -
ConcurrentLongLongHashMap
Deprecated. -
ConcurrentLongLongHashMap
public ConcurrentLongLongHashMap(int expectedItems, int concurrencyLevel, float mapFillFactor, float mapIdleFactor, boolean autoShrink, float expandFactor, float shrinkFactor)
-
-
Method Details
-
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
-
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:
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
-
removeIf
-
clear
public void clear() -
forEach
-
keys
- Returns:
- a new list of all keys (makes a copy)
-
values
-
asMap
-
hash
static final long hash(long key) -
signSafeMod
static final int signSafeMod(long n, int max) -
toString
-