1 *java.util.concurrent.ConcurrentSkipListMap* *ConcurrentSkipListMap* A scalable
3 public class ConcurrentSkipListMap<K,V>
4 extends |java.util.AbstractMap|
5 implements |java.util.concurrent.ConcurrentNavigableMap|
9 |java.util.concurrent.ConcurrentSkipListMap_Description|
10 |java.util.concurrent.ConcurrentSkipListMap_Fields|
11 |java.util.concurrent.ConcurrentSkipListMap_Constructors|
12 |java.util.concurrent.ConcurrentSkipListMap_Methods|
14 ================================================================================
16 *java.util.concurrent.ConcurrentSkipListMap_Constructors*
17 |java.util.concurrent.ConcurrentSkipListMap()|Constructs a new, empty map, sort
18 |java.util.concurrent.ConcurrentSkipListMap(Comparator<?superK>)|Constructs a n
19 |java.util.concurrent.ConcurrentSkipListMap(Map<?extendsK,?extendsV>)|Construct
20 |java.util.concurrent.ConcurrentSkipListMap(SortedMap<K,?extendsV>)|Constructs
22 *java.util.concurrent.ConcurrentSkipListMap_Methods*
23 |java.util.concurrent.ConcurrentSkipListMap.ceilingEntry(K)|Returns a key-value
24 |java.util.concurrent.ConcurrentSkipListMap.ceilingKey(K)|
25 |java.util.concurrent.ConcurrentSkipListMap.clear()|Removes all of the mappings
26 |java.util.concurrent.ConcurrentSkipListMap.clone()|Returns a shallow copy of t
27 |java.util.concurrent.ConcurrentSkipListMap.comparator()|
28 |java.util.concurrent.ConcurrentSkipListMap.containsKey(Object)|Returns true if
29 |java.util.concurrent.ConcurrentSkipListMap.containsValue(Object)|Returns true
30 |java.util.concurrent.ConcurrentSkipListMap.descendingKeySet()|
31 |java.util.concurrent.ConcurrentSkipListMap.descendingMap()|
32 |java.util.concurrent.ConcurrentSkipListMap.entrySet()|Returns aSetview of the
33 |java.util.concurrent.ConcurrentSkipListMap.equals(Object)|Compares the specifi
34 |java.util.concurrent.ConcurrentSkipListMap.firstEntry()|Returns a key-value ma
35 |java.util.concurrent.ConcurrentSkipListMap.firstKey()|
36 |java.util.concurrent.ConcurrentSkipListMap.floorEntry(K)|Returns a key-value m
37 |java.util.concurrent.ConcurrentSkipListMap.floorKey(K)|
38 |java.util.concurrent.ConcurrentSkipListMap.get(Object)|Returns the value to wh
39 |java.util.concurrent.ConcurrentSkipListMap.headMap(K)|
40 |java.util.concurrent.ConcurrentSkipListMap.headMap(K,boolean)|
41 |java.util.concurrent.ConcurrentSkipListMap.higherEntry(K)|Returns a key-value
42 |java.util.concurrent.ConcurrentSkipListMap.higherKey(K)|
43 |java.util.concurrent.ConcurrentSkipListMap.isEmpty()|Returns true if this map
44 |java.util.concurrent.ConcurrentSkipListMap.keySet()|Returns aNavigableSetview
45 |java.util.concurrent.ConcurrentSkipListMap.lastEntry()|Returns a key-value map
46 |java.util.concurrent.ConcurrentSkipListMap.lastKey()|
47 |java.util.concurrent.ConcurrentSkipListMap.lowerEntry(K)|Returns a key-value m
48 |java.util.concurrent.ConcurrentSkipListMap.lowerKey(K)|
49 |java.util.concurrent.ConcurrentSkipListMap.navigableKeySet()|
50 |java.util.concurrent.ConcurrentSkipListMap.pollFirstEntry()|Removes and return
51 |java.util.concurrent.ConcurrentSkipListMap.pollLastEntry()|Removes and returns
52 |java.util.concurrent.ConcurrentSkipListMap.put(K,V)|Associates the specified v
53 |java.util.concurrent.ConcurrentSkipListMap.putIfAbsent(K,V)|
54 |java.util.concurrent.ConcurrentSkipListMap.remove(Object)|Removes the mapping
55 |java.util.concurrent.ConcurrentSkipListMap.remove(Object,Object)|
56 |java.util.concurrent.ConcurrentSkipListMap.replace(K,V)|
57 |java.util.concurrent.ConcurrentSkipListMap.replace(K,V,V)|
58 |java.util.concurrent.ConcurrentSkipListMap.size()|Returns the number of key-va
59 |java.util.concurrent.ConcurrentSkipListMap.subMap(K,boolean,K,boolean)|
60 |java.util.concurrent.ConcurrentSkipListMap.subMap(K,K)|
61 |java.util.concurrent.ConcurrentSkipListMap.tailMap(K)|
62 |java.util.concurrent.ConcurrentSkipListMap.tailMap(K,boolean)|
63 |java.util.concurrent.ConcurrentSkipListMap.values()|Returns aCollectionview of
65 *java.util.concurrent.ConcurrentSkipListMap_Description*
67 A scalable concurrent (|java.util.concurrent.ConcurrentNavigableMap|)
68 implementation. The map is sorted according to the natural
69 ordering(|java.lang.Comparable|) of its keys, or by a (|java.util.Comparator|)
70 provided at map creation time, depending on which constructor is used.
72 This class implements a concurrent variant of SkipLists providing expected
73 average log(n) time cost for the containsKey, get, put and remove operations
74 and their variants. Insertion, removal, update, and access operations safely
75 execute concurrently by multiple threads. Iterators are weakly consistent,
76 returning elements reflecting the state of the map at some point at or since
77 the creation of the iterator. They do not throw
78 (|java.util.ConcurrentModificationException|) , and may proceed concurrently
79 with other operations. Ascending key ordered views and their iterators are
80 faster than descending ones.
82 All Map.Entry pairs returned by methods in this class and its views represent
83 snapshots of mappings at the time they were produced. They do not support the
84 Entry.setValue method. (Note however that it is possible to change mappings in
85 the associated map using put, putIfAbsent, or replace, depending on exactly
86 which effect you need.)
88 Beware that, unlike in most collections, the size method is not a constant-time
89 operation. Because of the asynchronous nature of these maps, determining the
90 current number of elements requires a traversal of the elements. Additionally,
91 the bulk operations putAll, equals, and clear are not guaranteed to be
92 performed atomically. For example, an iterator operating concurrently with a
93 putAll operation might view only some of the added elements.
95 This class and its views and iterators implement all of the optional methods of
96 the (|java.util.Map|) and (|java.util.Iterator|) interfaces. Like most other
97 concurrent collections, this class does not permit the use of null keys or
98 values because some null return values cannot be reliably distinguished from
99 the absence of elements.
101 This class is a member of the <a
102 href="/../technotes/guides/collections/index.html"> Java Collections Framework.
106 *java.util.concurrent.ConcurrentSkipListMap()*
108 public ConcurrentSkipListMap()
110 Constructs a new, empty map, sorted according to the natural
111 ordering(|java.lang.Comparable|) of the keys.
114 *java.util.concurrent.ConcurrentSkipListMap(Comparator<?superK>)*
116 public ConcurrentSkipListMap(java.util.Comparator<? super K> comparator)
118 Constructs a new, empty map, sorted according to the specified comparator.
120 comparator - the comparator that will be used to order this map. If null, the {@linkplain
121 Comparable natural ordering} of the keys will be used.
123 *java.util.concurrent.ConcurrentSkipListMap(Map<?extendsK,?extendsV>)*
125 public ConcurrentSkipListMap(java.util.Map<? extends K, ? extends V> m)
127 Constructs a new map containing the same mappings as the given map, sorted
128 according to the natural ordering(|java.lang.Comparable|) of the keys.
130 m - the map whose mappings are to be placed in this map
132 *java.util.concurrent.ConcurrentSkipListMap(SortedMap<K,?extendsV>)*
134 public ConcurrentSkipListMap(java.util.SortedMap<K, ? extends V> m)
136 Constructs a new map containing the same mappings and using the same ordering
137 as the specified sorted map.
139 m - the sorted map whose mappings are to be placed in this map, and whose
140 comparator is to be used to sort this map
142 *java.util.concurrent.ConcurrentSkipListMap.ceilingEntry(K)*
144 public |java.util.Map.Entry|<K,V> ceilingEntry(K key)
146 Returns a key-value mapping associated with the least key greater than or equal
147 to the given key, or null if there is no such entry. The returned entry does
148 not support the Entry.setValue method.
152 *java.util.concurrent.ConcurrentSkipListMap.ceilingKey(K)*
154 public |K| ceilingKey(K key)
160 *java.util.concurrent.ConcurrentSkipListMap.clear()*
164 Removes all of the mappings from this map.
168 *java.util.concurrent.ConcurrentSkipListMap.clone()*
170 public |java.util.concurrent.ConcurrentSkipListMap|<K,V> clone()
172 Returns a shallow copy of this ConcurrentSkipListMap instance. (The keys and
173 values themselves are not cloned.)
177 Returns: a shallow copy of this map
179 *java.util.concurrent.ConcurrentSkipListMap.comparator()*
181 public |java.util.Comparator|<? super K> comparator()
187 *java.util.concurrent.ConcurrentSkipListMap.containsKey(Object)*
189 public boolean containsKey(java.lang.Object key)
191 Returns true if this map contains a mapping for the specified key.
194 key - key whose presence in this map is to be tested
196 Returns: true if this map contains a mapping for the specified key
198 *java.util.concurrent.ConcurrentSkipListMap.containsValue(Object)*
200 public boolean containsValue(java.lang.Object value)
202 Returns true if this map maps one or more keys to the specified value. This
203 operation requires time linear in the map size.
206 value - value whose presence in this map is to be tested
208 Returns: true if a mapping to value exists; false otherwise
210 *java.util.concurrent.ConcurrentSkipListMap.descendingKeySet()*
212 public |java.util.NavigableSet|<K> descendingKeySet()
218 *java.util.concurrent.ConcurrentSkipListMap.descendingMap()*
220 public |java.util.concurrent.ConcurrentNavigableMap|<K,V> descendingMap()
226 *java.util.concurrent.ConcurrentSkipListMap.entrySet()*
228 public |java.util.Set|<Entry<K,V>> entrySet()
230 Returns a (|java.util.Set|) view of the mappings contained in this map. The
231 set's iterator returns the entries in ascending key order. The set is backed by
232 the map, so changes to the map are reflected in the set, and vice-versa. The
233 set supports element removal, which removes the corresponding mapping from the
234 map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear
235 operations. It does not support the add or addAll operations.
237 The view's iterator is a "weakly consistent" iterator that will never throw
238 (|java.util.ConcurrentModificationException|) , and guarantees to traverse
239 elements as they existed upon construction of the iterator, and may (but is not
240 guaranteed to) reflect any modifications subsequent to construction.
242 The Map.Entry elements returned by iterator.next() do not support the setValue
247 Returns: a set view of the mappings contained in this map, sorted in ascending key order
249 *java.util.concurrent.ConcurrentSkipListMap.equals(Object)*
251 public boolean equals(java.lang.Object o)
253 Compares the specified object with this map for equality. Returns true if the
254 given object is also a map and the two maps represent the same mappings. More
255 formally, two maps m1 and m2 represent the same mappings if
256 m1.entrySet().equals(m2.entrySet()). This operation may return misleading
257 results if either map is concurrently modified during execution of this method.
260 o - object to be compared for equality with this map
262 Returns: true if the specified object is equal to this map
264 *java.util.concurrent.ConcurrentSkipListMap.firstEntry()*
266 public |java.util.Map.Entry|<K,V> firstEntry()
268 Returns a key-value mapping associated with the least key in this map, or null
269 if the map is empty. The returned entry does not support the Entry.setValue
274 *java.util.concurrent.ConcurrentSkipListMap.firstKey()*
276 public |K| firstKey()
282 *java.util.concurrent.ConcurrentSkipListMap.floorEntry(K)*
284 public |java.util.Map.Entry|<K,V> floorEntry(K key)
286 Returns a key-value mapping associated with the greatest key less than or equal
287 to the given key, or null if there is no such key. The returned entry does not
288 support the Entry.setValue method.
293 *java.util.concurrent.ConcurrentSkipListMap.floorKey(K)*
295 public |K| floorKey(K key)
302 *java.util.concurrent.ConcurrentSkipListMap.get(Object)*
304 public |V| get(java.lang.Object key)
306 Returns the value to which the specified key is mapped, ornullif this map
307 contains no mapping for the key.
309 More formally, if this map contains a mapping from a keykto a valuevsuch
310 thatkeycompares equal tokaccording to the map's ordering, then this method
311 returnsv; otherwise it returnsnull. (There can be at most one such mapping.)
315 *java.util.concurrent.ConcurrentSkipListMap.headMap(K)*
317 public |java.util.concurrent.ConcurrentNavigableMap|<K,V> headMap(K toKey)
323 *java.util.concurrent.ConcurrentSkipListMap.headMap(K,boolean)*
325 public |java.util.concurrent.ConcurrentNavigableMap|<K,V> headMap(
333 *java.util.concurrent.ConcurrentSkipListMap.higherEntry(K)*
335 public |java.util.Map.Entry|<K,V> higherEntry(K key)
337 Returns a key-value mapping associated with the least key strictly greater than
338 the given key, or null if there is no such key. The returned entry does not
339 support the Entry.setValue method.
344 *java.util.concurrent.ConcurrentSkipListMap.higherKey(K)*
346 public |K| higherKey(K key)
353 *java.util.concurrent.ConcurrentSkipListMap.isEmpty()*
355 public boolean isEmpty()
357 Returns true if this map contains no key-value mappings.
361 Returns: true if this map contains no key-value mappings
363 *java.util.concurrent.ConcurrentSkipListMap.keySet()*
365 public |java.util.NavigableSet|<K> keySet()
367 Returns a (|java.util.NavigableSet|) view of the keys contained in this map.
368 The set's iterator returns the keys in ascending order. The set is backed by
369 the map, so changes to the map are reflected in the set, and vice-versa. The
370 set supports element removal, which removes the corresponding mapping from the
371 map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations.
372 It does not support theaddoraddAlloperations.
374 The view'siteratoris a "weakly consistent" iterator that will never throw
375 (|java.util.ConcurrentModificationException|) , and guarantees to traverse
376 elements as they existed upon construction of the iterator, and may (but is not
377 guaranteed to) reflect any modifications subsequent to construction.
379 This method is equivalent to methodnavigableKeySet.
383 Returns: a navigable set view of the keys in this map
385 *java.util.concurrent.ConcurrentSkipListMap.lastEntry()*
387 public |java.util.Map.Entry|<K,V> lastEntry()
389 Returns a key-value mapping associated with the greatest key in this map, or
390 null if the map is empty. The returned entry does not support the
391 Entry.setValue method.
395 *java.util.concurrent.ConcurrentSkipListMap.lastKey()*
403 *java.util.concurrent.ConcurrentSkipListMap.lowerEntry(K)*
405 public |java.util.Map.Entry|<K,V> lowerEntry(K key)
407 Returns a key-value mapping associated with the greatest key strictly less than
408 the given key, or null if there is no such key. The returned entry does not
409 support the Entry.setValue method.
413 *java.util.concurrent.ConcurrentSkipListMap.lowerKey(K)*
415 public |K| lowerKey(K key)
421 *java.util.concurrent.ConcurrentSkipListMap.navigableKeySet()*
423 public |java.util.NavigableSet|<K> navigableKeySet()
429 *java.util.concurrent.ConcurrentSkipListMap.pollFirstEntry()*
431 public |java.util.Map.Entry|<K,V> pollFirstEntry()
433 Removes and returns a key-value mapping associated with the least key in this
434 map, or null if the map is empty. The returned entry does not support the
435 Entry.setValue method.
439 *java.util.concurrent.ConcurrentSkipListMap.pollLastEntry()*
441 public |java.util.Map.Entry|<K,V> pollLastEntry()
443 Removes and returns a key-value mapping associated with the greatest key in
444 this map, or null if the map is empty. The returned entry does not support the
445 Entry.setValue method.
449 *java.util.concurrent.ConcurrentSkipListMap.put(K,V)*
455 Associates the specified value with the specified key in this map. If the map
456 previously contained a mapping for the key, the old value is replaced.
459 key - key with which the specified value is to be associated
460 value - value to be associated with the specified key
462 Returns: the previous value associated with the specified key, or null if there was no
465 *java.util.concurrent.ConcurrentSkipListMap.putIfAbsent(K,V)*
467 public |V| putIfAbsent(
475 Returns: the previous value associated with the specified key, or null if there was no
478 *java.util.concurrent.ConcurrentSkipListMap.remove(Object)*
480 public |V| remove(java.lang.Object key)
482 Removes the mapping for the specified key from this map if present.
485 key - key for which mapping should be removed
487 Returns: the previous value associated with the specified key, or null if there was no
490 *java.util.concurrent.ConcurrentSkipListMap.remove(Object,Object)*
492 public boolean remove(
493 java.lang.Object key,
494 java.lang.Object value)
500 *java.util.concurrent.ConcurrentSkipListMap.replace(K,V)*
510 Returns: the previous value associated with the specified key, or null if there was no
513 *java.util.concurrent.ConcurrentSkipListMap.replace(K,V,V)*
515 public boolean replace(
524 *java.util.concurrent.ConcurrentSkipListMap.size()*
528 Returns the number of key-value mappings in this map. If this map contains more
529 than Integer.MAX_VALUE elements, it returns Integer.MAX_VALUE.
531 Beware that, unlike in most collections, this method is NOT a constant-time
532 operation. Because of the asynchronous nature of these maps, determining the
533 current number of elements requires traversing them all to count them.
534 Additionally, it is possible for the size to change during execution of this
535 method, in which case the returned result will be inaccurate. Thus, this method
536 is typically not very useful in concurrent applications.
540 Returns: the number of elements in this map
542 *java.util.concurrent.ConcurrentSkipListMap.subMap(K,boolean,K,boolean)*
544 public |java.util.concurrent.ConcurrentNavigableMap|<K,V> subMap(
546 boolean fromInclusive,
554 *java.util.concurrent.ConcurrentSkipListMap.subMap(K,K)*
556 public |java.util.concurrent.ConcurrentNavigableMap|<K,V> subMap(
564 *java.util.concurrent.ConcurrentSkipListMap.tailMap(K)*
566 public |java.util.concurrent.ConcurrentNavigableMap|<K,V> tailMap(K fromKey)
572 *java.util.concurrent.ConcurrentSkipListMap.tailMap(K,boolean)*
574 public |java.util.concurrent.ConcurrentNavigableMap|<K,V> tailMap(
582 *java.util.concurrent.ConcurrentSkipListMap.values()*
584 public |java.util.Collection|<V> values()
586 Returns a (|java.util.Collection|) view of the values contained in this map.
587 The collection's iterator returns the values in ascending order of the
588 corresponding keys. The collection is backed by the map, so changes to the map
589 are reflected in the collection, and vice-versa. The collection supports
590 element removal, which removes the corresponding mapping from the map, via the
591 Iterator.remove, Collection.remove, removeAll, retainAll and clear operations.
592 It does not support the add or addAll operations.
594 The view's iterator is a "weakly consistent" iterator that will never throw
595 (|java.util.ConcurrentModificationException|) , and guarantees to traverse
596 elements as they existed upon construction of the iterator, and may (but is not
597 guaranteed to) reflect any modifications subsequent to construction.