85 |
|
* {@code hashCode()} is a sure way to slow down performance of any |
86 |
|
* hash table. |
87 |
|
* |
88 |
+ |
* <p> A {@link Set} projection of a ConcurrentHashMap may be created |
89 |
+ |
* (using {@link #newKeySet()} or {@link #newKeySet(int)}), or viewed |
90 |
+ |
* (using {@link #keySet(Object)} when only keys are of interest, and the |
91 |
+ |
* mapped values are (perhaps transiently) not used or all take the |
92 |
+ |
* same mapping value. |
93 |
+ |
* |
94 |
+ |
* <p> A ConcurrentHashMap can be used as scalable frequency map (a |
95 |
+ |
* form of histogram or multiset) by using {@link LongAdder} values |
96 |
+ |
* and initializing via {@link #computeIfAbsent}. For example, to add |
97 |
+ |
* a count to a {@code ConcurrentHashMap<String,LongAdder> freqs}, you |
98 |
+ |
* can use {@code freqs.computeIfAbsent(k -> new |
99 |
+ |
* LongAdder()).increment();} |
100 |
+ |
* |
101 |
|
* <p>This class and its views and iterators implement all of the |
102 |
|
* <em>optional</em> methods of the {@link Map} and {@link Iterator} |
103 |
|
* interfaces. |
105 |
|
* <p> Like {@link Hashtable} but unlike {@link HashMap}, this class |
106 |
|
* does <em>not</em> allow {@code null} to be used as a key or value. |
107 |
|
* |
108 |
+ |
* <p>ConcurrentHashMaps support parallel operations using the {@link |
109 |
+ |
* ForkJoinPool#commonPool}. (Task that may be used in other contexts |
110 |
+ |
* are available in class {@link ForkJoinTasks}). These operations are |
111 |
+ |
* designed to be safely, and often sensibly, applied even with maps |
112 |
+ |
* that are being concurrently updated by other threads; for example, |
113 |
+ |
* when computing a snapshot summary of the values in a shared |
114 |
+ |
* registry. There are three kinds of operation, each with four |
115 |
+ |
* forms, accepting functions with Keys, Values, Entries, and (Key, |
116 |
+ |
* Value) arguments and/or return values. Because the elements of a |
117 |
+ |
* ConcurrentHashMap are not ordered in any particular way, and may be |
118 |
+ |
* processed in different orders in different parallel executions, the |
119 |
+ |
* correctness of supplied functions should not depend on any |
120 |
+ |
* ordering, or on any other objects or values that may transiently |
121 |
+ |
* change while computation is in progress; and except for forEach |
122 |
+ |
* actions, should ideally be side-effect-free. |
123 |
+ |
* |
124 |
+ |
* <ul> |
125 |
+ |
* <li> forEach: Perform a given action on each element. |
126 |
+ |
* A variant form applies a given transformation on each element |
127 |
+ |
* before performing the action.</li> |
128 |
+ |
* |
129 |
+ |
* <li> search: Return the first available non-null result of |
130 |
+ |
* applying a given function on each element; skipping further |
131 |
+ |
* search when a result is found.</li> |
132 |
+ |
* |
133 |
+ |
* <li> reduce: Accumulate each element. The supplied reduction |
134 |
+ |
* function cannot rely on ordering (more formally, it should be |
135 |
+ |
* both associative and commutative). There are five variants: |
136 |
+ |
* |
137 |
+ |
* <ul> |
138 |
+ |
* |
139 |
+ |
* <li> Plain reductions. (There is not a form of this method for |
140 |
+ |
* (key, value) function arguments since there is no corresponding |
141 |
+ |
* return type.)</li> |
142 |
+ |
* |
143 |
+ |
* <li> Mapped reductions that accumulate the results of a given |
144 |
+ |
* function applied to each element.</li> |
145 |
+ |
* |
146 |
+ |
* <li> Reductions to scalar doubles, longs, and ints, using a |
147 |
+ |
* given basis value.</li> |
148 |
+ |
* |
149 |
+ |
* </li> |
150 |
+ |
* </ul> |
151 |
+ |
* </ul> |
152 |
+ |
* |
153 |
+ |
* <p>The concurrency properties of bulk operations follow |
154 |
+ |
* from those of ConcurrentHashMap: Any non-null result returned |
155 |
+ |
* from {@code get(key)} and related access methods bears a |
156 |
+ |
* happens-before relation with the associated insertion or |
157 |
+ |
* update. The result of any bulk operation reflects the |
158 |
+ |
* composition of these per-element relations (but is not |
159 |
+ |
* necessarily atomic with respect to the map as a whole unless it |
160 |
+ |
* is somehow known to be quiescent). Conversely, because keys |
161 |
+ |
* and values in the map are never null, null serves as a reliable |
162 |
+ |
* atomic indicator of the current lack of any result. To |
163 |
+ |
* maintain this property, null serves as an implicit basis for |
164 |
+ |
* all non-scalar reduction operations. For the double, long, and |
165 |
+ |
* int versions, the basis should be one that, when combined with |
166 |
+ |
* any other value, returns that other value (more formally, it |
167 |
+ |
* should be the identity element for the reduction). Most common |
168 |
+ |
* reductions have these properties; for example, computing a sum |
169 |
+ |
* with basis 0 or a minimum with basis MAX_VALUE. |
170 |
+ |
* |
171 |
+ |
* <p>Search and transformation functions provided as arguments |
172 |
+ |
* should similarly return null to indicate the lack of any result |
173 |
+ |
* (in which case it is not used). In the case of mapped |
174 |
+ |
* reductions, this also enables transformations to serve as |
175 |
+ |
* filters, returning null (or, in the case of primitive |
176 |
+ |
* specializations, the identity basis) if the element should not |
177 |
+ |
* be combined. You can create compound transformations and |
178 |
+ |
* filterings by composing them yourself under this "null means |
179 |
+ |
* there is nothing there now" rule before using them in search or |
180 |
+ |
* reduce operations. |
181 |
+ |
* |
182 |
+ |
* <p>Methods accepting and/or returning Entry arguments maintain |
183 |
+ |
* key-value associations. They may be useful for example when |
184 |
+ |
* finding the key for the greatest value. Note that "plain" Entry |
185 |
+ |
* arguments can be supplied using {@code new |
186 |
+ |
* AbstractMap.SimpleEntry(k,v)}. |
187 |
+ |
* |
188 |
+ |
* <p> Bulk operations may complete abruptly, throwing an |
189 |
+ |
* exception encountered in the application of a supplied |
190 |
+ |
* function. Bear in mind when handling such exceptions that other |
191 |
+ |
* concurrently executing functions could also have thrown |
192 |
+ |
* exceptions, or would have done so if the first exception had |
193 |
+ |
* not occurred. |
194 |
+ |
* |
195 |
+ |
* <p>Parallel speedups for bulk operations compared to sequential |
196 |
+ |
* processing are common but not guaranteed. Operations involving |
197 |
+ |
* brief functions on small maps may execute more slowly than |
198 |
+ |
* sequential loops if the underlying work to parallelize the |
199 |
+ |
* computation is more expensive than the computation |
200 |
+ |
* itself. Similarly, parallelization may not lead to much actual |
201 |
+ |
* parallelism if all processors are busy performing unrelated tasks. |
202 |
+ |
* |
203 |
+ |
* <p> All arguments to all task methods must be non-null. |
204 |
+ |
* |
205 |
+ |
* <p><em>jsr166e note: During transition, this class |
206 |
+ |
* uses nested functional interfaces with different names but the |
207 |
+ |
* same forms as those expected for JDK8.<em> |
208 |
+ |
* |
209 |
|
* <p>This class is a member of the |
210 |
|
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
211 |
|
* Java Collections Framework</a>. |
212 |
|
* |
99 |
– |
* <p><em> During transition to JDK8, this |
100 |
– |
* class declares and uses nested functional interfaces with different |
101 |
– |
* names but the same forms as those expected for JDK8.<em> |
102 |
– |
* |
213 |
|
* @since 1.5 |
214 |
|
* @author Doug Lea |
215 |
|
* @param <K> the type of keys maintained by this map |
288 |
|
Spliterator<T> split(); |
289 |
|
} |
290 |
|
|
291 |
+ |
/** |
292 |
+ |
* A view of a ConcurrentHashMap as a {@link Set} of keys, in |
293 |
+ |
* which additions may optionally be enabled by mapping to a |
294 |
+ |
* common value. This class cannot be directly instantiated. See |
295 |
+ |
* {@link #keySet}, {@link #keySet(Object)}, {@link #newKeySet()}, |
296 |
+ |
* {@link #newKeySet(int)}. |
297 |
+ |
* |
298 |
+ |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
299 |
+ |
* that will never throw {@link ConcurrentModificationException}, |
300 |
+ |
* and guarantees to traverse elements as they existed upon |
301 |
+ |
* construction of the iterator, and may (but is not guaranteed to) |
302 |
+ |
* reflect any modifications subsequent to construction. |
303 |
+ |
*/ |
304 |
+ |
public static class KeySetView<K,V> extends CHMView<K,V> implements Set<K>, java.io.Serializable { |
305 |
+ |
private static final long serialVersionUID = 7249069246763182397L; |
306 |
+ |
private final V value; |
307 |
+ |
KeySetView(ConcurrentHashMap<K, V> map, V value) { // non-public |
308 |
+ |
super(map); |
309 |
+ |
this.value = value; |
310 |
+ |
} |
311 |
+ |
|
312 |
+ |
/** |
313 |
+ |
* Returns the map backing this view. |
314 |
+ |
* |
315 |
+ |
* @return the map backing this view |
316 |
+ |
*/ |
317 |
+ |
public ConcurrentHashMap<K,V> getMap() { return map; } |
318 |
+ |
|
319 |
+ |
/** |
320 |
+ |
* Returns the default mapped value for additions, |
321 |
+ |
* or {@code null} if additions are not supported. |
322 |
+ |
* |
323 |
+ |
* @return the default mapped value for additions, or {@code null} |
324 |
+ |
* if not supported. |
325 |
+ |
*/ |
326 |
+ |
public V getMappedValue() { return value; } |
327 |
+ |
|
328 |
+ |
// implement Set API |
329 |
+ |
|
330 |
+ |
public boolean contains(Object o) { return map.containsKey(o); } |
331 |
+ |
public boolean remove(Object o) { return map.remove(o) != null; } |
332 |
+ |
public Iterator<K> iterator() { return new KeyIterator<K,V>(map); } |
333 |
+ |
public boolean add(K e) { |
334 |
+ |
V v; |
335 |
+ |
if ((v = value) == null) |
336 |
+ |
throw new UnsupportedOperationException(); |
337 |
+ |
if (e == null) |
338 |
+ |
throw new NullPointerException(); |
339 |
+ |
return map.internalPutIfAbsent(e, v) == null; |
340 |
+ |
} |
341 |
+ |
public boolean addAll(Collection<? extends K> c) { |
342 |
+ |
boolean added = false; |
343 |
+ |
V v; |
344 |
+ |
if ((v = value) == null) |
345 |
+ |
throw new UnsupportedOperationException(); |
346 |
+ |
for (K e : c) { |
347 |
+ |
if (e == null) |
348 |
+ |
throw new NullPointerException(); |
349 |
+ |
if (map.internalPutIfAbsent(e, v) == null) |
350 |
+ |
added = true; |
351 |
+ |
} |
352 |
+ |
return added; |
353 |
+ |
} |
354 |
+ |
public boolean equals(Object o) { |
355 |
+ |
Set<?> c; |
356 |
+ |
return ((o instanceof Set) && |
357 |
+ |
((c = (Set<?>)o) == this || |
358 |
+ |
(containsAll(c) && c.containsAll(this)))); |
359 |
+ |
} |
360 |
+ |
} |
361 |
+ |
|
362 |
|
/* |
363 |
|
* Overview: |
364 |
|
* |
641 |
|
private transient volatile int sizeCtl; |
642 |
|
|
643 |
|
// views |
644 |
< |
private transient KeySet<K,V> keySet; |
644 |
> |
private transient KeySetView<K,V> keySet; |
645 |
|
private transient Values<K,V> values; |
646 |
|
private transient EntrySet<K,V> entrySet; |
647 |
|
|
2423 |
|
* change (including to null, indicating deletion), field nextVal |
2424 |
|
* might not be accurate at point of use, but still maintains the |
2425 |
|
* weak consistency property of holding a value that was once |
2426 |
< |
* valid. |
2426 |
> |
* valid. To support iterator.remove, the nextKey field is not |
2427 |
> |
* updated (nulled out) when the iterator cannot advance. |
2428 |
|
* |
2429 |
|
* Internal traversals directly access these fields, as in: |
2430 |
|
* {@code while (it.advance() != null) { process(it.nextKey); }} |
2461 |
|
@SuppressWarnings("serial") static class Traverser<K,V,R> extends ForkJoinTask<R> { |
2462 |
|
final ConcurrentHashMap<K, V> map; |
2463 |
|
Node next; // the next entry to use |
2282 |
– |
Node last; // the last entry used |
2464 |
|
Object nextKey; // cached key field of next |
2465 |
|
Object nextVal; // cached val field of next |
2466 |
|
Node[] tab; // current table; updated if resized |
2493 |
|
* See above for explanation. |
2494 |
|
*/ |
2495 |
|
final Object advance() { |
2496 |
< |
Node e = last = next; |
2496 |
> |
Node e = next; |
2497 |
|
Object ev = null; |
2498 |
|
outer: do { |
2499 |
|
if (e != null) // advance past used/skipped node |
2527 |
|
} |
2528 |
|
|
2529 |
|
public final void remove() { |
2530 |
< |
if (nextVal == null && last == null) |
2531 |
< |
advance(); |
2351 |
< |
Node e = last; |
2352 |
< |
if (e == null) |
2530 |
> |
Object k = nextKey; |
2531 |
> |
if (k == null && (advance() == null || (k = nextKey) == null)) |
2532 |
|
throw new IllegalStateException(); |
2533 |
< |
last = null; |
2355 |
< |
map.remove(e.key); |
2533 |
> |
map.internalReplace(k, null, null); |
2534 |
|
} |
2535 |
|
|
2536 |
|
public final boolean hasNext() { |
2634 |
|
} |
2635 |
|
|
2636 |
|
/** |
2637 |
+ |
* Creates a new {@link Set} backed by a ConcurrentHashMap |
2638 |
+ |
* from the given type to {@code Boolean.TRUE}. |
2639 |
+ |
* |
2640 |
+ |
* @return the new set |
2641 |
+ |
*/ |
2642 |
+ |
public static <K> KeySetView<K,Boolean> newKeySet() { |
2643 |
+ |
return new KeySetView<K,Boolean>(new ConcurrentHashMap<K,Boolean>(), |
2644 |
+ |
Boolean.TRUE); |
2645 |
+ |
} |
2646 |
+ |
|
2647 |
+ |
/** |
2648 |
+ |
* Creates a new {@link Set} backed by a ConcurrentHashMap |
2649 |
+ |
* from the given type to {@code Boolean.TRUE}. |
2650 |
+ |
* |
2651 |
+ |
* @param initialCapacity The implementation performs internal |
2652 |
+ |
* sizing to accommodate this many elements. |
2653 |
+ |
* @throws IllegalArgumentException if the initial capacity of |
2654 |
+ |
* elements is negative |
2655 |
+ |
* @return the new set |
2656 |
+ |
*/ |
2657 |
+ |
public static <K> KeySetView<K,Boolean> newKeySet(int initialCapacity) { |
2658 |
+ |
return new KeySetView<K,Boolean>(new ConcurrentHashMap<K,Boolean>(initialCapacity), |
2659 |
+ |
Boolean.TRUE); |
2660 |
+ |
} |
2661 |
+ |
|
2662 |
+ |
/** |
2663 |
|
* {@inheritDoc} |
2664 |
|
*/ |
2665 |
|
public boolean isEmpty() { |
3051 |
|
/** |
3052 |
|
* Returns a {@link Set} view of the keys contained in this map. |
3053 |
|
* The set is backed by the map, so changes to the map are |
3054 |
< |
* reflected in the set, and vice-versa. The set supports element |
2851 |
< |
* removal, which removes the corresponding mapping from this map, |
2852 |
< |
* via the {@code Iterator.remove}, {@code Set.remove}, |
2853 |
< |
* {@code removeAll}, {@code retainAll}, and {@code clear} |
2854 |
< |
* operations. It does not support the {@code add} or |
2855 |
< |
* {@code addAll} operations. |
3054 |
> |
* reflected in the set, and vice-versa. |
3055 |
|
* |
3056 |
< |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
3057 |
< |
* that will never throw {@link ConcurrentModificationException}, |
3058 |
< |
* and guarantees to traverse elements as they existed upon |
3059 |
< |
* construction of the iterator, and may (but is not guaranteed to) |
3060 |
< |
* reflect any modifications subsequent to construction. |
3056 |
> |
* @return the set view |
3057 |
> |
*/ |
3058 |
> |
public KeySetView<K,V> keySet() { |
3059 |
> |
KeySetView<K,V> ks = keySet; |
3060 |
> |
return (ks != null) ? ks : (keySet = new KeySetView<K,V>(this, null)); |
3061 |
> |
} |
3062 |
> |
|
3063 |
> |
/** |
3064 |
> |
* Returns a {@link Set} view of the keys in this map, using the |
3065 |
> |
* given common mapped value for any additions (i.e., {@link |
3066 |
> |
* Collection#add} and {@link Collection#addAll}). This is of |
3067 |
> |
* course only appropriate if it is acceptable to use the same |
3068 |
> |
* value for all additions from this view. |
3069 |
> |
* |
3070 |
> |
* @param mappedValue the mapped value to use for any |
3071 |
> |
* additions. |
3072 |
> |
* @return the set view |
3073 |
> |
* @throws NullPointerException if the mappedValue is null |
3074 |
|
*/ |
3075 |
< |
public Set<K> keySet() { |
3076 |
< |
KeySet<K,V> ks = keySet; |
3077 |
< |
return (ks != null) ? ks : (keySet = new KeySet<K,V>(this)); |
3075 |
> |
public KeySetView<K,V> keySet(V mappedValue) { |
3076 |
> |
if (mappedValue == null) |
3077 |
> |
throw new NullPointerException(); |
3078 |
> |
return new KeySetView<K,V>(this, mappedValue); |
3079 |
|
} |
3080 |
|
|
3081 |
|
/** |
3257 |
|
super(it); |
3258 |
|
} |
3259 |
|
public KeyIterator<K,V> split() { |
3260 |
< |
if (last != null || (next != null && nextVal == null)) |
3260 |
> |
if (nextKey != null) |
3261 |
|
throw new IllegalStateException(); |
3262 |
|
return new KeyIterator<K,V>(this); |
3263 |
|
} |
3279 |
|
super(it); |
3280 |
|
} |
3281 |
|
public ValueIterator<K,V> split() { |
3282 |
< |
if (last != null || (next != null && nextVal == null)) |
3282 |
> |
if (nextKey != null) |
3283 |
|
throw new IllegalStateException(); |
3284 |
|
return new ValueIterator<K,V>(this); |
3285 |
|
} |
3302 |
|
super(it); |
3303 |
|
} |
3304 |
|
public EntryIterator<K,V> split() { |
3305 |
< |
if (last != null || (next != null && nextVal == null)) |
3305 |
> |
if (nextKey != null) |
3306 |
|
throw new IllegalStateException(); |
3307 |
|
return new EntryIterator<K,V>(this); |
3308 |
|
} |
3490 |
|
|
3491 |
|
} |
3492 |
|
|
3280 |
– |
static final class KeySet<K,V> extends CHMView<K,V> implements Set<K> { |
3281 |
– |
KeySet(ConcurrentHashMap<K, V> map) { |
3282 |
– |
super(map); |
3283 |
– |
} |
3284 |
– |
public final boolean contains(Object o) { return map.containsKey(o); } |
3285 |
– |
public final boolean remove(Object o) { return map.remove(o) != null; } |
3286 |
– |
public final Iterator<K> iterator() { |
3287 |
– |
return new KeyIterator<K,V>(map); |
3288 |
– |
} |
3289 |
– |
public final boolean add(K e) { |
3290 |
– |
throw new UnsupportedOperationException(); |
3291 |
– |
} |
3292 |
– |
public final boolean addAll(Collection<? extends K> c) { |
3293 |
– |
throw new UnsupportedOperationException(); |
3294 |
– |
} |
3295 |
– |
public boolean equals(Object o) { |
3296 |
– |
Set<?> c; |
3297 |
– |
return ((o instanceof Set) && |
3298 |
– |
((c = (Set<?>)o) == this || |
3299 |
– |
(containsAll(c) && c.containsAll(this)))); |
3300 |
– |
} |
3301 |
– |
} |
3302 |
– |
|
3303 |
– |
|
3493 |
|
static final class Values<K,V> extends CHMView<K,V> |
3494 |
|
implements Collection<V> { |
3495 |
|
Values(ConcurrentHashMap<K, V> map) { super(map); } |
3719 |
|
// ------------------------------------------------------- |
3720 |
|
|
3721 |
|
/** |
3722 |
< |
* Returns an extended {@link Parallel} view of this map using the |
3534 |
< |
* given executor for bulk parallel operations. |
3722 |
> |
* Performs the given action for each (key, value). |
3723 |
|
* |
3724 |
< |
* @param executor the executor |
3537 |
< |
* @return a parallel view |
3724 |
> |
* @param action the action |
3725 |
|
*/ |
3726 |
< |
public Parallel parallel(ForkJoinPool executor) { |
3727 |
< |
return new Parallel(executor); |
3726 |
> |
public void forEach(BiAction<K,V> action) { |
3727 |
> |
ForkJoinTasks.forEach |
3728 |
> |
(this, action).invoke(); |
3729 |
|
} |
3730 |
|
|
3731 |
|
/** |
3732 |
< |
* An extended view of a ConcurrentHashMap supporting bulk |
3733 |
< |
* parallel operations. These operations are designed to be |
3734 |
< |
* safely, and often sensibly, applied even with maps that are |
3735 |
< |
* being concurrently updated by other threads; for example, when |
3736 |
< |
* computing a snapshot summary of the values in a shared |
3737 |
< |
* registry. There are three kinds of operation, each with four |
3738 |
< |
* forms, accepting functions with Keys, Values, Entries, and |
3551 |
< |
* (Key, Value) arguments and/or return values. Because the |
3552 |
< |
* elements of a ConcurrentHashMap are not ordered in any |
3553 |
< |
* particular way, and may be processed in different orders in |
3554 |
< |
* different parallel executions, the correctness of supplied |
3555 |
< |
* functions should not depend on any ordering, or on any other |
3556 |
< |
* objects or values that may transiently change while computation |
3557 |
< |
* is in progress; and except for forEach actions, should ideally |
3558 |
< |
* be side-effect-free. |
3559 |
< |
* |
3560 |
< |
* <ul> |
3561 |
< |
* <li> forEach: Perform a given action on each element. |
3562 |
< |
* A variant form applies a given transformation on each element |
3563 |
< |
* before performing the action.</li> |
3564 |
< |
* |
3565 |
< |
* <li> search: Return the first available non-null result of |
3566 |
< |
* applying a given function on each element; skipping further |
3567 |
< |
* search when a result is found.</li> |
3568 |
< |
* |
3569 |
< |
* <li> reduce: Accumulate each element. The supplied reduction |
3570 |
< |
* function cannot rely on ordering (more formally, it should be |
3571 |
< |
* both associative and commutative). There are five variants: |
3572 |
< |
* |
3573 |
< |
* <ul> |
3574 |
< |
* |
3575 |
< |
* <li> Plain reductions. (There is not a form of this method for |
3576 |
< |
* (key, value) function arguments since there is no corresponding |
3577 |
< |
* return type.)</li> |
3578 |
< |
* |
3579 |
< |
* <li> Mapped reductions that accumulate the results of a given |
3580 |
< |
* function applied to each element.</li> |
3581 |
< |
* |
3582 |
< |
* <li> Reductions to scalar doubles, longs, and ints, using a |
3583 |
< |
* given basis value.</li> |
3584 |
< |
* |
3585 |
< |
* </li> |
3586 |
< |
* </ul> |
3587 |
< |
* </ul> |
3588 |
< |
* |
3589 |
< |
* <p>The concurrency properties of the bulk operations follow |
3590 |
< |
* from those of ConcurrentHashMap: Any non-null result returned |
3591 |
< |
* from {@code get(key)} and related access methods bears a |
3592 |
< |
* happens-before relation with the associated insertion or |
3593 |
< |
* update. The result of any bulk operation reflects the |
3594 |
< |
* composition of these per-element relations (but is not |
3595 |
< |
* necessarily atomic with respect to the map as a whole unless it |
3596 |
< |
* is somehow known to be quiescent). Conversely, because keys |
3597 |
< |
* and values in the map are never null, null serves as a reliable |
3598 |
< |
* atomic indicator of the current lack of any result. To |
3599 |
< |
* maintain this property, null serves as an implicit basis for |
3600 |
< |
* all non-scalar reduction operations. For the double, long, and |
3601 |
< |
* int versions, the basis should be one that, when combined with |
3602 |
< |
* any other value, returns that other value (more formally, it |
3603 |
< |
* should be the identity element for the reduction). Most common |
3604 |
< |
* reductions have these properties; for example, computing a sum |
3605 |
< |
* with basis 0 or a minimum with basis MAX_VALUE. |
3606 |
< |
* |
3607 |
< |
* <p>Search and transformation functions provided as arguments |
3608 |
< |
* should similarly return null to indicate the lack of any result |
3609 |
< |
* (in which case it is not used). In the case of mapped |
3610 |
< |
* reductions, this also enables transformations to serve as |
3611 |
< |
* filters, returning null (or, in the case of primitive |
3612 |
< |
* specializations, the identity basis) if the element should not |
3613 |
< |
* be combined. You can create compound transformations and |
3614 |
< |
* filterings by composing them yourself under this "null means |
3615 |
< |
* there is nothing there now" rule before using them in search or |
3616 |
< |
* reduce operations. |
3617 |
< |
* |
3618 |
< |
* <p>Methods accepting and/or returning Entry arguments maintain |
3619 |
< |
* key-value associations. They may be useful for example when |
3620 |
< |
* finding the key for the greatest value. Note that "plain" Entry |
3621 |
< |
* arguments can be supplied using {@code new |
3622 |
< |
* AbstractMap.SimpleEntry(k,v)}. |
3623 |
< |
* |
3624 |
< |
* <p> Bulk operations may complete abruptly, throwing an |
3625 |
< |
* exception encountered in the application of a supplied |
3626 |
< |
* function. Bear in mind when handling such exceptions that other |
3627 |
< |
* concurrently executing functions could also have thrown |
3628 |
< |
* exceptions, or would have done so if the first exception had |
3629 |
< |
* not occurred. |
3630 |
< |
* |
3631 |
< |
* <p>Parallel speedups compared to sequential processing are |
3632 |
< |
* common but not guaranteed. Operations involving brief |
3633 |
< |
* functions on small maps may execute more slowly than sequential |
3634 |
< |
* loops if the underlying work to parallelize the computation is |
3635 |
< |
* more expensive than the computation itself. Similarly, |
3636 |
< |
* parallelization may not lead to much actual parallelism if all |
3637 |
< |
* processors are busy performing unrelated tasks. |
3638 |
< |
* |
3639 |
< |
* <p> All arguments to all task methods must be non-null. |
3640 |
< |
* |
3641 |
< |
* <p><em>jsr166e note: During transition, this class |
3642 |
< |
* uses nested functional interfaces with different names but the |
3643 |
< |
* same forms as those expected for JDK8.<em> |
3732 |
> |
* Performs the given action for each non-null transformation |
3733 |
> |
* of each (key, value). |
3734 |
> |
* |
3735 |
> |
* @param transformer a function returning the transformation |
3736 |
> |
* for an element, or null of there is no transformation (in |
3737 |
> |
* which case the action is not applied). |
3738 |
> |
* @param action the action |
3739 |
|
*/ |
3740 |
< |
public class Parallel { |
3741 |
< |
final ForkJoinPool fjp; |
3740 |
> |
public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer, |
3741 |
> |
Action<U> action) { |
3742 |
> |
ForkJoinTasks.forEach |
3743 |
> |
(this, transformer, action).invoke(); |
3744 |
> |
} |
3745 |
|
|
3746 |
< |
/** |
3747 |
< |
* Returns an extended view of this map using the given |
3748 |
< |
* executor for bulk parallel operations. |
3749 |
< |
* |
3750 |
< |
* @param executor the executor |
3751 |
< |
*/ |
3752 |
< |
public Parallel(ForkJoinPool executor) { |
3753 |
< |
this.fjp = executor; |
3754 |
< |
} |
3746 |
> |
/** |
3747 |
> |
* Returns a non-null result from applying the given search |
3748 |
> |
* function on each (key, value), or null if none. Upon |
3749 |
> |
* success, further element processing is suppressed and the |
3750 |
> |
* results of any other parallel invocations of the search |
3751 |
> |
* function are ignored. |
3752 |
> |
* |
3753 |
> |
* @param searchFunction a function returning a non-null |
3754 |
> |
* result on success, else null |
3755 |
> |
* @return a non-null result from applying the given search |
3756 |
> |
* function on each (key, value), or null if none |
3757 |
> |
*/ |
3758 |
> |
public <U> U search(BiFun<? super K, ? super V, ? extends U> searchFunction) { |
3759 |
> |
return ForkJoinTasks.search |
3760 |
> |
(this, searchFunction).invoke(); |
3761 |
> |
} |
3762 |
|
|
3763 |
< |
/** |
3764 |
< |
* Performs the given action for each (key, value). |
3765 |
< |
* |
3766 |
< |
* @param action the action |
3767 |
< |
*/ |
3768 |
< |
public void forEach(BiAction<K,V> action) { |
3769 |
< |
fjp.invoke(ForkJoinTasks.forEach |
3770 |
< |
(ConcurrentHashMap.this, action)); |
3771 |
< |
} |
3763 |
> |
/** |
3764 |
> |
* Returns the result of accumulating the given transformation |
3765 |
> |
* of all (key, value) pairs using the given reducer to |
3766 |
> |
* combine values, or null if none. |
3767 |
> |
* |
3768 |
> |
* @param transformer a function returning the transformation |
3769 |
> |
* for an element, or null of there is no transformation (in |
3770 |
> |
* which case it is not combined). |
3771 |
> |
* @param reducer a commutative associative combining function |
3772 |
> |
* @return the result of accumulating the given transformation |
3773 |
> |
* of all (key, value) pairs |
3774 |
> |
*/ |
3775 |
> |
public <U> U reduce(BiFun<? super K, ? super V, ? extends U> transformer, |
3776 |
> |
BiFun<? super U, ? super U, ? extends U> reducer) { |
3777 |
> |
return ForkJoinTasks.reduce |
3778 |
> |
(this, transformer, reducer).invoke(); |
3779 |
> |
} |
3780 |
|
|
3781 |
< |
/** |
3782 |
< |
* Performs the given action for each non-null transformation |
3783 |
< |
* of each (key, value). |
3784 |
< |
* |
3785 |
< |
* @param transformer a function returning the transformation |
3786 |
< |
* for an element, or null if there is no transformation (in |
3787 |
< |
* which case the action is not applied) |
3788 |
< |
* @param action the action |
3789 |
< |
*/ |
3790 |
< |
public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer, |
3791 |
< |
Action<U> action) { |
3792 |
< |
fjp.invoke(ForkJoinTasks.forEach |
3793 |
< |
(ConcurrentHashMap.this, transformer, action)); |
3794 |
< |
} |
3781 |
> |
/** |
3782 |
> |
* Returns the result of accumulating the given transformation |
3783 |
> |
* of all (key, value) pairs using the given reducer to |
3784 |
> |
* combine values, and the given basis as an identity value. |
3785 |
> |
* |
3786 |
> |
* @param transformer a function returning the transformation |
3787 |
> |
* for an element |
3788 |
> |
* @param basis the identity (initial default value) for the reduction |
3789 |
> |
* @param reducer a commutative associative combining function |
3790 |
> |
* @return the result of accumulating the given transformation |
3791 |
> |
* of all (key, value) pairs |
3792 |
> |
*/ |
3793 |
> |
public double reduceToDouble(ObjectByObjectToDouble<? super K, ? super V> transformer, |
3794 |
> |
double basis, |
3795 |
> |
DoubleByDoubleToDouble reducer) { |
3796 |
> |
return ForkJoinTasks.reduceToDouble |
3797 |
> |
(this, transformer, basis, reducer).invoke(); |
3798 |
> |
} |
3799 |
|
|
3800 |
< |
/** |
3801 |
< |
* Returns a non-null result from applying the given search |
3802 |
< |
* function on each (key, value), or null if none. Upon |
3803 |
< |
* success, further element processing is suppressed and the |
3804 |
< |
* results of any other parallel invocations of the search |
3805 |
< |
* function are ignored. |
3806 |
< |
* |
3807 |
< |
* @param searchFunction a function returning a non-null |
3808 |
< |
* result on success, else null |
3809 |
< |
* @return a non-null result from applying the given search |
3810 |
< |
* function on each (key, value), or null if none |
3811 |
< |
*/ |
3812 |
< |
public <U> U search(BiFun<? super K, ? super V, ? extends U> searchFunction) { |
3813 |
< |
return fjp.invoke(ForkJoinTasks.search |
3814 |
< |
(ConcurrentHashMap.this, searchFunction)); |
3815 |
< |
} |
3800 |
> |
/** |
3801 |
> |
* Returns the result of accumulating the given transformation |
3802 |
> |
* of all (key, value) pairs using the given reducer to |
3803 |
> |
* combine values, and the given basis as an identity value. |
3804 |
> |
* |
3805 |
> |
* @param transformer a function returning the transformation |
3806 |
> |
* for an element |
3807 |
> |
* @param basis the identity (initial default value) for the reduction |
3808 |
> |
* @param reducer a commutative associative combining function |
3809 |
> |
* @return the result of accumulating the given transformation |
3810 |
> |
* of all (key, value) pairs |
3811 |
> |
*/ |
3812 |
> |
public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer, |
3813 |
> |
long basis, |
3814 |
> |
LongByLongToLong reducer) { |
3815 |
> |
return ForkJoinTasks.reduceToLong |
3816 |
> |
(this, transformer, basis, reducer).invoke(); |
3817 |
> |
} |
3818 |
|
|
3819 |
< |
/** |
3820 |
< |
* Returns the result of accumulating the given transformation |
3821 |
< |
* of all (key, value) pairs using the given reducer to |
3822 |
< |
* combine values, or null if none. |
3823 |
< |
* |
3824 |
< |
* @param transformer a function returning the transformation |
3825 |
< |
* for an element, or null if there is no transformation (in |
3826 |
< |
* which case it is not combined) |
3827 |
< |
* @param reducer a commutative associative combining function |
3828 |
< |
* @return the result of accumulating the given transformation |
3829 |
< |
* of all (key, value) pairs |
3830 |
< |
*/ |
3831 |
< |
public <U> U reduce(BiFun<? super K, ? super V, ? extends U> transformer, |
3819 |
> |
/** |
3820 |
> |
* Returns the result of accumulating the given transformation |
3821 |
> |
* of all (key, value) pairs using the given reducer to |
3822 |
> |
* combine values, and the given basis as an identity value. |
3823 |
> |
* |
3824 |
> |
* @param transformer a function returning the transformation |
3825 |
> |
* for an element |
3826 |
> |
* @param basis the identity (initial default value) for the reduction |
3827 |
> |
* @param reducer a commutative associative combining function |
3828 |
> |
* @return the result of accumulating the given transformation |
3829 |
> |
* of all (key, value) pairs |
3830 |
> |
*/ |
3831 |
> |
public int reduceToInt(ObjectByObjectToInt<? super K, ? super V> transformer, |
3832 |
> |
int basis, |
3833 |
> |
IntByIntToInt reducer) { |
3834 |
> |
return ForkJoinTasks.reduceToInt |
3835 |
> |
(this, transformer, basis, reducer).invoke(); |
3836 |
> |
} |
3837 |
> |
|
3838 |
> |
/** |
3839 |
> |
* Performs the given action for each key. |
3840 |
> |
* |
3841 |
> |
* @param action the action |
3842 |
> |
*/ |
3843 |
> |
public void forEachKey(Action<K> action) { |
3844 |
> |
ForkJoinTasks.forEachKey |
3845 |
> |
(this, action).invoke(); |
3846 |
> |
} |
3847 |
> |
|
3848 |
> |
/** |
3849 |
> |
* Performs the given action for each non-null transformation |
3850 |
> |
* of each key. |
3851 |
> |
* |
3852 |
> |
* @param transformer a function returning the transformation |
3853 |
> |
* for an element, or null of there is no transformation (in |
3854 |
> |
* which case the action is not applied). |
3855 |
> |
* @param action the action |
3856 |
> |
*/ |
3857 |
> |
public <U> void forEachKey(Fun<? super K, ? extends U> transformer, |
3858 |
> |
Action<U> action) { |
3859 |
> |
ForkJoinTasks.forEachKey |
3860 |
> |
(this, transformer, action).invoke(); |
3861 |
> |
} |
3862 |
> |
|
3863 |
> |
/** |
3864 |
> |
* Returns a non-null result from applying the given search |
3865 |
> |
* function on each key, or null if none. Upon success, |
3866 |
> |
* further element processing is suppressed and the results of |
3867 |
> |
* any other parallel invocations of the search function are |
3868 |
> |
* ignored. |
3869 |
> |
* |
3870 |
> |
* @param searchFunction a function returning a non-null |
3871 |
> |
* result on success, else null |
3872 |
> |
* @return a non-null result from applying the given search |
3873 |
> |
* function on each key, or null if none |
3874 |
> |
*/ |
3875 |
> |
public <U> U searchKeys(Fun<? super K, ? extends U> searchFunction) { |
3876 |
> |
return ForkJoinTasks.searchKeys |
3877 |
> |
(this, searchFunction).invoke(); |
3878 |
> |
} |
3879 |
> |
|
3880 |
> |
/** |
3881 |
> |
* Returns the result of accumulating all keys using the given |
3882 |
> |
* reducer to combine values, or null if none. |
3883 |
> |
* |
3884 |
> |
* @param reducer a commutative associative combining function |
3885 |
> |
* @return the result of accumulating all keys using the given |
3886 |
> |
* reducer to combine values, or null if none |
3887 |
> |
*/ |
3888 |
> |
public K reduceKeys(BiFun<? super K, ? super K, ? extends K> reducer) { |
3889 |
> |
return ForkJoinTasks.reduceKeys |
3890 |
> |
(this, reducer).invoke(); |
3891 |
> |
} |
3892 |
> |
|
3893 |
> |
/** |
3894 |
> |
* Returns the result of accumulating the given transformation |
3895 |
> |
* of all keys using the given reducer to combine values, or |
3896 |
> |
* null if none. |
3897 |
> |
* |
3898 |
> |
* @param transformer a function returning the transformation |
3899 |
> |
* for an element, or null of there is no transformation (in |
3900 |
> |
* which case it is not combined). |
3901 |
> |
* @param reducer a commutative associative combining function |
3902 |
> |
* @return the result of accumulating the given transformation |
3903 |
> |
* of all keys |
3904 |
> |
*/ |
3905 |
> |
public <U> U reduceKeys(Fun<? super K, ? extends U> transformer, |
3906 |
|
BiFun<? super U, ? super U, ? extends U> reducer) { |
3907 |
< |
return fjp.invoke(ForkJoinTasks.reduce |
3908 |
< |
(ConcurrentHashMap.this, transformer, reducer)); |
3909 |
< |
} |
3907 |
> |
return ForkJoinTasks.reduceKeys |
3908 |
> |
(this, transformer, reducer).invoke(); |
3909 |
> |
} |
3910 |
|
|
3911 |
< |
/** |
3912 |
< |
* Returns the result of accumulating the given transformation |
3913 |
< |
* of all (key, value) pairs using the given reducer to |
3914 |
< |
* combine values, and the given basis as an identity value. |
3915 |
< |
* |
3916 |
< |
* @param transformer a function returning the transformation |
3917 |
< |
* for an element |
3918 |
< |
* @param basis the identity (initial default value) for the reduction |
3919 |
< |
* @param reducer a commutative associative combining function |
3920 |
< |
* @return the result of accumulating the given transformation |
3921 |
< |
* of all (key, value) pairs |
3922 |
< |
*/ |
3923 |
< |
public double reduceToDouble(ObjectByObjectToDouble<? super K, ? super V> transformer, |
3911 |
> |
/** |
3912 |
> |
* Returns the result of accumulating the given transformation |
3913 |
> |
* of all keys using the given reducer to combine values, and |
3914 |
> |
* the given basis as an identity value. |
3915 |
> |
* |
3916 |
> |
* @param transformer a function returning the transformation |
3917 |
> |
* for an element |
3918 |
> |
* @param basis the identity (initial default value) for the reduction |
3919 |
> |
* @param reducer a commutative associative combining function |
3920 |
> |
* @return the result of accumulating the given transformation |
3921 |
> |
* of all keys |
3922 |
> |
*/ |
3923 |
> |
public double reduceKeysToDouble(ObjectToDouble<? super K> transformer, |
3924 |
|
double basis, |
3925 |
|
DoubleByDoubleToDouble reducer) { |
3926 |
< |
return fjp.invoke(ForkJoinTasks.reduceToDouble |
3927 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
3928 |
< |
} |
3926 |
> |
return ForkJoinTasks.reduceKeysToDouble |
3927 |
> |
(this, transformer, basis, reducer).invoke(); |
3928 |
> |
} |
3929 |
|
|
3930 |
< |
/** |
3931 |
< |
* Returns the result of accumulating the given transformation |
3932 |
< |
* of all (key, value) pairs using the given reducer to |
3933 |
< |
* combine values, and the given basis as an identity value. |
3934 |
< |
* |
3935 |
< |
* @param transformer a function returning the transformation |
3936 |
< |
* for an element |
3937 |
< |
* @param basis the identity (initial default value) for the reduction |
3938 |
< |
* @param reducer a commutative associative combining function |
3939 |
< |
* @return the result of accumulating the given transformation |
3940 |
< |
* of all (key, value) pairs |
3941 |
< |
*/ |
3942 |
< |
public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer, |
3930 |
> |
/** |
3931 |
> |
* Returns the result of accumulating the given transformation |
3932 |
> |
* of all keys using the given reducer to combine values, and |
3933 |
> |
* the given basis as an identity value. |
3934 |
> |
* |
3935 |
> |
* @param transformer a function returning the transformation |
3936 |
> |
* for an element |
3937 |
> |
* @param basis the identity (initial default value) for the reduction |
3938 |
> |
* @param reducer a commutative associative combining function |
3939 |
> |
* @return the result of accumulating the given transformation |
3940 |
> |
* of all keys |
3941 |
> |
*/ |
3942 |
> |
public long reduceKeysToLong(ObjectToLong<? super K> transformer, |
3943 |
|
long basis, |
3944 |
|
LongByLongToLong reducer) { |
3945 |
< |
return fjp.invoke(ForkJoinTasks.reduceToLong |
3946 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
3947 |
< |
} |
3945 |
> |
return ForkJoinTasks.reduceKeysToLong |
3946 |
> |
(this, transformer, basis, reducer).invoke(); |
3947 |
> |
} |
3948 |
|
|
3949 |
< |
/** |
3950 |
< |
* Returns the result of accumulating the given transformation |
3951 |
< |
* of all (key, value) pairs using the given reducer to |
3952 |
< |
* combine values, and the given basis as an identity value. |
3953 |
< |
* |
3954 |
< |
* @param transformer a function returning the transformation |
3955 |
< |
* for an element |
3956 |
< |
* @param basis the identity (initial default value) for the reduction |
3957 |
< |
* @param reducer a commutative associative combining function |
3958 |
< |
* @return the result of accumulating the given transformation |
3959 |
< |
* of all (key, value) pairs |
3960 |
< |
*/ |
3961 |
< |
public int reduceToInt(ObjectByObjectToInt<? super K, ? super V> transformer, |
3949 |
> |
/** |
3950 |
> |
* Returns the result of accumulating the given transformation |
3951 |
> |
* of all keys using the given reducer to combine values, and |
3952 |
> |
* the given basis as an identity value. |
3953 |
> |
* |
3954 |
> |
* @param transformer a function returning the transformation |
3955 |
> |
* for an element |
3956 |
> |
* @param basis the identity (initial default value) for the reduction |
3957 |
> |
* @param reducer a commutative associative combining function |
3958 |
> |
* @return the result of accumulating the given transformation |
3959 |
> |
* of all keys |
3960 |
> |
*/ |
3961 |
> |
public int reduceKeysToInt(ObjectToInt<? super K> transformer, |
3962 |
|
int basis, |
3963 |
|
IntByIntToInt reducer) { |
3964 |
< |
return fjp.invoke(ForkJoinTasks.reduceToInt |
3965 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
3966 |
< |
} |
3774 |
< |
|
3775 |
< |
/** |
3776 |
< |
* Performs the given action for each key. |
3777 |
< |
* |
3778 |
< |
* @param action the action |
3779 |
< |
*/ |
3780 |
< |
public void forEachKey(Action<K> action) { |
3781 |
< |
fjp.invoke(ForkJoinTasks.forEachKey |
3782 |
< |
(ConcurrentHashMap.this, action)); |
3783 |
< |
} |
3784 |
< |
|
3785 |
< |
/** |
3786 |
< |
* Performs the given action for each non-null transformation |
3787 |
< |
* of each key. |
3788 |
< |
* |
3789 |
< |
* @param transformer a function returning the transformation |
3790 |
< |
* for an element, or null if there is no transformation (in |
3791 |
< |
* which case the action is not applied) |
3792 |
< |
* @param action the action |
3793 |
< |
*/ |
3794 |
< |
public <U> void forEachKey(Fun<? super K, ? extends U> transformer, |
3795 |
< |
Action<U> action) { |
3796 |
< |
fjp.invoke(ForkJoinTasks.forEachKey |
3797 |
< |
(ConcurrentHashMap.this, transformer, action)); |
3798 |
< |
} |
3799 |
< |
|
3800 |
< |
/** |
3801 |
< |
* Returns a non-null result from applying the given search |
3802 |
< |
* function on each key, or null if none. Upon success, |
3803 |
< |
* further element processing is suppressed and the results of |
3804 |
< |
* any other parallel invocations of the search function are |
3805 |
< |
* ignored. |
3806 |
< |
* |
3807 |
< |
* @param searchFunction a function returning a non-null |
3808 |
< |
* result on success, else null |
3809 |
< |
* @return a non-null result from applying the given search |
3810 |
< |
* function on each key, or null if none |
3811 |
< |
*/ |
3812 |
< |
public <U> U searchKeys(Fun<? super K, ? extends U> searchFunction) { |
3813 |
< |
return fjp.invoke(ForkJoinTasks.searchKeys |
3814 |
< |
(ConcurrentHashMap.this, searchFunction)); |
3815 |
< |
} |
3816 |
< |
|
3817 |
< |
/** |
3818 |
< |
* Returns the result of accumulating all keys using the given |
3819 |
< |
* reducer to combine values, or null if none. |
3820 |
< |
* |
3821 |
< |
* @param reducer a commutative associative combining function |
3822 |
< |
* @return the result of accumulating all keys using the given |
3823 |
< |
* reducer to combine values, or null if none |
3824 |
< |
*/ |
3825 |
< |
public K reduceKeys(BiFun<? super K, ? super K, ? extends K> reducer) { |
3826 |
< |
return fjp.invoke(ForkJoinTasks.reduceKeys |
3827 |
< |
(ConcurrentHashMap.this, reducer)); |
3828 |
< |
} |
3829 |
< |
|
3830 |
< |
/** |
3831 |
< |
* Returns the result of accumulating the given transformation |
3832 |
< |
* of all keys using the given reducer to combine values, or |
3833 |
< |
* null if none. |
3834 |
< |
* |
3835 |
< |
* @param transformer a function returning the transformation |
3836 |
< |
* for an element, or null if there is no transformation (in |
3837 |
< |
* which case it is not combined) |
3838 |
< |
* @param reducer a commutative associative combining function |
3839 |
< |
* @return the result of accumulating the given transformation |
3840 |
< |
* of all keys |
3841 |
< |
*/ |
3842 |
< |
public <U> U reduceKeys(Fun<? super K, ? extends U> transformer, |
3843 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
3844 |
< |
return fjp.invoke(ForkJoinTasks.reduceKeys |
3845 |
< |
(ConcurrentHashMap.this, transformer, reducer)); |
3846 |
< |
} |
3847 |
< |
|
3848 |
< |
/** |
3849 |
< |
* Returns the result of accumulating the given transformation |
3850 |
< |
* of all keys using the given reducer to combine values, and |
3851 |
< |
* the given basis as an identity value. |
3852 |
< |
* |
3853 |
< |
* @param transformer a function returning the transformation |
3854 |
< |
* for an element |
3855 |
< |
* @param basis the identity (initial default value) for the reduction |
3856 |
< |
* @param reducer a commutative associative combining function |
3857 |
< |
* @return the result of accumulating the given transformation |
3858 |
< |
* of all keys |
3859 |
< |
*/ |
3860 |
< |
public double reduceKeysToDouble(ObjectToDouble<? super K> transformer, |
3861 |
< |
double basis, |
3862 |
< |
DoubleByDoubleToDouble reducer) { |
3863 |
< |
return fjp.invoke(ForkJoinTasks.reduceKeysToDouble |
3864 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
3865 |
< |
} |
3866 |
< |
|
3867 |
< |
/** |
3868 |
< |
* Returns the result of accumulating the given transformation |
3869 |
< |
* of all keys using the given reducer to combine values, and |
3870 |
< |
* the given basis as an identity value. |
3871 |
< |
* |
3872 |
< |
* @param transformer a function returning the transformation |
3873 |
< |
* for an element |
3874 |
< |
* @param basis the identity (initial default value) for the reduction |
3875 |
< |
* @param reducer a commutative associative combining function |
3876 |
< |
* @return the result of accumulating the given transformation |
3877 |
< |
* of all keys |
3878 |
< |
*/ |
3879 |
< |
public long reduceKeysToLong(ObjectToLong<? super K> transformer, |
3880 |
< |
long basis, |
3881 |
< |
LongByLongToLong reducer) { |
3882 |
< |
return fjp.invoke(ForkJoinTasks.reduceKeysToLong |
3883 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
3884 |
< |
} |
3885 |
< |
|
3886 |
< |
/** |
3887 |
< |
* Returns the result of accumulating the given transformation |
3888 |
< |
* of all keys using the given reducer to combine values, and |
3889 |
< |
* the given basis as an identity value. |
3890 |
< |
* |
3891 |
< |
* @param transformer a function returning the transformation |
3892 |
< |
* for an element |
3893 |
< |
* @param basis the identity (initial default value) for the reduction |
3894 |
< |
* @param reducer a commutative associative combining function |
3895 |
< |
* @return the result of accumulating the given transformation |
3896 |
< |
* of all keys |
3897 |
< |
*/ |
3898 |
< |
public int reduceKeysToInt(ObjectToInt<? super K> transformer, |
3899 |
< |
int basis, |
3900 |
< |
IntByIntToInt reducer) { |
3901 |
< |
return fjp.invoke(ForkJoinTasks.reduceKeysToInt |
3902 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
3903 |
< |
} |
3964 |
> |
return ForkJoinTasks.reduceKeysToInt |
3965 |
> |
(this, transformer, basis, reducer).invoke(); |
3966 |
> |
} |
3967 |
|
|
3968 |
< |
/** |
3969 |
< |
* Performs the given action for each value. |
3970 |
< |
* |
3971 |
< |
* @param action the action |
3972 |
< |
*/ |
3973 |
< |
public void forEachValue(Action<V> action) { |
3974 |
< |
fjp.invoke(ForkJoinTasks.forEachValue |
3975 |
< |
(ConcurrentHashMap.this, action)); |
3976 |
< |
} |
3968 |
> |
/** |
3969 |
> |
* Performs the given action for each value. |
3970 |
> |
* |
3971 |
> |
* @param action the action |
3972 |
> |
*/ |
3973 |
> |
public void forEachValue(Action<V> action) { |
3974 |
> |
ForkJoinTasks.forEachValue |
3975 |
> |
(this, action).invoke(); |
3976 |
> |
} |
3977 |
|
|
3978 |
< |
/** |
3979 |
< |
* Performs the given action for each non-null transformation |
3980 |
< |
* of each value. |
3981 |
< |
* |
3982 |
< |
* @param transformer a function returning the transformation |
3983 |
< |
* for an element, or null if there is no transformation (in |
3984 |
< |
* which case the action is not applied) |
3985 |
< |
*/ |
3986 |
< |
public <U> void forEachValue(Fun<? super V, ? extends U> transformer, |
3987 |
< |
Action<U> action) { |
3988 |
< |
fjp.invoke(ForkJoinTasks.forEachValue |
3989 |
< |
(ConcurrentHashMap.this, transformer, action)); |
3990 |
< |
} |
3978 |
> |
/** |
3979 |
> |
* Performs the given action for each non-null transformation |
3980 |
> |
* of each value. |
3981 |
> |
* |
3982 |
> |
* @param transformer a function returning the transformation |
3983 |
> |
* for an element, or null of there is no transformation (in |
3984 |
> |
* which case the action is not applied). |
3985 |
> |
*/ |
3986 |
> |
public <U> void forEachValue(Fun<? super V, ? extends U> transformer, |
3987 |
> |
Action<U> action) { |
3988 |
> |
ForkJoinTasks.forEachValue |
3989 |
> |
(this, transformer, action).invoke(); |
3990 |
> |
} |
3991 |
|
|
3992 |
< |
/** |
3993 |
< |
* Returns a non-null result from applying the given search |
3994 |
< |
* function on each value, or null if none. Upon success, |
3995 |
< |
* further element processing is suppressed and the results of |
3996 |
< |
* any other parallel invocations of the search function are |
3997 |
< |
* ignored. |
3998 |
< |
* |
3999 |
< |
* @param searchFunction a function returning a non-null |
4000 |
< |
* result on success, else null |
4001 |
< |
* @return a non-null result from applying the given search |
4002 |
< |
* function on each value, or null if none |
4003 |
< |
*/ |
4004 |
< |
public <U> U searchValues(Fun<? super V, ? extends U> searchFunction) { |
4005 |
< |
return fjp.invoke(ForkJoinTasks.searchValues |
4006 |
< |
(ConcurrentHashMap.this, searchFunction)); |
4007 |
< |
} |
3992 |
> |
/** |
3993 |
> |
* Returns a non-null result from applying the given search |
3994 |
> |
* function on each value, or null if none. Upon success, |
3995 |
> |
* further element processing is suppressed and the results of |
3996 |
> |
* any other parallel invocations of the search function are |
3997 |
> |
* ignored. |
3998 |
> |
* |
3999 |
> |
* @param searchFunction a function returning a non-null |
4000 |
> |
* result on success, else null |
4001 |
> |
* @return a non-null result from applying the given search |
4002 |
> |
* function on each value, or null if none |
4003 |
> |
* |
4004 |
> |
*/ |
4005 |
> |
public <U> U searchValues(Fun<? super V, ? extends U> searchFunction) { |
4006 |
> |
return ForkJoinTasks.searchValues |
4007 |
> |
(this, searchFunction).invoke(); |
4008 |
> |
} |
4009 |
|
|
4010 |
< |
/** |
4011 |
< |
* Returns the result of accumulating all values using the |
4012 |
< |
* given reducer to combine values, or null if none. |
4013 |
< |
* |
4014 |
< |
* @param reducer a commutative associative combining function |
4015 |
< |
* @return the result of accumulating all values |
4016 |
< |
*/ |
4017 |
< |
public V reduceValues(BiFun<? super V, ? super V, ? extends V> reducer) { |
4018 |
< |
return fjp.invoke(ForkJoinTasks.reduceValues |
4019 |
< |
(ConcurrentHashMap.this, reducer)); |
4020 |
< |
} |
4010 |
> |
/** |
4011 |
> |
* Returns the result of accumulating all values using the |
4012 |
> |
* given reducer to combine values, or null if none. |
4013 |
> |
* |
4014 |
> |
* @param reducer a commutative associative combining function |
4015 |
> |
* @return the result of accumulating all values |
4016 |
> |
*/ |
4017 |
> |
public V reduceValues(BiFun<? super V, ? super V, ? extends V> reducer) { |
4018 |
> |
return ForkJoinTasks.reduceValues |
4019 |
> |
(this, reducer).invoke(); |
4020 |
> |
} |
4021 |
|
|
4022 |
< |
/** |
4023 |
< |
* Returns the result of accumulating the given transformation |
4024 |
< |
* of all values using the given reducer to combine values, or |
4025 |
< |
* null if none. |
4026 |
< |
* |
4027 |
< |
* @param transformer a function returning the transformation |
4028 |
< |
* for an element, or null if there is no transformation (in |
4029 |
< |
* which case it is not combined) |
4030 |
< |
* @param reducer a commutative associative combining function |
4031 |
< |
* @return the result of accumulating the given transformation |
4032 |
< |
* of all values |
4033 |
< |
*/ |
4034 |
< |
public <U> U reduceValues(Fun<? super V, ? extends U> transformer, |
4035 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4036 |
< |
return fjp.invoke(ForkJoinTasks.reduceValues |
4037 |
< |
(ConcurrentHashMap.this, transformer, reducer)); |
4038 |
< |
} |
4022 |
> |
/** |
4023 |
> |
* Returns the result of accumulating the given transformation |
4024 |
> |
* of all values using the given reducer to combine values, or |
4025 |
> |
* null if none. |
4026 |
> |
* |
4027 |
> |
* @param transformer a function returning the transformation |
4028 |
> |
* for an element, or null of there is no transformation (in |
4029 |
> |
* which case it is not combined). |
4030 |
> |
* @param reducer a commutative associative combining function |
4031 |
> |
* @return the result of accumulating the given transformation |
4032 |
> |
* of all values |
4033 |
> |
*/ |
4034 |
> |
public <U> U reduceValues(Fun<? super V, ? extends U> transformer, |
4035 |
> |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4036 |
> |
return ForkJoinTasks.reduceValues |
4037 |
> |
(this, transformer, reducer).invoke(); |
4038 |
> |
} |
4039 |
|
|
4040 |
< |
/** |
4041 |
< |
* Returns the result of accumulating the given transformation |
4042 |
< |
* of all values using the given reducer to combine values, |
4043 |
< |
* and the given basis as an identity value. |
4044 |
< |
* |
4045 |
< |
* @param transformer a function returning the transformation |
4046 |
< |
* for an element |
4047 |
< |
* @param basis the identity (initial default value) for the reduction |
4048 |
< |
* @param reducer a commutative associative combining function |
4049 |
< |
* @return the result of accumulating the given transformation |
4050 |
< |
* of all values |
4051 |
< |
*/ |
4052 |
< |
public double reduceValuesToDouble(ObjectToDouble<? super V> transformer, |
4053 |
< |
double basis, |
4054 |
< |
DoubleByDoubleToDouble reducer) { |
4055 |
< |
return fjp.invoke(ForkJoinTasks.reduceValuesToDouble |
4056 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
4057 |
< |
} |
4040 |
> |
/** |
4041 |
> |
* Returns the result of accumulating the given transformation |
4042 |
> |
* of all values using the given reducer to combine values, |
4043 |
> |
* and the given basis as an identity value. |
4044 |
> |
* |
4045 |
> |
* @param transformer a function returning the transformation |
4046 |
> |
* for an element |
4047 |
> |
* @param basis the identity (initial default value) for the reduction |
4048 |
> |
* @param reducer a commutative associative combining function |
4049 |
> |
* @return the result of accumulating the given transformation |
4050 |
> |
* of all values |
4051 |
> |
*/ |
4052 |
> |
public double reduceValuesToDouble(ObjectToDouble<? super V> transformer, |
4053 |
> |
double basis, |
4054 |
> |
DoubleByDoubleToDouble reducer) { |
4055 |
> |
return ForkJoinTasks.reduceValuesToDouble |
4056 |
> |
(this, transformer, basis, reducer).invoke(); |
4057 |
> |
} |
4058 |
|
|
4059 |
< |
/** |
4060 |
< |
* Returns the result of accumulating the given transformation |
4061 |
< |
* of all values using the given reducer to combine values, |
4062 |
< |
* and the given basis as an identity value. |
4063 |
< |
* |
4064 |
< |
* @param transformer a function returning the transformation |
4065 |
< |
* for an element |
4066 |
< |
* @param basis the identity (initial default value) for the reduction |
4067 |
< |
* @param reducer a commutative associative combining function |
4068 |
< |
* @return the result of accumulating the given transformation |
4069 |
< |
* of all values |
4070 |
< |
*/ |
4071 |
< |
public long reduceValuesToLong(ObjectToLong<? super V> transformer, |
4072 |
< |
long basis, |
4073 |
< |
LongByLongToLong reducer) { |
4074 |
< |
return fjp.invoke(ForkJoinTasks.reduceValuesToLong |
4075 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
4076 |
< |
} |
4059 |
> |
/** |
4060 |
> |
* Returns the result of accumulating the given transformation |
4061 |
> |
* of all values using the given reducer to combine values, |
4062 |
> |
* and the given basis as an identity value. |
4063 |
> |
* |
4064 |
> |
* @param transformer a function returning the transformation |
4065 |
> |
* for an element |
4066 |
> |
* @param basis the identity (initial default value) for the reduction |
4067 |
> |
* @param reducer a commutative associative combining function |
4068 |
> |
* @return the result of accumulating the given transformation |
4069 |
> |
* of all values |
4070 |
> |
*/ |
4071 |
> |
public long reduceValuesToLong(ObjectToLong<? super V> transformer, |
4072 |
> |
long basis, |
4073 |
> |
LongByLongToLong reducer) { |
4074 |
> |
return ForkJoinTasks.reduceValuesToLong |
4075 |
> |
(this, transformer, basis, reducer).invoke(); |
4076 |
> |
} |
4077 |
|
|
4078 |
< |
/** |
4079 |
< |
* Returns the result of accumulating the given transformation |
4080 |
< |
* of all values using the given reducer to combine values, |
4081 |
< |
* and the given basis as an identity value. |
4082 |
< |
* |
4083 |
< |
* @param transformer a function returning the transformation |
4084 |
< |
* for an element |
4085 |
< |
* @param basis the identity (initial default value) for the reduction |
4086 |
< |
* @param reducer a commutative associative combining function |
4087 |
< |
* @return the result of accumulating the given transformation |
4088 |
< |
* of all values |
4089 |
< |
*/ |
4090 |
< |
public int reduceValuesToInt(ObjectToInt<? super V> transformer, |
4091 |
< |
int basis, |
4092 |
< |
IntByIntToInt reducer) { |
4093 |
< |
return fjp.invoke(ForkJoinTasks.reduceValuesToInt |
4094 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
4095 |
< |
} |
4078 |
> |
/** |
4079 |
> |
* Returns the result of accumulating the given transformation |
4080 |
> |
* of all values using the given reducer to combine values, |
4081 |
> |
* and the given basis as an identity value. |
4082 |
> |
* |
4083 |
> |
* @param transformer a function returning the transformation |
4084 |
> |
* for an element |
4085 |
> |
* @param basis the identity (initial default value) for the reduction |
4086 |
> |
* @param reducer a commutative associative combining function |
4087 |
> |
* @return the result of accumulating the given transformation |
4088 |
> |
* of all values |
4089 |
> |
*/ |
4090 |
> |
public int reduceValuesToInt(ObjectToInt<? super V> transformer, |
4091 |
> |
int basis, |
4092 |
> |
IntByIntToInt reducer) { |
4093 |
> |
return ForkJoinTasks.reduceValuesToInt |
4094 |
> |
(this, transformer, basis, reducer).invoke(); |
4095 |
> |
} |
4096 |
|
|
4097 |
< |
/** |
4098 |
< |
* Performs the given action for each entry. |
4099 |
< |
* |
4100 |
< |
* @param action the action |
4101 |
< |
*/ |
4102 |
< |
public void forEachEntry(Action<Map.Entry<K,V>> action) { |
4103 |
< |
fjp.invoke(ForkJoinTasks.forEachEntry |
4104 |
< |
(ConcurrentHashMap.this, action)); |
4105 |
< |
} |
4097 |
> |
/** |
4098 |
> |
* Performs the given action for each entry. |
4099 |
> |
* |
4100 |
> |
* @param action the action |
4101 |
> |
*/ |
4102 |
> |
public void forEachEntry(Action<Map.Entry<K,V>> action) { |
4103 |
> |
ForkJoinTasks.forEachEntry |
4104 |
> |
(this, action).invoke(); |
4105 |
> |
} |
4106 |
|
|
4107 |
< |
/** |
4108 |
< |
* Performs the given action for each non-null transformation |
4109 |
< |
* of each entry. |
4110 |
< |
* |
4111 |
< |
* @param transformer a function returning the transformation |
4112 |
< |
* for an element, or null if there is no transformation (in |
4113 |
< |
* which case the action is not applied) |
4114 |
< |
* @param action the action |
4115 |
< |
*/ |
4116 |
< |
public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4117 |
< |
Action<U> action) { |
4118 |
< |
fjp.invoke(ForkJoinTasks.forEachEntry |
4119 |
< |
(ConcurrentHashMap.this, transformer, action)); |
4120 |
< |
} |
4107 |
> |
/** |
4108 |
> |
* Performs the given action for each non-null transformation |
4109 |
> |
* of each entry. |
4110 |
> |
* |
4111 |
> |
* @param transformer a function returning the transformation |
4112 |
> |
* for an element, or null of there is no transformation (in |
4113 |
> |
* which case the action is not applied). |
4114 |
> |
* @param action the action |
4115 |
> |
*/ |
4116 |
> |
public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4117 |
> |
Action<U> action) { |
4118 |
> |
ForkJoinTasks.forEachEntry |
4119 |
> |
(this, transformer, action).invoke(); |
4120 |
> |
} |
4121 |
|
|
4122 |
< |
/** |
4123 |
< |
* Returns a non-null result from applying the given search |
4124 |
< |
* function on each entry, or null if none. Upon success, |
4125 |
< |
* further element processing is suppressed and the results of |
4126 |
< |
* any other parallel invocations of the search function are |
4127 |
< |
* ignored. |
4128 |
< |
* |
4129 |
< |
* @param searchFunction a function returning a non-null |
4130 |
< |
* result on success, else null |
4131 |
< |
* @return a non-null result from applying the given search |
4132 |
< |
* function on each entry, or null if none |
4133 |
< |
*/ |
4134 |
< |
public <U> U searchEntries(Fun<Map.Entry<K,V>, ? extends U> searchFunction) { |
4135 |
< |
return fjp.invoke(ForkJoinTasks.searchEntries |
4136 |
< |
(ConcurrentHashMap.this, searchFunction)); |
4137 |
< |
} |
4122 |
> |
/** |
4123 |
> |
* Returns a non-null result from applying the given search |
4124 |
> |
* function on each entry, or null if none. Upon success, |
4125 |
> |
* further element processing is suppressed and the results of |
4126 |
> |
* any other parallel invocations of the search function are |
4127 |
> |
* ignored. |
4128 |
> |
* |
4129 |
> |
* @param searchFunction a function returning a non-null |
4130 |
> |
* result on success, else null |
4131 |
> |
* @return a non-null result from applying the given search |
4132 |
> |
* function on each entry, or null if none |
4133 |
> |
*/ |
4134 |
> |
public <U> U searchEntries(Fun<Map.Entry<K,V>, ? extends U> searchFunction) { |
4135 |
> |
return ForkJoinTasks.searchEntries |
4136 |
> |
(this, searchFunction).invoke(); |
4137 |
> |
} |
4138 |
|
|
4139 |
< |
/** |
4140 |
< |
* Returns the result of accumulating all entries using the |
4141 |
< |
* given reducer to combine values, or null if none. |
4142 |
< |
* |
4143 |
< |
* @param reducer a commutative associative combining function |
4144 |
< |
* @return the result of accumulating all entries |
4145 |
< |
*/ |
4146 |
< |
public Map.Entry<K,V> reduceEntries(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
4147 |
< |
return fjp.invoke(ForkJoinTasks.reduceEntries |
4148 |
< |
(ConcurrentHashMap.this, reducer)); |
4149 |
< |
} |
4139 |
> |
/** |
4140 |
> |
* Returns the result of accumulating all entries using the |
4141 |
> |
* given reducer to combine values, or null if none. |
4142 |
> |
* |
4143 |
> |
* @param reducer a commutative associative combining function |
4144 |
> |
* @return the result of accumulating all entries |
4145 |
> |
*/ |
4146 |
> |
public Map.Entry<K,V> reduceEntries(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
4147 |
> |
return ForkJoinTasks.reduceEntries |
4148 |
> |
(this, reducer).invoke(); |
4149 |
> |
} |
4150 |
|
|
4151 |
< |
/** |
4152 |
< |
* Returns the result of accumulating the given transformation |
4153 |
< |
* of all entries using the given reducer to combine values, |
4154 |
< |
* or null if none. |
4155 |
< |
* |
4156 |
< |
* @param transformer a function returning the transformation |
4157 |
< |
* for an element, or null if there is no transformation (in |
4158 |
< |
* which case it is not combined). |
4159 |
< |
* @param reducer a commutative associative combining function |
4160 |
< |
* @return the result of accumulating the given transformation |
4161 |
< |
* of all entries |
4162 |
< |
*/ |
4163 |
< |
public <U> U reduceEntries(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4164 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4165 |
< |
return fjp.invoke(ForkJoinTasks.reduceEntries |
4166 |
< |
(ConcurrentHashMap.this, transformer, reducer)); |
4167 |
< |
} |
4151 |
> |
/** |
4152 |
> |
* Returns the result of accumulating the given transformation |
4153 |
> |
* of all entries using the given reducer to combine values, |
4154 |
> |
* or null if none. |
4155 |
> |
* |
4156 |
> |
* @param transformer a function returning the transformation |
4157 |
> |
* for an element, or null of there is no transformation (in |
4158 |
> |
* which case it is not combined). |
4159 |
> |
* @param reducer a commutative associative combining function |
4160 |
> |
* @return the result of accumulating the given transformation |
4161 |
> |
* of all entries |
4162 |
> |
*/ |
4163 |
> |
public <U> U reduceEntries(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4164 |
> |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4165 |
> |
return ForkJoinTasks.reduceEntries |
4166 |
> |
(this, transformer, reducer).invoke(); |
4167 |
> |
} |
4168 |
|
|
4169 |
< |
/** |
4170 |
< |
* Returns the result of accumulating the given transformation |
4171 |
< |
* of all entries using the given reducer to combine values, |
4172 |
< |
* and the given basis as an identity value. |
4173 |
< |
* |
4174 |
< |
* @param transformer a function returning the transformation |
4175 |
< |
* for an element |
4176 |
< |
* @param basis the identity (initial default value) for the reduction |
4177 |
< |
* @param reducer a commutative associative combining function |
4178 |
< |
* @return the result of accumulating the given transformation |
4179 |
< |
* of all entries |
4180 |
< |
*/ |
4181 |
< |
public double reduceEntriesToDouble(ObjectToDouble<Map.Entry<K,V>> transformer, |
4182 |
< |
double basis, |
4183 |
< |
DoubleByDoubleToDouble reducer) { |
4184 |
< |
return fjp.invoke(ForkJoinTasks.reduceEntriesToDouble |
4185 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
4186 |
< |
} |
4169 |
> |
/** |
4170 |
> |
* Returns the result of accumulating the given transformation |
4171 |
> |
* of all entries using the given reducer to combine values, |
4172 |
> |
* and the given basis as an identity value. |
4173 |
> |
* |
4174 |
> |
* @param transformer a function returning the transformation |
4175 |
> |
* for an element |
4176 |
> |
* @param basis the identity (initial default value) for the reduction |
4177 |
> |
* @param reducer a commutative associative combining function |
4178 |
> |
* @return the result of accumulating the given transformation |
4179 |
> |
* of all entries |
4180 |
> |
*/ |
4181 |
> |
public double reduceEntriesToDouble(ObjectToDouble<Map.Entry<K,V>> transformer, |
4182 |
> |
double basis, |
4183 |
> |
DoubleByDoubleToDouble reducer) { |
4184 |
> |
return ForkJoinTasks.reduceEntriesToDouble |
4185 |
> |
(this, transformer, basis, reducer).invoke(); |
4186 |
> |
} |
4187 |
|
|
4188 |
< |
/** |
4189 |
< |
* Returns the result of accumulating the given transformation |
4190 |
< |
* of all entries using the given reducer to combine values, |
4191 |
< |
* and the given basis as an identity value. |
4192 |
< |
* |
4193 |
< |
* @param transformer a function returning the transformation |
4194 |
< |
* for an element |
4195 |
< |
* @param basis the identity (initial default value) for the reduction |
4196 |
< |
* @param reducer a commutative associative combining function |
4197 |
< |
* @return the result of accumulating the given transformation |
4198 |
< |
* of all entries |
4199 |
< |
*/ |
4200 |
< |
public long reduceEntriesToLong(ObjectToLong<Map.Entry<K,V>> transformer, |
4201 |
< |
long basis, |
4202 |
< |
LongByLongToLong reducer) { |
4203 |
< |
return fjp.invoke(ForkJoinTasks.reduceEntriesToLong |
4204 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
4205 |
< |
} |
4188 |
> |
/** |
4189 |
> |
* Returns the result of accumulating the given transformation |
4190 |
> |
* of all entries using the given reducer to combine values, |
4191 |
> |
* and the given basis as an identity value. |
4192 |
> |
* |
4193 |
> |
* @param transformer a function returning the transformation |
4194 |
> |
* for an element |
4195 |
> |
* @param basis the identity (initial default value) for the reduction |
4196 |
> |
* @param reducer a commutative associative combining function |
4197 |
> |
* @return the result of accumulating the given transformation |
4198 |
> |
* of all entries |
4199 |
> |
*/ |
4200 |
> |
public long reduceEntriesToLong(ObjectToLong<Map.Entry<K,V>> transformer, |
4201 |
> |
long basis, |
4202 |
> |
LongByLongToLong reducer) { |
4203 |
> |
return ForkJoinTasks.reduceEntriesToLong |
4204 |
> |
(this, transformer, basis, reducer).invoke(); |
4205 |
> |
} |
4206 |
|
|
4207 |
< |
/** |
4208 |
< |
* Returns the result of accumulating the given transformation |
4209 |
< |
* of all entries using the given reducer to combine values, |
4210 |
< |
* and the given basis as an identity value. |
4211 |
< |
* |
4212 |
< |
* @param transformer a function returning the transformation |
4213 |
< |
* for an element |
4214 |
< |
* @param basis the identity (initial default value) for the reduction |
4215 |
< |
* @param reducer a commutative associative combining function |
4216 |
< |
* @return the result of accumulating the given transformation |
4217 |
< |
* of all entries |
4218 |
< |
*/ |
4219 |
< |
public int reduceEntriesToInt(ObjectToInt<Map.Entry<K,V>> transformer, |
4220 |
< |
int basis, |
4221 |
< |
IntByIntToInt reducer) { |
4222 |
< |
return fjp.invoke(ForkJoinTasks.reduceEntriesToInt |
4223 |
< |
(ConcurrentHashMap.this, transformer, basis, reducer)); |
4160 |
< |
} |
4207 |
> |
/** |
4208 |
> |
* Returns the result of accumulating the given transformation |
4209 |
> |
* of all entries using the given reducer to combine values, |
4210 |
> |
* and the given basis as an identity value. |
4211 |
> |
* |
4212 |
> |
* @param transformer a function returning the transformation |
4213 |
> |
* for an element |
4214 |
> |
* @param basis the identity (initial default value) for the reduction |
4215 |
> |
* @param reducer a commutative associative combining function |
4216 |
> |
* @return the result of accumulating the given transformation |
4217 |
> |
* of all entries |
4218 |
> |
*/ |
4219 |
> |
public int reduceEntriesToInt(ObjectToInt<Map.Entry<K,V>> transformer, |
4220 |
> |
int basis, |
4221 |
> |
IntByIntToInt reducer) { |
4222 |
> |
return ForkJoinTasks.reduceEntriesToInt |
4223 |
> |
(this, transformer, basis, reducer).invoke(); |
4224 |
|
} |
4225 |
|
|
4226 |
|
// --------------------------------------------------------------------- |
4228 |
|
/** |
4229 |
|
* Predefined tasks for performing bulk parallel operations on |
4230 |
|
* ConcurrentHashMaps. These tasks follow the forms and rules used |
4231 |
< |
* in class {@link Parallel}. Each method has the same name, but |
4232 |
< |
* returns a task rather than invoking it. These methods may be |
4233 |
< |
* useful in custom applications such as submitting a task without |
4234 |
< |
* waiting for completion, or combining with other tasks. |
4231 |
> |
* for bulk operations. Each method has the same name, but returns |
4232 |
> |
* a task rather than invoking it. These methods may be useful in |
4233 |
> |
* custom applications such as submitting a task without waiting |
4234 |
> |
* for completion, using a custom pool, or combining with other |
4235 |
> |
* tasks. |
4236 |
|
*/ |
4237 |
|
public static class ForkJoinTasks { |
4238 |
|
private ForkJoinTasks() {} |
4249 |
|
(ConcurrentHashMap<K,V> map, |
4250 |
|
BiAction<K,V> action) { |
4251 |
|
if (action == null) throw new NullPointerException(); |
4252 |
< |
return new ForEachMappingTask<K,V>(map, null, -1, action); |
4252 |
> |
return new ForEachMappingTask<K,V>(map, null, -1, null, action); |
4253 |
|
} |
4254 |
|
|
4255 |
|
/** |
4270 |
|
if (transformer == null || action == null) |
4271 |
|
throw new NullPointerException(); |
4272 |
|
return new ForEachTransformedMappingTask<K,V,U> |
4273 |
< |
(map, null, -1, transformer, action); |
4273 |
> |
(map, null, -1, null, transformer, action); |
4274 |
|
} |
4275 |
|
|
4276 |
|
/** |
4290 |
|
BiFun<? super K, ? super V, ? extends U> searchFunction) { |
4291 |
|
if (searchFunction == null) throw new NullPointerException(); |
4292 |
|
return new SearchMappingsTask<K,V,U> |
4293 |
< |
(map, null, -1, searchFunction, |
4293 |
> |
(map, null, -1, null, searchFunction, |
4294 |
|
new AtomicReference<U>()); |
4295 |
|
} |
4296 |
|
|
4399 |
|
(ConcurrentHashMap<K,V> map, |
4400 |
|
Action<K> action) { |
4401 |
|
if (action == null) throw new NullPointerException(); |
4402 |
< |
return new ForEachKeyTask<K,V>(map, null, -1, action); |
4402 |
> |
return new ForEachKeyTask<K,V>(map, null, -1, null, action); |
4403 |
|
} |
4404 |
|
|
4405 |
|
/** |
4420 |
|
if (transformer == null || action == null) |
4421 |
|
throw new NullPointerException(); |
4422 |
|
return new ForEachTransformedKeyTask<K,V,U> |
4423 |
< |
(map, null, -1, transformer, action); |
4423 |
> |
(map, null, -1, null, transformer, action); |
4424 |
|
} |
4425 |
|
|
4426 |
|
/** |
4440 |
|
Fun<? super K, ? extends U> searchFunction) { |
4441 |
|
if (searchFunction == null) throw new NullPointerException(); |
4442 |
|
return new SearchKeysTask<K,V,U> |
4443 |
< |
(map, null, -1, searchFunction, |
4443 |
> |
(map, null, -1, null, searchFunction, |
4444 |
|
new AtomicReference<U>()); |
4445 |
|
} |
4446 |
|
|
4566 |
|
(ConcurrentHashMap<K,V> map, |
4567 |
|
Action<V> action) { |
4568 |
|
if (action == null) throw new NullPointerException(); |
4569 |
< |
return new ForEachValueTask<K,V>(map, null, -1, action); |
4569 |
> |
return new ForEachValueTask<K,V>(map, null, -1, null, action); |
4570 |
|
} |
4571 |
|
|
4572 |
|
/** |
4586 |
|
if (transformer == null || action == null) |
4587 |
|
throw new NullPointerException(); |
4588 |
|
return new ForEachTransformedValueTask<K,V,U> |
4589 |
< |
(map, null, -1, transformer, action); |
4589 |
> |
(map, null, -1, null, transformer, action); |
4590 |
|
} |
4591 |
|
|
4592 |
|
/** |
4606 |
|
Fun<? super V, ? extends U> searchFunction) { |
4607 |
|
if (searchFunction == null) throw new NullPointerException(); |
4608 |
|
return new SearchValuesTask<K,V,U> |
4609 |
< |
(map, null, -1, searchFunction, |
4609 |
> |
(map, null, -1, null, searchFunction, |
4610 |
|
new AtomicReference<U>()); |
4611 |
|
} |
4612 |
|
|
4732 |
|
(ConcurrentHashMap<K,V> map, |
4733 |
|
Action<Map.Entry<K,V>> action) { |
4734 |
|
if (action == null) throw new NullPointerException(); |
4735 |
< |
return new ForEachEntryTask<K,V>(map, null, -1, action); |
4735 |
> |
return new ForEachEntryTask<K,V>(map, null, -1, null, action); |
4736 |
|
} |
4737 |
|
|
4738 |
|
/** |
4752 |
|
if (transformer == null || action == null) |
4753 |
|
throw new NullPointerException(); |
4754 |
|
return new ForEachTransformedEntryTask<K,V,U> |
4755 |
< |
(map, null, -1, transformer, action); |
4755 |
> |
(map, null, -1, null, transformer, action); |
4756 |
|
} |
4757 |
|
|
4758 |
|
/** |
4772 |
|
Fun<Map.Entry<K,V>, ? extends U> searchFunction) { |
4773 |
|
if (searchFunction == null) throw new NullPointerException(); |
4774 |
|
return new SearchEntriesTask<K,V,U> |
4775 |
< |
(map, null, -1, searchFunction, |
4775 |
> |
(map, null, -1, null, searchFunction, |
4776 |
|
new AtomicReference<U>()); |
4777 |
|
} |
4778 |
|
|
4985 |
|
* dividing by two anyway. |
4986 |
|
*/ |
4987 |
|
final int batch() { |
4988 |
< |
ConcurrentHashMap<K, V> m; int b; Node[] t; |
4988 |
> |
ConcurrentHashMap<K, V> m; int b; Node[] t; ForkJoinPool pool; |
4989 |
|
if ((b = batch) < 0 && (m = map) != null) { // force initialization |
4990 |
|
if ((t = tab) == null && (t = tab = m.table) != null) |
4991 |
|
baseLimit = baseSize = t.length; |
4992 |
|
if (t != null) { |
4993 |
|
long n = m.counter.sum(); |
4994 |
< |
int sp = getPool().getParallelism() << 3; // slack of 8 |
4994 |
> |
int par = (pool = getPool()) == null? |
4995 |
> |
ForkJoinPool.getCommonPoolParallelism() : |
4996 |
> |
pool.getParallelism(); |
4997 |
> |
int sp = par << 3; // slack of 8 |
4998 |
|
b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp; |
4999 |
|
} |
5000 |
|
} |
5031 |
|
@SuppressWarnings("serial") static final class ForEachKeyTask<K,V> |
5032 |
|
extends BulkTask<K,V,Void> { |
5033 |
|
final Action<K> action; |
5034 |
+ |
ForEachKeyTask<K,V> nextRight; |
5035 |
|
ForEachKeyTask |
5036 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5037 |
+ |
ForEachKeyTask<K,V> nextRight, |
5038 |
|
Action<K> action) { |
5039 |
|
super(m, p, b); |
5040 |
+ |
this.nextRight = nextRight; |
5041 |
|
this.action = action; |
5042 |
|
} |
5043 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5044 |
|
final Action<K> action = this.action; |
5045 |
|
if (action == null) |
5046 |
|
return abortOnNullFunction(); |
5047 |
+ |
ForEachKeyTask<K,V> rights = null; |
5048 |
|
try { |
5049 |
|
int b = batch(), c; |
5050 |
|
while (b > 1 && baseIndex != baseLimit) { |
5051 |
|
do {} while (!casPending(c = pending, c+1)); |
5052 |
< |
new ForEachKeyTask<K,V>(map, this, b >>>= 1, action).fork(); |
5052 |
> |
(rights = new ForEachKeyTask<K,V> |
5053 |
> |
(map, this, b >>>= 1, rights, action)).fork(); |
5054 |
|
} |
5055 |
|
while (advance() != null) |
5056 |
|
action.apply((K)nextKey); |
5058 |
|
} catch (Throwable ex) { |
5059 |
|
return tryCompleteComputation(ex); |
5060 |
|
} |
5061 |
+ |
while (rights != null && rights.tryUnfork()) { |
5062 |
+ |
rights.exec(); |
5063 |
+ |
rights = rights.nextRight; |
5064 |
+ |
} |
5065 |
|
return false; |
5066 |
|
} |
5067 |
|
} |
5068 |
|
|
5069 |
|
@SuppressWarnings("serial") static final class ForEachValueTask<K,V> |
5070 |
|
extends BulkTask<K,V,Void> { |
5071 |
+ |
ForEachValueTask<K,V> nextRight; |
5072 |
|
final Action<V> action; |
5073 |
|
ForEachValueTask |
5074 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5075 |
+ |
ForEachValueTask<K,V> nextRight, |
5076 |
|
Action<V> action) { |
5077 |
|
super(m, p, b); |
5078 |
+ |
this.nextRight = nextRight; |
5079 |
|
this.action = action; |
5080 |
|
} |
5081 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5082 |
|
final Action<V> action = this.action; |
5083 |
|
if (action == null) |
5084 |
|
return abortOnNullFunction(); |
5085 |
+ |
ForEachValueTask<K,V> rights = null; |
5086 |
|
try { |
5087 |
|
int b = batch(), c; |
5088 |
|
while (b > 1 && baseIndex != baseLimit) { |
5089 |
|
do {} while (!casPending(c = pending, c+1)); |
5090 |
< |
new ForEachValueTask<K,V>(map, this, b >>>= 1, action).fork(); |
5090 |
> |
(rights = new ForEachValueTask<K,V> |
5091 |
> |
(map, this, b >>>= 1, rights, action)).fork(); |
5092 |
|
} |
5093 |
|
Object v; |
5094 |
|
while ((v = advance()) != null) |
5097 |
|
} catch (Throwable ex) { |
5098 |
|
return tryCompleteComputation(ex); |
5099 |
|
} |
5100 |
+ |
while (rights != null && rights.tryUnfork()) { |
5101 |
+ |
rights.exec(); |
5102 |
+ |
rights = rights.nextRight; |
5103 |
+ |
} |
5104 |
|
return false; |
5105 |
|
} |
5106 |
|
} |
5107 |
|
|
5108 |
|
@SuppressWarnings("serial") static final class ForEachEntryTask<K,V> |
5109 |
|
extends BulkTask<K,V,Void> { |
5110 |
+ |
ForEachEntryTask<K,V> nextRight; |
5111 |
|
final Action<Entry<K,V>> action; |
5112 |
|
ForEachEntryTask |
5113 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5114 |
+ |
ForEachEntryTask<K,V> nextRight, |
5115 |
|
Action<Entry<K,V>> action) { |
5116 |
|
super(m, p, b); |
5117 |
+ |
this.nextRight = nextRight; |
5118 |
|
this.action = action; |
5119 |
|
} |
5120 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5121 |
|
final Action<Entry<K,V>> action = this.action; |
5122 |
|
if (action == null) |
5123 |
|
return abortOnNullFunction(); |
5124 |
+ |
ForEachEntryTask<K,V> rights = null; |
5125 |
|
try { |
5126 |
|
int b = batch(), c; |
5127 |
|
while (b > 1 && baseIndex != baseLimit) { |
5128 |
|
do {} while (!casPending(c = pending, c+1)); |
5129 |
< |
new ForEachEntryTask<K,V>(map, this, b >>>= 1, action).fork(); |
5129 |
> |
(rights = new ForEachEntryTask<K,V> |
5130 |
> |
(map, this, b >>>= 1, rights, action)).fork(); |
5131 |
|
} |
5132 |
|
Object v; |
5133 |
|
while ((v = advance()) != null) |
5136 |
|
} catch (Throwable ex) { |
5137 |
|
return tryCompleteComputation(ex); |
5138 |
|
} |
5139 |
+ |
while (rights != null && rights.tryUnfork()) { |
5140 |
+ |
rights.exec(); |
5141 |
+ |
rights = rights.nextRight; |
5142 |
+ |
} |
5143 |
|
return false; |
5144 |
|
} |
5145 |
|
} |
5146 |
|
|
5147 |
|
@SuppressWarnings("serial") static final class ForEachMappingTask<K,V> |
5148 |
|
extends BulkTask<K,V,Void> { |
5149 |
+ |
ForEachMappingTask<K,V> nextRight; |
5150 |
|
final BiAction<K,V> action; |
5151 |
|
ForEachMappingTask |
5152 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5153 |
+ |
ForEachMappingTask<K,V> nextRight, |
5154 |
|
BiAction<K,V> action) { |
5155 |
|
super(m, p, b); |
5156 |
+ |
this.nextRight = nextRight; |
5157 |
|
this.action = action; |
5158 |
|
} |
5159 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5160 |
|
final BiAction<K,V> action = this.action; |
5161 |
|
if (action == null) |
5162 |
|
return abortOnNullFunction(); |
5163 |
+ |
ForEachMappingTask<K,V> rights = null; |
5164 |
|
try { |
5165 |
|
int b = batch(), c; |
5166 |
|
while (b > 1 && baseIndex != baseLimit) { |
5167 |
|
do {} while (!casPending(c = pending, c+1)); |
5168 |
< |
new ForEachMappingTask<K,V>(map, this, b >>>= 1, |
5169 |
< |
action).fork(); |
5168 |
> |
(rights = new ForEachMappingTask<K,V> |
5169 |
> |
(map, this, b >>>= 1, rights, action)).fork(); |
5170 |
|
} |
5171 |
|
Object v; |
5172 |
|
while ((v = advance()) != null) |
5175 |
|
} catch (Throwable ex) { |
5176 |
|
return tryCompleteComputation(ex); |
5177 |
|
} |
5178 |
+ |
while (rights != null && rights.tryUnfork()) { |
5179 |
+ |
rights.exec(); |
5180 |
+ |
rights = rights.nextRight; |
5181 |
+ |
} |
5182 |
|
return false; |
5183 |
|
} |
5184 |
|
} |
5185 |
|
|
5186 |
|
@SuppressWarnings("serial") static final class ForEachTransformedKeyTask<K,V,U> |
5187 |
|
extends BulkTask<K,V,Void> { |
5188 |
+ |
ForEachTransformedKeyTask<K,V,U> nextRight; |
5189 |
|
final Fun<? super K, ? extends U> transformer; |
5190 |
|
final Action<U> action; |
5191 |
|
ForEachTransformedKeyTask |
5192 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5193 |
+ |
ForEachTransformedKeyTask<K,V,U> nextRight, |
5194 |
|
Fun<? super K, ? extends U> transformer, |
5195 |
|
Action<U> action) { |
5196 |
|
super(m, p, b); |
5197 |
+ |
this.nextRight = nextRight; |
5198 |
|
this.transformer = transformer; |
5199 |
|
this.action = action; |
5200 |
|
|
5205 |
|
final Action<U> action = this.action; |
5206 |
|
if (transformer == null || action == null) |
5207 |
|
return abortOnNullFunction(); |
5208 |
+ |
ForEachTransformedKeyTask<K,V,U> rights = null; |
5209 |
|
try { |
5210 |
|
int b = batch(), c; |
5211 |
|
while (b > 1 && baseIndex != baseLimit) { |
5212 |
|
do {} while (!casPending(c = pending, c+1)); |
5213 |
< |
new ForEachTransformedKeyTask<K,V,U> |
5214 |
< |
(map, this, b >>>= 1, transformer, action).fork(); |
5213 |
> |
(rights = new ForEachTransformedKeyTask<K,V,U> |
5214 |
> |
(map, this, b >>>= 1, rights, transformer, action)).fork(); |
5215 |
|
} |
5216 |
|
U u; |
5217 |
|
while (advance() != null) { |
5222 |
|
} catch (Throwable ex) { |
5223 |
|
return tryCompleteComputation(ex); |
5224 |
|
} |
5225 |
+ |
while (rights != null && rights.tryUnfork()) { |
5226 |
+ |
rights.exec(); |
5227 |
+ |
rights = rights.nextRight; |
5228 |
+ |
} |
5229 |
|
return false; |
5230 |
|
} |
5231 |
|
} |
5232 |
|
|
5233 |
|
@SuppressWarnings("serial") static final class ForEachTransformedValueTask<K,V,U> |
5234 |
|
extends BulkTask<K,V,Void> { |
5235 |
+ |
ForEachTransformedValueTask<K,V,U> nextRight; |
5236 |
|
final Fun<? super V, ? extends U> transformer; |
5237 |
|
final Action<U> action; |
5238 |
|
ForEachTransformedValueTask |
5239 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5240 |
+ |
ForEachTransformedValueTask<K,V,U> nextRight, |
5241 |
|
Fun<? super V, ? extends U> transformer, |
5242 |
|
Action<U> action) { |
5243 |
|
super(m, p, b); |
5244 |
+ |
this.nextRight = nextRight; |
5245 |
|
this.transformer = transformer; |
5246 |
|
this.action = action; |
5247 |
|
|
5252 |
|
final Action<U> action = this.action; |
5253 |
|
if (transformer == null || action == null) |
5254 |
|
return abortOnNullFunction(); |
5255 |
+ |
ForEachTransformedValueTask<K,V,U> rights = null; |
5256 |
|
try { |
5257 |
|
int b = batch(), c; |
5258 |
|
while (b > 1 && baseIndex != baseLimit) { |
5259 |
|
do {} while (!casPending(c = pending, c+1)); |
5260 |
< |
new ForEachTransformedValueTask<K,V,U> |
5261 |
< |
(map, this, b >>>= 1, transformer, action).fork(); |
5260 |
> |
(rights = new ForEachTransformedValueTask<K,V,U> |
5261 |
> |
(map, this, b >>>= 1, rights, transformer, action)).fork(); |
5262 |
|
} |
5263 |
|
Object v; U u; |
5264 |
|
while ((v = advance()) != null) { |
5269 |
|
} catch (Throwable ex) { |
5270 |
|
return tryCompleteComputation(ex); |
5271 |
|
} |
5272 |
+ |
while (rights != null && rights.tryUnfork()) { |
5273 |
+ |
rights.exec(); |
5274 |
+ |
rights = rights.nextRight; |
5275 |
+ |
} |
5276 |
|
return false; |
5277 |
|
} |
5278 |
|
} |
5279 |
|
|
5280 |
|
@SuppressWarnings("serial") static final class ForEachTransformedEntryTask<K,V,U> |
5281 |
|
extends BulkTask<K,V,Void> { |
5282 |
+ |
ForEachTransformedEntryTask<K,V,U> nextRight; |
5283 |
|
final Fun<Map.Entry<K,V>, ? extends U> transformer; |
5284 |
|
final Action<U> action; |
5285 |
|
ForEachTransformedEntryTask |
5286 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5287 |
+ |
ForEachTransformedEntryTask<K,V,U> nextRight, |
5288 |
|
Fun<Map.Entry<K,V>, ? extends U> transformer, |
5289 |
|
Action<U> action) { |
5290 |
|
super(m, p, b); |
5291 |
+ |
this.nextRight = nextRight; |
5292 |
|
this.transformer = transformer; |
5293 |
|
this.action = action; |
5294 |
|
|
5299 |
|
final Action<U> action = this.action; |
5300 |
|
if (transformer == null || action == null) |
5301 |
|
return abortOnNullFunction(); |
5302 |
+ |
ForEachTransformedEntryTask<K,V,U> rights = null; |
5303 |
|
try { |
5304 |
|
int b = batch(), c; |
5305 |
|
while (b > 1 && baseIndex != baseLimit) { |
5306 |
|
do {} while (!casPending(c = pending, c+1)); |
5307 |
< |
new ForEachTransformedEntryTask<K,V,U> |
5308 |
< |
(map, this, b >>>= 1, transformer, action).fork(); |
5307 |
> |
(rights = new ForEachTransformedEntryTask<K,V,U> |
5308 |
> |
(map, this, b >>>= 1, rights, transformer, action)).fork(); |
5309 |
|
} |
5310 |
|
Object v; U u; |
5311 |
|
while ((v = advance()) != null) { |
5316 |
|
} catch (Throwable ex) { |
5317 |
|
return tryCompleteComputation(ex); |
5318 |
|
} |
5319 |
+ |
while (rights != null && rights.tryUnfork()) { |
5320 |
+ |
rights.exec(); |
5321 |
+ |
rights = rights.nextRight; |
5322 |
+ |
} |
5323 |
|
return false; |
5324 |
|
} |
5325 |
|
} |
5326 |
|
|
5327 |
|
@SuppressWarnings("serial") static final class ForEachTransformedMappingTask<K,V,U> |
5328 |
|
extends BulkTask<K,V,Void> { |
5329 |
+ |
ForEachTransformedMappingTask<K,V,U> nextRight; |
5330 |
|
final BiFun<? super K, ? super V, ? extends U> transformer; |
5331 |
|
final Action<U> action; |
5332 |
|
ForEachTransformedMappingTask |
5333 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5334 |
+ |
ForEachTransformedMappingTask<K,V,U> nextRight, |
5335 |
|
BiFun<? super K, ? super V, ? extends U> transformer, |
5336 |
|
Action<U> action) { |
5337 |
|
super(m, p, b); |
5338 |
+ |
this.nextRight = nextRight; |
5339 |
|
this.transformer = transformer; |
5340 |
|
this.action = action; |
5341 |
|
|
5346 |
|
final Action<U> action = this.action; |
5347 |
|
if (transformer == null || action == null) |
5348 |
|
return abortOnNullFunction(); |
5349 |
+ |
ForEachTransformedMappingTask<K,V,U> rights = null; |
5350 |
|
try { |
5351 |
|
int b = batch(), c; |
5352 |
|
while (b > 1 && baseIndex != baseLimit) { |
5353 |
|
do {} while (!casPending(c = pending, c+1)); |
5354 |
< |
new ForEachTransformedMappingTask<K,V,U> |
5355 |
< |
(map, this, b >>>= 1, transformer, action).fork(); |
5354 |
> |
(rights = new ForEachTransformedMappingTask<K,V,U> |
5355 |
> |
(map, this, b >>>= 1, rights, transformer, action)).fork(); |
5356 |
|
} |
5357 |
|
Object v; U u; |
5358 |
|
while ((v = advance()) != null) { |
5363 |
|
} catch (Throwable ex) { |
5364 |
|
return tryCompleteComputation(ex); |
5365 |
|
} |
5366 |
+ |
while (rights != null && rights.tryUnfork()) { |
5367 |
+ |
rights.exec(); |
5368 |
+ |
rights = rights.nextRight; |
5369 |
+ |
} |
5370 |
|
return false; |
5371 |
|
} |
5372 |
|
} |
5373 |
|
|
5374 |
|
@SuppressWarnings("serial") static final class SearchKeysTask<K,V,U> |
5375 |
|
extends BulkTask<K,V,U> { |
5376 |
+ |
SearchKeysTask<K,V,U> nextRight; |
5377 |
|
final Fun<? super K, ? extends U> searchFunction; |
5378 |
|
final AtomicReference<U> result; |
5379 |
|
SearchKeysTask |
5380 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5381 |
+ |
SearchKeysTask<K,V,U> nextRight, |
5382 |
|
Fun<? super K, ? extends U> searchFunction, |
5383 |
|
AtomicReference<U> result) { |
5384 |
|
super(m, p, b); |
5385 |
+ |
this.nextRight = nextRight; |
5386 |
|
this.searchFunction = searchFunction; this.result = result; |
5387 |
|
} |
5388 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5391 |
|
this.searchFunction; |
5392 |
|
if (searchFunction == null || result == null) |
5393 |
|
return abortOnNullFunction(); |
5394 |
+ |
SearchKeysTask<K,V,U> rights = null; |
5395 |
|
try { |
5396 |
|
int b = batch(), c; |
5397 |
|
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5398 |
|
do {} while (!casPending(c = pending, c+1)); |
5399 |
< |
new SearchKeysTask<K,V,U>(map, this, b >>>= 1, |
5400 |
< |
searchFunction, result).fork(); |
5399 |
> |
(rights = new SearchKeysTask<K,V,U> |
5400 |
> |
(map, this, b >>>= 1, rights, searchFunction, result)).fork(); |
5401 |
|
} |
5402 |
|
U u; |
5403 |
|
while (result.get() == null && advance() != null) { |
5411 |
|
} catch (Throwable ex) { |
5412 |
|
return tryCompleteComputation(ex); |
5413 |
|
} |
5414 |
+ |
while (rights != null && result.get() == null && rights.tryUnfork()) { |
5415 |
+ |
rights.exec(); |
5416 |
+ |
rights = rights.nextRight; |
5417 |
+ |
} |
5418 |
|
return false; |
5419 |
|
} |
5420 |
|
public final U getRawResult() { return result.get(); } |
5422 |
|
|
5423 |
|
@SuppressWarnings("serial") static final class SearchValuesTask<K,V,U> |
5424 |
|
extends BulkTask<K,V,U> { |
5425 |
+ |
SearchValuesTask<K,V,U> nextRight; |
5426 |
|
final Fun<? super V, ? extends U> searchFunction; |
5427 |
|
final AtomicReference<U> result; |
5428 |
|
SearchValuesTask |
5429 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5430 |
+ |
SearchValuesTask<K,V,U> nextRight, |
5431 |
|
Fun<? super V, ? extends U> searchFunction, |
5432 |
|
AtomicReference<U> result) { |
5433 |
|
super(m, p, b); |
5434 |
+ |
this.nextRight = nextRight; |
5435 |
|
this.searchFunction = searchFunction; this.result = result; |
5436 |
|
} |
5437 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5440 |
|
this.searchFunction; |
5441 |
|
if (searchFunction == null || result == null) |
5442 |
|
return abortOnNullFunction(); |
5443 |
+ |
SearchValuesTask<K,V,U> rights = null; |
5444 |
|
try { |
5445 |
|
int b = batch(), c; |
5446 |
|
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5447 |
|
do {} while (!casPending(c = pending, c+1)); |
5448 |
< |
new SearchValuesTask<K,V,U>(map, this, b >>>= 1, |
5449 |
< |
searchFunction, result).fork(); |
5448 |
> |
(rights = new SearchValuesTask<K,V,U> |
5449 |
> |
(map, this, b >>>= 1, rights, searchFunction, result)).fork(); |
5450 |
|
} |
5451 |
|
Object v; U u; |
5452 |
|
while (result.get() == null && (v = advance()) != null) { |
5460 |
|
} catch (Throwable ex) { |
5461 |
|
return tryCompleteComputation(ex); |
5462 |
|
} |
5463 |
+ |
while (rights != null && result.get() == null && rights.tryUnfork()) { |
5464 |
+ |
rights.exec(); |
5465 |
+ |
rights = rights.nextRight; |
5466 |
+ |
} |
5467 |
|
return false; |
5468 |
|
} |
5469 |
|
public final U getRawResult() { return result.get(); } |
5471 |
|
|
5472 |
|
@SuppressWarnings("serial") static final class SearchEntriesTask<K,V,U> |
5473 |
|
extends BulkTask<K,V,U> { |
5474 |
+ |
SearchEntriesTask<K,V,U> nextRight; |
5475 |
|
final Fun<Entry<K,V>, ? extends U> searchFunction; |
5476 |
|
final AtomicReference<U> result; |
5477 |
|
SearchEntriesTask |
5478 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5479 |
+ |
SearchEntriesTask<K,V,U> nextRight, |
5480 |
|
Fun<Entry<K,V>, ? extends U> searchFunction, |
5481 |
|
AtomicReference<U> result) { |
5482 |
|
super(m, p, b); |
5483 |
+ |
this.nextRight = nextRight; |
5484 |
|
this.searchFunction = searchFunction; this.result = result; |
5485 |
|
} |
5486 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5489 |
|
this.searchFunction; |
5490 |
|
if (searchFunction == null || result == null) |
5491 |
|
return abortOnNullFunction(); |
5492 |
+ |
SearchEntriesTask<K,V,U> rights = null; |
5493 |
|
try { |
5494 |
|
int b = batch(), c; |
5495 |
|
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5496 |
|
do {} while (!casPending(c = pending, c+1)); |
5497 |
< |
new SearchEntriesTask<K,V,U>(map, this, b >>>= 1, |
5498 |
< |
searchFunction, result).fork(); |
5497 |
> |
(rights = new SearchEntriesTask<K,V,U> |
5498 |
> |
(map, this, b >>>= 1, rights, searchFunction, result)).fork(); |
5499 |
|
} |
5500 |
|
Object v; U u; |
5501 |
|
while (result.get() == null && (v = advance()) != null) { |
5509 |
|
} catch (Throwable ex) { |
5510 |
|
return tryCompleteComputation(ex); |
5511 |
|
} |
5512 |
+ |
while (rights != null && result.get() == null && rights.tryUnfork()) { |
5513 |
+ |
rights.exec(); |
5514 |
+ |
rights = rights.nextRight; |
5515 |
+ |
} |
5516 |
|
return false; |
5517 |
|
} |
5518 |
|
public final U getRawResult() { return result.get(); } |
5520 |
|
|
5521 |
|
@SuppressWarnings("serial") static final class SearchMappingsTask<K,V,U> |
5522 |
|
extends BulkTask<K,V,U> { |
5523 |
+ |
SearchMappingsTask<K,V,U> nextRight; |
5524 |
|
final BiFun<? super K, ? super V, ? extends U> searchFunction; |
5525 |
|
final AtomicReference<U> result; |
5526 |
|
SearchMappingsTask |
5527 |
|
(ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b, |
5528 |
+ |
SearchMappingsTask<K,V,U> nextRight, |
5529 |
|
BiFun<? super K, ? super V, ? extends U> searchFunction, |
5530 |
|
AtomicReference<U> result) { |
5531 |
|
super(m, p, b); |
5532 |
+ |
this.nextRight = nextRight; |
5533 |
|
this.searchFunction = searchFunction; this.result = result; |
5534 |
|
} |
5535 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5538 |
|
this.searchFunction; |
5539 |
|
if (searchFunction == null || result == null) |
5540 |
|
return abortOnNullFunction(); |
5541 |
+ |
SearchMappingsTask<K,V,U> rights = null; |
5542 |
|
try { |
5543 |
|
int b = batch(), c; |
5544 |
|
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5545 |
|
do {} while (!casPending(c = pending, c+1)); |
5546 |
< |
new SearchMappingsTask<K,V,U>(map, this, b >>>= 1, |
5547 |
< |
searchFunction, result).fork(); |
5546 |
> |
(rights = new SearchMappingsTask<K,V,U> |
5547 |
> |
(map, this, b >>>= 1, rights, searchFunction, result)).fork(); |
5548 |
|
} |
5549 |
|
Object v; U u; |
5550 |
|
while (result.get() == null && (v = advance()) != null) { |
5558 |
|
} catch (Throwable ex) { |
5559 |
|
return tryCompleteComputation(ex); |
5560 |
|
} |
5561 |
+ |
while (rights != null && result.get() == null && rights.tryUnfork()) { |
5562 |
+ |
rights.exec(); |
5563 |
+ |
rights = rights.nextRight; |
5564 |
+ |
} |
5565 |
|
return false; |
5566 |
|
} |
5567 |
|
public final U getRawResult() { return result.get(); } |
5616 |
|
} catch (Throwable ex) { |
5617 |
|
return tryCompleteComputation(ex); |
5618 |
|
} |
5619 |
+ |
for (ReduceKeysTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
5620 |
+ |
s.exec(); |
5621 |
|
return false; |
5622 |
|
} |
5623 |
|
public final K getRawResult() { return result; } |
5673 |
|
} catch (Throwable ex) { |
5674 |
|
return tryCompleteComputation(ex); |
5675 |
|
} |
5676 |
+ |
for (ReduceValuesTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
5677 |
+ |
s.exec(); |
5678 |
|
return false; |
5679 |
|
} |
5680 |
|
public final V getRawResult() { return result; } |
5730 |
|
} catch (Throwable ex) { |
5731 |
|
return tryCompleteComputation(ex); |
5732 |
|
} |
5733 |
+ |
for (ReduceEntriesTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
5734 |
+ |
s.exec(); |
5735 |
|
return false; |
5736 |
|
} |
5737 |
|
public final Map.Entry<K,V> getRawResult() { return result; } |
5791 |
|
} catch (Throwable ex) { |
5792 |
|
return tryCompleteComputation(ex); |
5793 |
|
} |
5794 |
+ |
for (MapReduceKeysTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
5795 |
+ |
s.exec(); |
5796 |
|
return false; |
5797 |
|
} |
5798 |
|
public final U getRawResult() { return result; } |
5853 |
|
} catch (Throwable ex) { |
5854 |
|
return tryCompleteComputation(ex); |
5855 |
|
} |
5856 |
+ |
for (MapReduceValuesTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
5857 |
+ |
s.exec(); |
5858 |
|
return false; |
5859 |
|
} |
5860 |
|
public final U getRawResult() { return result; } |
5915 |
|
} catch (Throwable ex) { |
5916 |
|
return tryCompleteComputation(ex); |
5917 |
|
} |
5918 |
+ |
for (MapReduceEntriesTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
5919 |
+ |
s.exec(); |
5920 |
|
return false; |
5921 |
|
} |
5922 |
|
public final U getRawResult() { return result; } |
5977 |
|
} catch (Throwable ex) { |
5978 |
|
return tryCompleteComputation(ex); |
5979 |
|
} |
5980 |
+ |
for (MapReduceMappingsTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
5981 |
+ |
s.exec(); |
5982 |
|
return false; |
5983 |
|
} |
5984 |
|
public final U getRawResult() { return result; } |
6037 |
|
} catch (Throwable ex) { |
6038 |
|
return tryCompleteComputation(ex); |
6039 |
|
} |
6040 |
+ |
for (MapReduceKeysToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6041 |
+ |
s.exec(); |
6042 |
|
return false; |
6043 |
|
} |
6044 |
|
public final Double getRawResult() { return result; } |
6098 |
|
} catch (Throwable ex) { |
6099 |
|
return tryCompleteComputation(ex); |
6100 |
|
} |
6101 |
+ |
for (MapReduceValuesToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6102 |
+ |
s.exec(); |
6103 |
|
return false; |
6104 |
|
} |
6105 |
|
public final Double getRawResult() { return result; } |
6159 |
|
} catch (Throwable ex) { |
6160 |
|
return tryCompleteComputation(ex); |
6161 |
|
} |
6162 |
+ |
for (MapReduceEntriesToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6163 |
+ |
s.exec(); |
6164 |
|
return false; |
6165 |
|
} |
6166 |
|
public final Double getRawResult() { return result; } |
6220 |
|
} catch (Throwable ex) { |
6221 |
|
return tryCompleteComputation(ex); |
6222 |
|
} |
6223 |
+ |
for (MapReduceMappingsToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6224 |
+ |
s.exec(); |
6225 |
|
return false; |
6226 |
|
} |
6227 |
|
public final Double getRawResult() { return result; } |
6280 |
|
} catch (Throwable ex) { |
6281 |
|
return tryCompleteComputation(ex); |
6282 |
|
} |
6283 |
+ |
for (MapReduceKeysToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6284 |
+ |
s.exec(); |
6285 |
|
return false; |
6286 |
|
} |
6287 |
|
public final Long getRawResult() { return result; } |
6341 |
|
} catch (Throwable ex) { |
6342 |
|
return tryCompleteComputation(ex); |
6343 |
|
} |
6344 |
+ |
for (MapReduceValuesToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6345 |
+ |
s.exec(); |
6346 |
|
return false; |
6347 |
|
} |
6348 |
|
public final Long getRawResult() { return result; } |
6402 |
|
} catch (Throwable ex) { |
6403 |
|
return tryCompleteComputation(ex); |
6404 |
|
} |
6405 |
+ |
for (MapReduceEntriesToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6406 |
+ |
s.exec(); |
6407 |
|
return false; |
6408 |
|
} |
6409 |
|
public final Long getRawResult() { return result; } |
6463 |
|
} catch (Throwable ex) { |
6464 |
|
return tryCompleteComputation(ex); |
6465 |
|
} |
6466 |
+ |
for (MapReduceMappingsToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6467 |
+ |
s.exec(); |
6468 |
|
return false; |
6469 |
|
} |
6470 |
|
public final Long getRawResult() { return result; } |
6523 |
|
} catch (Throwable ex) { |
6524 |
|
return tryCompleteComputation(ex); |
6525 |
|
} |
6526 |
+ |
for (MapReduceKeysToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6527 |
+ |
s.exec(); |
6528 |
|
return false; |
6529 |
|
} |
6530 |
|
public final Integer getRawResult() { return result; } |
6584 |
|
} catch (Throwable ex) { |
6585 |
|
return tryCompleteComputation(ex); |
6586 |
|
} |
6587 |
+ |
for (MapReduceValuesToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6588 |
+ |
s.exec(); |
6589 |
|
return false; |
6590 |
|
} |
6591 |
|
public final Integer getRawResult() { return result; } |
6645 |
|
} catch (Throwable ex) { |
6646 |
|
return tryCompleteComputation(ex); |
6647 |
|
} |
6648 |
+ |
for (MapReduceEntriesToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6649 |
+ |
s.exec(); |
6650 |
|
return false; |
6651 |
|
} |
6652 |
|
public final Integer getRawResult() { return result; } |
6706 |
|
} catch (Throwable ex) { |
6707 |
|
return tryCompleteComputation(ex); |
6708 |
|
} |
6709 |
+ |
for (MapReduceMappingsToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6710 |
+ |
s.exec(); |
6711 |
|
return false; |
6712 |
|
} |
6713 |
|
public final Integer getRawResult() { return result; } |
6714 |
|
} |
6715 |
|
|
6512 |
– |
|
6716 |
|
// Unsafe mechanics |
6717 |
|
private static final sun.misc.Unsafe UNSAFE; |
6718 |
|
private static final long counterOffset; |