ConcurrentNavigableMap implementation.
The map is sorted according to the natural
ordering of its keys, or by a Comparator provided at map
creation time, depending on which constructor is used.
This class implements a concurrent variant of SkipLists
providing expected average log(n) time cost for the
containsKey, get, put and
remove operations and their variants. Insertion, removal,
update, and access operations safely execute concurrently by
multiple threads.
Iterators and spliterators are weakly consistent.
Ascending key ordered views and their iterators are faster than descending ones.
All Map.Entry pairs returned by methods in this class
and its views represent snapshots of mappings at the time they were
produced. They do not support the Entry.setValue
method. (Note however that it is possible to change mappings in the
associated map using put, putIfAbsent, or
replace, depending on exactly which effect you need.)
Beware that bulk operations putAll, equals,
toArray, containsValue, and clear are
not guaranteed to be performed atomically. For example, an
iterator operating concurrently with a putAll operation
might view only some of the added elements.
This class and its views and iterators implement all of the
optional methods of the Map and Iterator
interfaces. Like most other concurrent collections, this class does
not permit the use of null keys or values because some
null return values cannot be reliably distinguished from the absence of
elements.
This class is a member of the Java Collections Framework.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv abstract static class | |
| pack-priv class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv abstract class | |
| pack-priv class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | ConcurrentSkipListMap.
Nodes hold keys and values, and are singly linked in sorted order, possibly with some intervening marker nodes. |
| pack-priv static class | ConcurrentSkipListMap.
Submaps returned by |
| pack-priv class | |
| pack-priv static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private transient LongAdder | adder
Lazily initialized element count |
| private static final VarHandle | |
| pack-priv final Comparator | comparator
The comparator used to maintain order in this map, or null if using natural ordering. |
| private transient ConcurrentSkipListMap. | descendingMap
Lazily initialized descending map |
| private transient ConcurrentSkipListMap. | entrySet
Lazily initialized entry set |
| private static final int | |
| private static final int | |
| private transient ConcurrentSkipListMap. | head
Lazily initialized topmost index of the skiplist. |
| private static final VarHandle | |
| private transient ConcurrentSkipListMap. | keySet
Hides java. |
| private static final int | |
| private static final VarHandle | |
| private static final VarHandle | |
| private static final long | |
| private static final VarHandle | |
| private transient ConcurrentSkipListMap. | values
Hides java. |
| Access | Constructor and Description |
|---|---|
| public | ConcurrentSkipListMap()
Constructs a new, empty map, sorted according to the natural ordering of the keys. |
| public | ConcurrentSkipListMap(Comparator<? super K>
the comparator that will be used to order this map.
If comparator)null, the natural
ordering of the keys will be used.Constructs a new, empty map, sorted according to the specified comparator. |
| public | ConcurrentSkipListMap(Map<? extends K, ? extends V>
the map whose mappings are to be placed in this map m)Constructs a new map containing the same mappings as the given map, sorted according to the natural ordering of the keys. |
| public | ConcurrentSkipListMap(SortedMap<K, ? extends V>
the sorted map whose mappings are to be placed in this
map, and whose comparator is to be used to sort this map m)Constructs a new map containing the same mappings and using the same ordering as the specified sorted map. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| pack-priv static <K, V> boolean | addIndices(ConcurrentSkipListMap.
starting index for current level q,levels to skip before inserting skips, ConcurrentSkipListMap.index for this insertion x,comparator cmp)Add indices after an insertion. |
| pack-priv final ConcurrentSkipListMap. | |
| private void | buildFromSorted(SortedMap<K, ? extends V> map)
Streamlined bulk insertion to initialize from elements of given sorted map. |
| public Map. | ceilingEntry(K key)
Implements java. Returns a key-value mapping associated with the least key
greater than or equal to the given key, or |
| public K | ceilingKey(K key)
Implements java. Returns the least key greater than or equal to the given key,
or |
| public void | clear()
Overrides java. Implements java. Removes all of the mappings from this map. |
| public ConcurrentSkipListMap | Returns: a shallow copy of this mapOverrides java. Returns a shallow copy of this |
| public Comparator | comparator()
Implements java. Returns the comparator used to order the keys in this map, or
|
| public V | Returns: the new value associated with the specified key, or null if nonekey with which the specified value is to be associated key, BiFunction<? super K, ? super V, ? extends V> the function to compute a value remappingFunction)Overrides default java. Attempts to compute a mapping for the specified key and its
current mapped value (or |
| public V | Returns: the current (existing or computed) value associated with the specified key, or null if the computed value is nullkey with which the specified value is to be associated key, Function<? super K, ? extends V> the function to compute a value mappingFunction)Overrides default java. If the specified key is not already associated with a value,
attempts to compute its value using the given mapping function
and enters it into this map unless |
| public V | Returns: the new value associated with the specified key, or null if nonekey with which a value may be associated key, BiFunction<? super K, ? super V, ? extends V> the function to compute a value remappingFunction)Overrides default java. If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value. |
| public boolean | Returns: true if this map contains a mapping for the specified keykey whose presence in this map is to be tested key)Overrides java. Implements java. Returns |
| public boolean | Returns: true if a mapping to value exists;
false otherwisevalue whose presence in this map is to be tested value)Overrides java. Implements java. Returns |
| pack-priv static int | |
| public NavigableSet | descendingKeySet()
Implements java. Returns a reverse order |
| public ConcurrentNavigableMap | descendingMap()
Implements java. Returns a reverse order view of the mappings contained in this map. |
| private V | |
| private V | Returns: the old value, or null if newly insertedthe key key, V the value that must be associated with key value, boolean if should not insert if already present onlyIfAbsent)Main insertion method. |
| pack-priv final V | |
| private AbstractMap. | Returns: null if empty, else snapshot of first entryRemoves first entry; returns its snapshot. |
| private Map. | Returns: null if empty, else snapshot of last entryRemoves last entry; returns its snapshot. |
| public Set | Returns: a set view of the mappings contained in this map, sorted in ascending key orderImplements abstract java. Implements java. Returns a |
| pack-priv final ConcurrentSkipListMap. | |
| public boolean | Returns: true if the specified object is equal to this mapobject to be compared for equality with this map o)Overrides java. Implements java. Compares the specified object with this map for equality. |
| pack-priv final ConcurrentSkipListMap. | Returns: first node or null if emptyGets first valid node, unlinking deleted nodes if encountered. |
| pack-priv final AbstractMap. | |
| pack-priv final ConcurrentSkipListMap. | |
| pack-priv final AbstractMap. | |
| pack-priv final ConcurrentSkipListMap. | Returns: nearest node fitting relation, or null if no suchthe key key, int the relation -- OR'ed combination of EQ, LT, GT rel, Comparator<? super K> cmp)Utility for ceiling, floor, lower, higher methods. |
| pack-priv final AbstractMap. | Returns: Entry fitting relation, or null if no suchthe key key, int the relation -- OR'ed combination of EQ, LT, GT rel, Comparator<? super K> cmp)Variant of findNear returning SimpleImmutableEntry |
| private ConcurrentSkipListMap. | |
| private ConcurrentSkipListMap. | Returns: a predecessor node of key, or null if uninitialized or null keyif nonnull the key key, Comparator<? super K> cmp)Returns an index node with key strictly less than given key. |
| public Map. | firstEntry()
Implements java. Returns a key-value mapping associated with the least
key in this map, or |
| public K | firstKey()
Implements java. Returns the first (lowest) key currently in this map. |
| public Map. | floorEntry(K
the key key)Implements java. Returns a key-value mapping associated with the greatest key
less than or equal to the given key, or |
| public K | floorKey(K
the key key)Implements java. Returns the greatest key less than or equal to the given key,
or |
| public void | forEach(BiConsumer<? super K, ? super V> action)
Overrides default java. Performs the given action for each entry in this map until all entries have been processed or the action throws an exception. |
| public V | get(Object key)
Overrides java. Implements java. Returns the value to which the specified key is mapped,
or |
| pack-priv final long | |
| public V | Returns: the mapping for the key, if present; else the defaultValuethe key key, V the value to return if this map contains
no mapping for the given key defaultValue)Overrides default java. Returns the value to which the specified key is mapped, or the given defaultValue if this map contains no mapping for the key. |
| public ConcurrentNavigableMap | headMap(K toKey, boolean inclusive)
Implements java. Returns a view of the portion of this map whose keys are less than (or
equal to, if |
| public ConcurrentNavigableMap | headMap(K toKey)
Implements java. Returns a view of the portion of this map whose keys are
strictly less than |
| public Map. | higherEntry(K
the key key)Implements java. Returns a key-value mapping associated with the least key
strictly greater than the given key, or |
| public K | higherKey(K
the key key)Implements java. Returns the least key strictly greater than the given key, or
|
| public boolean | isEmpty()
Overrides java. Implements java. Returns |
| public NavigableSet | Returns: a navigable set view of the keys in this mapOverrides java. Implements java. Returns a |
| pack-priv final ConcurrentSkipListMap. | |
| public Map. | lastEntry()
Implements java. Returns a key-value mapping associated with the greatest
key in this map, or |
| public K | lastKey()
Implements java. Returns the last (highest) key currently in this map. |
| public Map. | lowerEntry(K key)
Implements java. Returns a key-value mapping associated with the greatest key
strictly less than the given key, or |
| public K | lowerKey(K key)
Implements java. Returns the greatest key strictly less than the given key, or
|
| public V | Returns: the new value associated with the specified key, or null if nonekey with which the specified value is to be associated key, V the value to use if absent value, BiFunction<? super V, ? super V, ? extends V> the function to recompute a value if present remappingFunction)Overrides default java. If the specified key is not already associated with a value, associates it with the given value. |
| public NavigableSet | navigableKeySet()
Implements java. Returns a |
| public Map. | pollFirstEntry()
Implements java. Removes and returns a key-value mapping associated with
the least key in this map, or |
| public Map. | pollLastEntry()
Implements java. Removes and returns a key-value mapping associated with
the greatest key in this map, or |
| public V | Returns: the previous value associated with the specified key, ornull if there was no mapping for the keykey with which the specified value is to be associated key, V value to be associated with the specified key value)Overrides java. Implements java. Associates the specified value with the specified key in this map. |
| public V | putFirst(K k, V v)
Overrides default java. Throws |
| public V | Returns: the previous value associated with the specified key, ornull if there was no mapping for the keyOverrides default java. Implements java. If the specified key is not already associated with a value, associates it with the given value. |
| public V | putLast(K k, V v)
Overrides default java. Throws |
| private void | readObject(final ObjectInputStream
the stream s)Reconstitutes this map from a stream (that is, deserializes it). |
| public V | Returns: the previous value associated with the specified key, ornull if there was no mapping for the keykey for which mapping should be removed key)Overrides java. Implements java. Removes the mapping for the specified key from this map if present. |
| public boolean | remove(Object key, Object value)
Overrides default java. Implements java. Removes the entry for a key only if currently mapped to a given value. |
| pack-priv boolean | |
| pack-priv boolean | |
| public boolean | replace(K key, V oldValue, V newValue)
Overrides default java. Implements java. Replaces the entry for a key only if currently mapped to a given value. |
| public V | Returns: the previous value associated with the specified key, ornull if there was no mapping for the keyOverrides default java. Implements java. Replaces the entry for a key only if currently mapped to some value. |
| public void | replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
Overrides default java. Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception (optional operation). |
| public int | size()
Overrides java. Implements java. Returns the number of key-value mappings in this map. |
| public ConcurrentNavigableMap | subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Implements java. Returns a view of the portion of this map whose keys range from
|
| public ConcurrentNavigableMap | subMap(K fromKey, K toKey)
Implements java. Returns a view of the portion of this map whose keys range from
|
| public ConcurrentNavigableMap | tailMap(K fromKey, boolean inclusive)
Implements java. Returns a view of the portion of this map whose keys are greater than (or
equal to, if |
| public ConcurrentNavigableMap | tailMap(K fromKey)
Implements java. Returns a view of the portion of this map whose keys are
greater than or equal to |
| pack-priv static final <E> List | |
| private void | |
| pack-priv static <K, V> void | unlinkNode(ConcurrentSkipListMap.
if nonnull, predecessor b,if nonnull, node known to be deleted nTries to unlink deleted node n from predecessor b (if both exist), by first splicing in a marker if not already present. |
| public Collection | values()
Overrides java. Implements java. Returns a |
| pack-priv final ConcurrentSkipListMap. | |
| private void |