Class ConcurrentChainedReference2ReferenceHashTable<K,V>
- Type Parameters:
K- The type for keys in this mapV- The type for values in this map
- All Implemented Interfaces:
Iterable<ConcurrentChainedReference2ReferenceHashTable.TableEntry<K,V>>
K values onto non-null V
values with support for multiple writer and multiple reader threads.
Happens-before relationship
As with ConcurrentMap, there is a happens-before relationship between actions in one thread
prior to writing to the map and access to the results of those actions in another thread.
Atomicity of functional methods
Functional methods are functions declared in this class which possibly perform a write (remove, replace, or modify) to an entry in this map as a result of invoking a function on an input parameter. Functional methods will be performed atomically, that is, the input parameter is guaranteed to only be invoked at most once per function call. However, the consequence of this behaviour is that a critical lock for a bin entry is held, which means that if the input parameter invocation makes additional calls to write into this hash table that the result is undefined and deadlock-prone.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfaceprotected static final classprotected static classprotected static final classprotected static classprotected static classstatic interfacestatic final classprotected static final classprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final floatprotected final floatprotected static final intprotected ConcurrentChainedReference2ReferenceHashTable.TableEntry<K,V>[] protected final AtomicLongprotected ConcurrentChainedReference2ReferenceHashTable.TableEntry<K,V>[] protected intprotected static final VarHandleprotected static final intprotected static final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConcurrentChainedReference2ReferenceHashTable(int capacity, float loadFactor) -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddSize(long count) Adds count to size and checks threshold for resizingvoidclear()Removes at least all entries currently mapped at the beginning of this call.protected static <K,V> ConcurrentChainedReference2ReferenceHashTable.TableEntry <K, V> compareAndExchangeAtIndexVolatile(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] table, int index, ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V> expect, ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V> update) protected final intcompareExchangeThresholdVolatile(int expect, int update) compute(K key, ConcurrentChainedReference2ReferenceHashTable.BiObjectObjectObjectFunction<K, ? super V, ? extends V> function) computeIfAbsent(K key, ConcurrentChainedReference2ReferenceHashTable.BiObjectObjectFunction<? super K, ? extends V> function) computeIfPresent(K key, ConcurrentChainedReference2ReferenceHashTable.BiObjectObjectObjectFunction<K, ? super V, ? extends V> function) booleanReturns whether the specified key is mapped and is mapped to the specified value.booleancontainsKey(K key) Returns whether the specified key is mapped to some value.booleancontainsValue(V value) Returns whether the specified value has a key mapped to it.static <K,V> ConcurrentChainedReference2ReferenceHashTable <K, V> createWithCapacity(int capacity) static <K,V> ConcurrentChainedReference2ReferenceHashTable <K, V> createWithCapacity(int capacity, float loadFactor) static <K,V> ConcurrentChainedReference2ReferenceHashTable <K, V> createWithExpected(int expected) static <K,V> ConcurrentChainedReference2ReferenceHashTable <K, V> createWithExpected(int expected, float loadFactor) static intstatic floatReturns an iterator over the entries in this map.entrySet()protected ConcurrentChainedReference2ReferenceHashTable.TableEntry<K,V>[] fetchNewTable(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] expectedCurr) Returns the currently mapped value associated with the specified key, ornullif there is none.protected static <K,V> ConcurrentChainedReference2ReferenceHashTable.TableEntry <K, V> getAtIndexAcquire(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] table, int index) protected static intgetCapacityFor(int capacity) protected static intmust be deterministic given a keyfinal floatReturns the load factor associated with this map.protected final ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V> Returns the possible node associated with the key, ornullif there is no such node.getOrDefault(K key, V defaultValue) Returns the currently mapped value associated with the specified key, or the specified default value if there is none.protected static intgetTargetThreshold(int capacity, float loadFactor) protected final intprotected final intbooleanisEmpty()Returns whether this map has no mappings.iterator()Returns an iterator over the keys in this map.keys()Atomically updates the value associated withkeytovalue, or inserts a new mapping withkeymapped tovalue.putIfAbsent(K key, V value) Atomically inserts a new mapping withkeymapped tovalueif and only ifkeyis not currently mapped to some value.Atomically removes the mapping for the specified key and returns the value it was associated with.Atomically removes the mapping for the specified key if it is mapped toexpectand returnsexpect.removeIf(K key, ConcurrentChainedReference2ReferenceHashTable.RemoveIfPredicate<K, ? super V> predicate) Atomically removes the mapping for the specified key the predicate returns true for its currently mapped value.Atomically updates the value associated withkeytovalue, or does nothing ifkeyis not associated with a value.Atomically updates the value associated withkeytoupdateif the currently associated value is equal toexpect, otherwise does nothing.protected static <K,V> void setAtIndexRelease(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] table, int index, ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V> value) protected static <K,V> void setAtIndexVolatile(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] table, int index, ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V> value) protected final voidsetThresholdPlain(int threshold) protected final voidsetThresholdRelease(int threshold) protected final voidsetThresholdVolatile(int threshold) intsize()Returns the number of mappings in this map.protected final voidsubSize(long count) Subtracts count from sizeReturns an iterator over the values in this map.values()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_CAPACITY
protected static final int DEFAULT_CAPACITY- See Also:
-
DEFAULT_LOAD_FACTOR
protected static final float DEFAULT_LOAD_FACTOR- See Also:
-
MAXIMUM_CAPACITY
protected static final int MAXIMUM_CAPACITY- See Also:
-
size
-
loadFactor
protected final float loadFactor -
table
-
nextTable
-
THRESHOLD_NO_RESIZE
protected static final int THRESHOLD_NO_RESIZE- See Also:
-
THRESHOLD_RESIZING
protected static final int THRESHOLD_RESIZING- See Also:
-
threshold
protected volatile int threshold -
THRESHOLD_HANDLE
-
keys
-
values
-
entrySet
-
-
Constructor Details
-
ConcurrentChainedReference2ReferenceHashTable
public ConcurrentChainedReference2ReferenceHashTable() -
ConcurrentChainedReference2ReferenceHashTable
protected ConcurrentChainedReference2ReferenceHashTable(int capacity, float loadFactor)
-
-
Method Details
-
defaultCapacity
public static int defaultCapacity() -
defaultLoadFactor
public static float defaultLoadFactor() -
getThresholdAcquire
protected final int getThresholdAcquire() -
getThresholdVolatile
protected final int getThresholdVolatile() -
setThresholdPlain
protected final void setThresholdPlain(int threshold) -
setThresholdRelease
protected final void setThresholdRelease(int threshold) -
setThresholdVolatile
protected final void setThresholdVolatile(int threshold) -
compareExchangeThresholdVolatile
protected final int compareExchangeThresholdVolatile(int expect, int update) -
getTargetThreshold
protected static int getTargetThreshold(int capacity, float loadFactor) -
getCapacityFor
protected static int getCapacityFor(int capacity) -
createWithCapacity
public static <K,V> ConcurrentChainedReference2ReferenceHashTable<K,V> createWithCapacity(int capacity) -
createWithCapacity
public static <K,V> ConcurrentChainedReference2ReferenceHashTable<K,V> createWithCapacity(int capacity, float loadFactor) -
createWithExpected
public static <K,V> ConcurrentChainedReference2ReferenceHashTable<K,V> createWithExpected(int expected) -
createWithExpected
public static <K,V> ConcurrentChainedReference2ReferenceHashTable<K,V> createWithExpected(int expected, float loadFactor) -
getHash
must be deterministic given a key -
getLoadFactor
public final float getLoadFactor()Returns the load factor associated with this map. -
getAtIndexAcquire
protected static <K,V> ConcurrentChainedReference2ReferenceHashTable.TableEntry<K,V> getAtIndexAcquire(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] table, int index) -
setAtIndexRelease
protected static <K,V> void setAtIndexRelease(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] table, int index, ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V> value) -
setAtIndexVolatile
protected static <K,V> void setAtIndexVolatile(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] table, int index, ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V> value) -
compareAndExchangeAtIndexVolatile
protected static <K,V> ConcurrentChainedReference2ReferenceHashTable.TableEntry<K,V> compareAndExchangeAtIndexVolatile(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] table, int index, ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V> expect, ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V> update) -
fetchNewTable
protected ConcurrentChainedReference2ReferenceHashTable.TableEntry<K,V>[] fetchNewTable(ConcurrentChainedReference2ReferenceHashTable.TableEntry<K, V>[] expectedCurr) -
getNode
Returns the possible node associated with the key, ornullif there is no such node. The node returned may have anullConcurrentChainedReference2ReferenceHashTable.TableEntry.value, in which case the node is a placeholder for a compute/computeIfAbsent call. The placeholder node should not be considered mapped in order to preserve happens-before relationships between writes and reads in the map. -
get
Returns the currently mapped value associated with the specified key, ornullif there is none.- Parameters:
key- Specified key- Throws:
NullPointerException- If key is null
-
getOrDefault
Returns the currently mapped value associated with the specified key, or the specified default value if there is none.- Parameters:
key- Specified keydefaultValue- Specified default value- Throws:
NullPointerException- If key is null
-
containsKey
Returns whether the specified key is mapped to some value.- Parameters:
key- Specified key- Throws:
NullPointerException- If key is null
-
containsValue
Returns whether the specified value has a key mapped to it.- Parameters:
value- Specified value- Throws:
NullPointerException- If value is null
-
contains
Returns whether the specified key is mapped and is mapped to the specified value.- Parameters:
key- Specified keyvalue- Specified value- Throws:
NullPointerException- If key is nullNullPointerException- If value is null
-
size
public int size()Returns the number of mappings in this map. -
isEmpty
public boolean isEmpty()Returns whether this map has no mappings. -
addSize
protected final void addSize(long count) Adds count to size and checks threshold for resizing -
subSize
protected final void subSize(long count) Subtracts count from size -
put
Atomically updates the value associated withkeytovalue, or inserts a new mapping withkeymapped tovalue.- Parameters:
key- Specified keyvalue- Specified value- Returns:
- Old value previously associated with key, or
nullif none. - Throws:
NullPointerException- If key is nullNullPointerException- If value is null
-
putIfAbsent
Atomically inserts a new mapping withkeymapped tovalueif and only ifkeyis not currently mapped to some value.- Parameters:
key- Specified keyvalue- Specified value- Returns:
- Value currently associated with key, or
nullif none andvaluewas associated. - Throws:
NullPointerException- If key is nullNullPointerException- If value is null
-
replace
Atomically updates the value associated withkeytovalue, or does nothing ifkeyis not associated with a value.- Parameters:
key- Specified keyvalue- Specified value- Returns:
- Old value previously associated with key, or
nullif none. - Throws:
NullPointerException- If key is nullNullPointerException- If value is null
-
replace
Atomically updates the value associated withkeytoupdateif the currently associated value is equal toexpect, otherwise does nothing.- Parameters:
key- Specified keyexpect- Expected value to check current mapped value withupdate- Update value to replace mapped value with- Returns:
- If the currently mapped value is not equal to
expect, then returns the currently mapped value. If the key is not mapped to any value, then returnsnull. If neither of the two cases are true, then returnsexpect. - Throws:
NullPointerException- If key is nullNullPointerException- If expect is nullNullPointerException- If update is null
-
remove
Atomically removes the mapping for the specified key and returns the value it was associated with. If the key is not mapped to a value, then does nothing and returnsnull.- Parameters:
key- Specified key- Returns:
- Old value previously associated with key, or
nullif none. - Throws:
NullPointerException- If key is null
-
remove
Atomically removes the mapping for the specified key if it is mapped toexpectand returnsexpect. If the key is not mapped to a value, then does nothing and returnsnull. If the key is mapped to a value that is not equal toexpect, then returns that value.- Parameters:
key- Specified keyexpect- Specified expected value- Returns:
- The specified expected value if the key was mapped to
expect. If the key is not mapped to any value, then returnsnull. If neither of those cases are true, then returns the current mapped value for key. - Throws:
NullPointerException- If key is null
-
removeIf
public V removeIf(K key, ConcurrentChainedReference2ReferenceHashTable.RemoveIfPredicate<K, ? super V> predicate) Atomically removes the mapping for the specified key the predicate returns true for its currently mapped value. If the key is not mapped to a value, then does nothing and returnsnull.This function is a "functional method" as defined by
ConcurrentChainedReference2ReferenceHashTable.- Parameters:
key- Specified keypredicate- Specified predicate- Returns:
- The specified expected value if the key was mapped to
expect. If the key is not mapped to any value, then returnsnull. If neither of those cases are true, then returns the current (non-null) mapped value for key. - Throws:
NullPointerException- If key is nullNullPointerException- If predicate is null
-
compute
public V compute(K key, ConcurrentChainedReference2ReferenceHashTable.BiObjectObjectObjectFunction<K, ? super V, ? extends V> function) SeeConcurrentMap.compute(Object, BiFunction)This function is a "functional method" as defined by
ConcurrentChainedReference2ReferenceHashTable. -
computeIfAbsent
public V computeIfAbsent(K key, ConcurrentChainedReference2ReferenceHashTable.BiObjectObjectFunction<? super K, ? extends V> function) SeeConcurrentMap.computeIfAbsent(Object, Function)This function is a "functional method" as defined by
ConcurrentChainedReference2ReferenceHashTable. -
computeIfPresent
public V computeIfPresent(K key, ConcurrentChainedReference2ReferenceHashTable.BiObjectObjectObjectFunction<K, ? super V, ? extends V> function) SeeConcurrentMap.computeIfPresent(Object, BiFunction)This function is a "functional method" as defined by
ConcurrentChainedReference2ReferenceHashTable. -
merge
SeeConcurrentMap.merge(Object, Object, BiFunction)This function is a "functional method" as defined by
ConcurrentChainedReference2ReferenceHashTable. -
clear
public void clear()Removes at least all entries currently mapped at the beginning of this call. May not remove entries added during this call. As a result, only if this map is not modified during the call, that all entries will be removed by the end of the call.This function is not atomic.
-
entryIterator
public BaseObjectIterator<ConcurrentChainedReference2ReferenceHashTable.TableEntry<K,V>> entryIterator()Returns an iterator over the entries in this map. The iterator is only guaranteed to see entries that were added before the beginning of this call, but it may see entries added during. -
iterator
public final BaseObjectIterator<ConcurrentChainedReference2ReferenceHashTable.TableEntry<K,V>> iterator() -
keyIterator
Returns an iterator over the keys in this map. The iterator is only guaranteed to see keys that were added before the beginning of this call, but it may see keys added during. -
valueIterator
Returns an iterator over the values in this map. The iterator is only guaranteed to see values that were added before the beginning of this call, but it may see values added during. -
keys
-
values
-
entrySet
-