5 |
|
*/ |
6 |
|
|
7 |
|
package jsr166e; |
8 |
< |
import jsr166e.LongAdder; |
9 |
< |
import jsr166e.ForkJoinPool; |
10 |
< |
import jsr166e.ForkJoinTask; |
8 |
> |
|
9 |
|
import java.util.Comparator; |
10 |
|
import java.util.Arrays; |
11 |
|
import java.util.Map; |
82 |
|
* {@code hashCode()} is a sure way to slow down performance of any |
83 |
|
* hash table. |
84 |
|
* |
85 |
< |
* <p> A {@link Set} projection of a ConcurrentHashMap may be created |
85 |
> |
* <p> A {@link Set} projection of a ConcurrentHashMapV8 may be created |
86 |
|
* (using {@link #newKeySet()} or {@link #newKeySet(int)}), or viewed |
87 |
|
* (using {@link #keySet(Object)} when only keys are of interest, and the |
88 |
|
* mapped values are (perhaps transiently) not used or all take the |
103 |
|
* does <em>not</em> allow {@code null} to be used as a key or value. |
104 |
|
* |
105 |
|
* <p>ConcurrentHashMapV8s support parallel operations using the {@link |
106 |
< |
* ForkJoinPool#commonPool}. (Task that may be used in other contexts |
106 |
> |
* ForkJoinPool#commonPool}. (Tasks that may be used in other contexts |
107 |
|
* are available in class {@link ForkJoinTasks}). These operations are |
108 |
|
* designed to be safely, and often sensibly, applied even with maps |
109 |
|
* that are being concurrently updated by other threads; for example, |
110 |
|
* when computing a snapshot summary of the values in a shared |
111 |
|
* registry. There are three kinds of operation, each with four |
112 |
|
* forms, accepting functions with Keys, Values, Entries, and (Key, |
113 |
< |
* Value) arguments and/or return values. Because the elements of a |
113 |
> |
* Value) arguments and/or return values. (The first three forms are |
114 |
> |
* also available via the {@link #keySet()}, {@link #values()} and |
115 |
> |
* {@link #entrySet()} views). Because the elements of a |
116 |
|
* ConcurrentHashMapV8 are not ordered in any particular way, and may be |
117 |
|
* processed in different orders in different parallel executions, the |
118 |
|
* correctness of supplied functions should not depend on any |
195 |
|
* processing are common but not guaranteed. Operations involving |
196 |
|
* brief functions on small maps may execute more slowly than |
197 |
|
* sequential loops if the underlying work to parallelize the |
198 |
< |
* computation is more expensive than the computation |
199 |
< |
* itself. Similarly, parallelization may not lead to much actual |
200 |
< |
* parallelism if all processors are busy performing unrelated tasks. |
198 |
> |
* computation is more expensive than the computation itself. |
199 |
> |
* Similarly, parallelization may not lead to much actual parallelism |
200 |
> |
* if all processors are busy performing unrelated tasks. |
201 |
|
* |
202 |
|
* <p> All arguments to all task methods must be non-null. |
203 |
|
* |
287 |
|
Spliterator<T> split(); |
288 |
|
} |
289 |
|
|
290 |
– |
/** |
291 |
– |
* A view of a ConcurrentHashMapV8 as a {@link Set} of keys, in |
292 |
– |
* which additions may optionally be enabled by mapping to a |
293 |
– |
* common value. This class cannot be directly instantiated. See |
294 |
– |
* {@link #keySet}, {@link #keySet(Object)}, {@link #newKeySet()}, |
295 |
– |
* {@link #newKeySet(int)}. |
296 |
– |
* |
297 |
– |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
298 |
– |
* that will never throw {@link ConcurrentModificationException}, |
299 |
– |
* and guarantees to traverse elements as they existed upon |
300 |
– |
* construction of the iterator, and may (but is not guaranteed to) |
301 |
– |
* reflect any modifications subsequent to construction. |
302 |
– |
*/ |
303 |
– |
public static class KeySetView<K,V> extends CHMView<K,V> implements Set<K>, java.io.Serializable { |
304 |
– |
private static final long serialVersionUID = 7249069246763182397L; |
305 |
– |
private final V value; |
306 |
– |
KeySetView(ConcurrentHashMapV8<K, V> map, V value) { // non-public |
307 |
– |
super(map); |
308 |
– |
this.value = value; |
309 |
– |
} |
310 |
– |
|
311 |
– |
/** |
312 |
– |
* Returns the map backing this view. |
313 |
– |
* |
314 |
– |
* @return the map backing this view |
315 |
– |
*/ |
316 |
– |
public ConcurrentHashMapV8<K,V> getMap() { return map; } |
317 |
– |
|
318 |
– |
/** |
319 |
– |
* Returns the default mapped value for additions, |
320 |
– |
* or {@code null} if additions are not supported. |
321 |
– |
* |
322 |
– |
* @return the default mapped value for additions, or {@code null} |
323 |
– |
* if not supported. |
324 |
– |
*/ |
325 |
– |
public V getMappedValue() { return value; } |
326 |
– |
|
327 |
– |
// implement Set API |
328 |
– |
|
329 |
– |
public boolean contains(Object o) { return map.containsKey(o); } |
330 |
– |
public boolean remove(Object o) { return map.remove(o) != null; } |
331 |
– |
public Iterator<K> iterator() { return new KeyIterator<K,V>(map); } |
332 |
– |
public boolean add(K e) { |
333 |
– |
V v; |
334 |
– |
if ((v = value) == null) |
335 |
– |
throw new UnsupportedOperationException(); |
336 |
– |
if (e == null) |
337 |
– |
throw new NullPointerException(); |
338 |
– |
return map.internalPutIfAbsent(e, v) == null; |
339 |
– |
} |
340 |
– |
public boolean addAll(Collection<? extends K> c) { |
341 |
– |
boolean added = false; |
342 |
– |
V v; |
343 |
– |
if ((v = value) == null) |
344 |
– |
throw new UnsupportedOperationException(); |
345 |
– |
for (K e : c) { |
346 |
– |
if (e == null) |
347 |
– |
throw new NullPointerException(); |
348 |
– |
if (map.internalPutIfAbsent(e, v) == null) |
349 |
– |
added = true; |
350 |
– |
} |
351 |
– |
return added; |
352 |
– |
} |
353 |
– |
public boolean equals(Object o) { |
354 |
– |
Set<?> c; |
355 |
– |
return ((o instanceof Set) && |
356 |
– |
((c = (Set<?>)o) == this || |
357 |
– |
(containsAll(c) && c.containsAll(this)))); |
358 |
– |
} |
359 |
– |
} |
290 |
|
|
291 |
|
/* |
292 |
|
* Overview: |
571 |
|
|
572 |
|
// views |
573 |
|
private transient KeySetView<K,V> keySet; |
574 |
< |
private transient Values<K,V> values; |
575 |
< |
private transient EntrySet<K,V> entrySet; |
574 |
> |
private transient ValuesView<K,V> values; |
575 |
> |
private transient EntrySetView<K,V> entrySet; |
576 |
|
|
577 |
|
/** For serialization compatibility. Null unless serialized; see below */ |
578 |
|
private Segment<K,V>[] segments; |
3010 |
|
/** |
3011 |
|
* Returns a {@link Collection} view of the values contained in this map. |
3012 |
|
* The collection is backed by the map, so changes to the map are |
3013 |
< |
* reflected in the collection, and vice-versa. The collection |
3084 |
< |
* supports element removal, which removes the corresponding |
3085 |
< |
* mapping from this map, via the {@code Iterator.remove}, |
3086 |
< |
* {@code Collection.remove}, {@code removeAll}, |
3087 |
< |
* {@code retainAll}, and {@code clear} operations. It does not |
3088 |
< |
* support the {@code add} or {@code addAll} operations. |
3089 |
< |
* |
3090 |
< |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
3091 |
< |
* that will never throw {@link ConcurrentModificationException}, |
3092 |
< |
* and guarantees to traverse elements as they existed upon |
3093 |
< |
* construction of the iterator, and may (but is not guaranteed to) |
3094 |
< |
* reflect any modifications subsequent to construction. |
3013 |
> |
* reflected in the collection, and vice-versa. |
3014 |
|
*/ |
3015 |
< |
public Collection<V> values() { |
3016 |
< |
Values<K,V> vs = values; |
3017 |
< |
return (vs != null) ? vs : (values = new Values<K,V>(this)); |
3015 |
> |
public ValuesView<K,V> values() { |
3016 |
> |
ValuesView<K,V> vs = values; |
3017 |
> |
return (vs != null) ? vs : (values = new ValuesView<K,V>(this)); |
3018 |
|
} |
3019 |
|
|
3020 |
|
/** |
3034 |
|
* reflect any modifications subsequent to construction. |
3035 |
|
*/ |
3036 |
|
public Set<Map.Entry<K,V>> entrySet() { |
3037 |
< |
EntrySet<K,V> es = entrySet; |
3038 |
< |
return (es != null) ? es : (entrySet = new EntrySet<K,V>(this)); |
3037 |
> |
EntrySetView<K,V> es = entrySet; |
3038 |
> |
return (es != null) ? es : (entrySet = new EntrySetView<K,V>(this)); |
3039 |
|
} |
3040 |
|
|
3041 |
|
/** |
3278 |
|
} |
3279 |
|
} |
3280 |
|
|
3362 |
– |
/* ----------------Views -------------- */ |
3363 |
– |
|
3364 |
– |
/** |
3365 |
– |
* Base class for views. |
3366 |
– |
*/ |
3367 |
– |
static abstract class CHMView<K, V> { |
3368 |
– |
final ConcurrentHashMapV8<K, V> map; |
3369 |
– |
CHMView(ConcurrentHashMapV8<K, V> map) { this.map = map; } |
3370 |
– |
public final int size() { return map.size(); } |
3371 |
– |
public final boolean isEmpty() { return map.isEmpty(); } |
3372 |
– |
public final void clear() { map.clear(); } |
3373 |
– |
|
3374 |
– |
// implementations below rely on concrete classes supplying these |
3375 |
– |
abstract public Iterator<?> iterator(); |
3376 |
– |
abstract public boolean contains(Object o); |
3377 |
– |
abstract public boolean remove(Object o); |
3378 |
– |
|
3379 |
– |
private static final String oomeMsg = "Required array size too large"; |
3380 |
– |
|
3381 |
– |
public final Object[] toArray() { |
3382 |
– |
long sz = map.mappingCount(); |
3383 |
– |
if (sz > (long)(MAX_ARRAY_SIZE)) |
3384 |
– |
throw new OutOfMemoryError(oomeMsg); |
3385 |
– |
int n = (int)sz; |
3386 |
– |
Object[] r = new Object[n]; |
3387 |
– |
int i = 0; |
3388 |
– |
Iterator<?> it = iterator(); |
3389 |
– |
while (it.hasNext()) { |
3390 |
– |
if (i == n) { |
3391 |
– |
if (n >= MAX_ARRAY_SIZE) |
3392 |
– |
throw new OutOfMemoryError(oomeMsg); |
3393 |
– |
if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1) |
3394 |
– |
n = MAX_ARRAY_SIZE; |
3395 |
– |
else |
3396 |
– |
n += (n >>> 1) + 1; |
3397 |
– |
r = Arrays.copyOf(r, n); |
3398 |
– |
} |
3399 |
– |
r[i++] = it.next(); |
3400 |
– |
} |
3401 |
– |
return (i == n) ? r : Arrays.copyOf(r, i); |
3402 |
– |
} |
3403 |
– |
|
3404 |
– |
@SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) { |
3405 |
– |
long sz = map.mappingCount(); |
3406 |
– |
if (sz > (long)(MAX_ARRAY_SIZE)) |
3407 |
– |
throw new OutOfMemoryError(oomeMsg); |
3408 |
– |
int m = (int)sz; |
3409 |
– |
T[] r = (a.length >= m) ? a : |
3410 |
– |
(T[])java.lang.reflect.Array |
3411 |
– |
.newInstance(a.getClass().getComponentType(), m); |
3412 |
– |
int n = r.length; |
3413 |
– |
int i = 0; |
3414 |
– |
Iterator<?> it = iterator(); |
3415 |
– |
while (it.hasNext()) { |
3416 |
– |
if (i == n) { |
3417 |
– |
if (n >= MAX_ARRAY_SIZE) |
3418 |
– |
throw new OutOfMemoryError(oomeMsg); |
3419 |
– |
if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1) |
3420 |
– |
n = MAX_ARRAY_SIZE; |
3421 |
– |
else |
3422 |
– |
n += (n >>> 1) + 1; |
3423 |
– |
r = Arrays.copyOf(r, n); |
3424 |
– |
} |
3425 |
– |
r[i++] = (T)it.next(); |
3426 |
– |
} |
3427 |
– |
if (a == r && i < n) { |
3428 |
– |
r[i] = null; // null-terminate |
3429 |
– |
return r; |
3430 |
– |
} |
3431 |
– |
return (i == n) ? r : Arrays.copyOf(r, i); |
3432 |
– |
} |
3433 |
– |
|
3434 |
– |
public final int hashCode() { |
3435 |
– |
int h = 0; |
3436 |
– |
for (Iterator<?> it = iterator(); it.hasNext();) |
3437 |
– |
h += it.next().hashCode(); |
3438 |
– |
return h; |
3439 |
– |
} |
3440 |
– |
|
3441 |
– |
public final String toString() { |
3442 |
– |
StringBuilder sb = new StringBuilder(); |
3443 |
– |
sb.append('['); |
3444 |
– |
Iterator<?> it = iterator(); |
3445 |
– |
if (it.hasNext()) { |
3446 |
– |
for (;;) { |
3447 |
– |
Object e = it.next(); |
3448 |
– |
sb.append(e == this ? "(this Collection)" : e); |
3449 |
– |
if (!it.hasNext()) |
3450 |
– |
break; |
3451 |
– |
sb.append(',').append(' '); |
3452 |
– |
} |
3453 |
– |
} |
3454 |
– |
return sb.append(']').toString(); |
3455 |
– |
} |
3456 |
– |
|
3457 |
– |
public final boolean containsAll(Collection<?> c) { |
3458 |
– |
if (c != this) { |
3459 |
– |
for (Iterator<?> it = c.iterator(); it.hasNext();) { |
3460 |
– |
Object e = it.next(); |
3461 |
– |
if (e == null || !contains(e)) |
3462 |
– |
return false; |
3463 |
– |
} |
3464 |
– |
} |
3465 |
– |
return true; |
3466 |
– |
} |
3467 |
– |
|
3468 |
– |
public final boolean removeAll(Collection<?> c) { |
3469 |
– |
boolean modified = false; |
3470 |
– |
for (Iterator<?> it = iterator(); it.hasNext();) { |
3471 |
– |
if (c.contains(it.next())) { |
3472 |
– |
it.remove(); |
3473 |
– |
modified = true; |
3474 |
– |
} |
3475 |
– |
} |
3476 |
– |
return modified; |
3477 |
– |
} |
3478 |
– |
|
3479 |
– |
public final boolean retainAll(Collection<?> c) { |
3480 |
– |
boolean modified = false; |
3481 |
– |
for (Iterator<?> it = iterator(); it.hasNext();) { |
3482 |
– |
if (!c.contains(it.next())) { |
3483 |
– |
it.remove(); |
3484 |
– |
modified = true; |
3485 |
– |
} |
3486 |
– |
} |
3487 |
– |
return modified; |
3488 |
– |
} |
3489 |
– |
|
3490 |
– |
} |
3491 |
– |
|
3492 |
– |
static final class Values<K,V> extends CHMView<K,V> |
3493 |
– |
implements Collection<V> { |
3494 |
– |
Values(ConcurrentHashMapV8<K, V> map) { super(map); } |
3495 |
– |
public final boolean contains(Object o) { return map.containsValue(o); } |
3496 |
– |
public final boolean remove(Object o) { |
3497 |
– |
if (o != null) { |
3498 |
– |
Iterator<V> it = new ValueIterator<K,V>(map); |
3499 |
– |
while (it.hasNext()) { |
3500 |
– |
if (o.equals(it.next())) { |
3501 |
– |
it.remove(); |
3502 |
– |
return true; |
3503 |
– |
} |
3504 |
– |
} |
3505 |
– |
} |
3506 |
– |
return false; |
3507 |
– |
} |
3508 |
– |
public final Iterator<V> iterator() { |
3509 |
– |
return new ValueIterator<K,V>(map); |
3510 |
– |
} |
3511 |
– |
public final boolean add(V e) { |
3512 |
– |
throw new UnsupportedOperationException(); |
3513 |
– |
} |
3514 |
– |
public final boolean addAll(Collection<? extends V> c) { |
3515 |
– |
throw new UnsupportedOperationException(); |
3516 |
– |
} |
3517 |
– |
|
3518 |
– |
} |
3519 |
– |
|
3520 |
– |
static final class EntrySet<K,V> extends CHMView<K,V> |
3521 |
– |
implements Set<Map.Entry<K,V>> { |
3522 |
– |
EntrySet(ConcurrentHashMapV8<K, V> map) { super(map); } |
3523 |
– |
public final boolean contains(Object o) { |
3524 |
– |
Object k, v, r; Map.Entry<?,?> e; |
3525 |
– |
return ((o instanceof Map.Entry) && |
3526 |
– |
(k = (e = (Map.Entry<?,?>)o).getKey()) != null && |
3527 |
– |
(r = map.get(k)) != null && |
3528 |
– |
(v = e.getValue()) != null && |
3529 |
– |
(v == r || v.equals(r))); |
3530 |
– |
} |
3531 |
– |
public final boolean remove(Object o) { |
3532 |
– |
Object k, v; Map.Entry<?,?> e; |
3533 |
– |
return ((o instanceof Map.Entry) && |
3534 |
– |
(k = (e = (Map.Entry<?,?>)o).getKey()) != null && |
3535 |
– |
(v = e.getValue()) != null && |
3536 |
– |
map.remove(k, v)); |
3537 |
– |
} |
3538 |
– |
public final Iterator<Map.Entry<K,V>> iterator() { |
3539 |
– |
return new EntryIterator<K,V>(map); |
3540 |
– |
} |
3541 |
– |
public final boolean add(Entry<K,V> e) { |
3542 |
– |
throw new UnsupportedOperationException(); |
3543 |
– |
} |
3544 |
– |
public final boolean addAll(Collection<? extends Entry<K,V>> c) { |
3545 |
– |
throw new UnsupportedOperationException(); |
3546 |
– |
} |
3547 |
– |
public boolean equals(Object o) { |
3548 |
– |
Set<?> c; |
3549 |
– |
return ((o instanceof Set) && |
3550 |
– |
((c = (Set<?>)o) == this || |
3551 |
– |
(containsAll(c) && c.containsAll(this)))); |
3552 |
– |
} |
3553 |
– |
} |
3554 |
– |
|
3281 |
|
/* ---------------- Serialization Support -------------- */ |
3282 |
|
|
3283 |
|
/** |
3586 |
|
} |
3587 |
|
|
3588 |
|
/** |
3589 |
+ |
* Returns a non-null result from applying the given search |
3590 |
+ |
* function on each key, or null if none. Upon success, |
3591 |
+ |
* further element processing is suppressed and the results of |
3592 |
+ |
* any other parallel invocations of the search function are |
3593 |
+ |
* ignored. |
3594 |
+ |
* |
3595 |
+ |
* @param searchFunction a function returning a non-null |
3596 |
+ |
* result on success, else null |
3597 |
+ |
* @return a non-null result from applying the given search |
3598 |
+ |
* function on each key, or null if none |
3599 |
+ |
*/ |
3600 |
+ |
public <U> U searchKeys(Fun<? super K, ? extends U> searchFunction) { |
3601 |
+ |
return ForkJoinTasks.searchKeys |
3602 |
+ |
(this, searchFunction).invoke(); |
3603 |
+ |
} |
3604 |
+ |
|
3605 |
+ |
/** |
3606 |
|
* Returns the result of accumulating all keys using the given |
3607 |
|
* reducer to combine values, or null if none. |
3608 |
|
* |
3948 |
|
(this, transformer, basis, reducer).invoke(); |
3949 |
|
} |
3950 |
|
|
3951 |
+ |
/* ----------------Views -------------- */ |
3952 |
+ |
|
3953 |
+ |
/** |
3954 |
+ |
* Base class for views. |
3955 |
+ |
*/ |
3956 |
+ |
static abstract class CHMView<K, V> { |
3957 |
+ |
final ConcurrentHashMapV8<K, V> map; |
3958 |
+ |
CHMView(ConcurrentHashMapV8<K, V> map) { this.map = map; } |
3959 |
+ |
|
3960 |
+ |
/** |
3961 |
+ |
* Returns the map backing this view. |
3962 |
+ |
* |
3963 |
+ |
* @return the map backing this view |
3964 |
+ |
*/ |
3965 |
+ |
public ConcurrentHashMapV8<K,V> getMap() { return map; } |
3966 |
+ |
|
3967 |
+ |
public final int size() { return map.size(); } |
3968 |
+ |
public final boolean isEmpty() { return map.isEmpty(); } |
3969 |
+ |
public final void clear() { map.clear(); } |
3970 |
+ |
|
3971 |
+ |
// implementations below rely on concrete classes supplying these |
3972 |
+ |
abstract public Iterator<?> iterator(); |
3973 |
+ |
abstract public boolean contains(Object o); |
3974 |
+ |
abstract public boolean remove(Object o); |
3975 |
+ |
|
3976 |
+ |
private static final String oomeMsg = "Required array size too large"; |
3977 |
+ |
|
3978 |
+ |
public final Object[] toArray() { |
3979 |
+ |
long sz = map.mappingCount(); |
3980 |
+ |
if (sz > (long)(MAX_ARRAY_SIZE)) |
3981 |
+ |
throw new OutOfMemoryError(oomeMsg); |
3982 |
+ |
int n = (int)sz; |
3983 |
+ |
Object[] r = new Object[n]; |
3984 |
+ |
int i = 0; |
3985 |
+ |
Iterator<?> it = iterator(); |
3986 |
+ |
while (it.hasNext()) { |
3987 |
+ |
if (i == n) { |
3988 |
+ |
if (n >= MAX_ARRAY_SIZE) |
3989 |
+ |
throw new OutOfMemoryError(oomeMsg); |
3990 |
+ |
if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1) |
3991 |
+ |
n = MAX_ARRAY_SIZE; |
3992 |
+ |
else |
3993 |
+ |
n += (n >>> 1) + 1; |
3994 |
+ |
r = Arrays.copyOf(r, n); |
3995 |
+ |
} |
3996 |
+ |
r[i++] = it.next(); |
3997 |
+ |
} |
3998 |
+ |
return (i == n) ? r : Arrays.copyOf(r, i); |
3999 |
+ |
} |
4000 |
+ |
|
4001 |
+ |
@SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) { |
4002 |
+ |
long sz = map.mappingCount(); |
4003 |
+ |
if (sz > (long)(MAX_ARRAY_SIZE)) |
4004 |
+ |
throw new OutOfMemoryError(oomeMsg); |
4005 |
+ |
int m = (int)sz; |
4006 |
+ |
T[] r = (a.length >= m) ? a : |
4007 |
+ |
(T[])java.lang.reflect.Array |
4008 |
+ |
.newInstance(a.getClass().getComponentType(), m); |
4009 |
+ |
int n = r.length; |
4010 |
+ |
int i = 0; |
4011 |
+ |
Iterator<?> it = iterator(); |
4012 |
+ |
while (it.hasNext()) { |
4013 |
+ |
if (i == n) { |
4014 |
+ |
if (n >= MAX_ARRAY_SIZE) |
4015 |
+ |
throw new OutOfMemoryError(oomeMsg); |
4016 |
+ |
if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1) |
4017 |
+ |
n = MAX_ARRAY_SIZE; |
4018 |
+ |
else |
4019 |
+ |
n += (n >>> 1) + 1; |
4020 |
+ |
r = Arrays.copyOf(r, n); |
4021 |
+ |
} |
4022 |
+ |
r[i++] = (T)it.next(); |
4023 |
+ |
} |
4024 |
+ |
if (a == r && i < n) { |
4025 |
+ |
r[i] = null; // null-terminate |
4026 |
+ |
return r; |
4027 |
+ |
} |
4028 |
+ |
return (i == n) ? r : Arrays.copyOf(r, i); |
4029 |
+ |
} |
4030 |
+ |
|
4031 |
+ |
public final int hashCode() { |
4032 |
+ |
int h = 0; |
4033 |
+ |
for (Iterator<?> it = iterator(); it.hasNext();) |
4034 |
+ |
h += it.next().hashCode(); |
4035 |
+ |
return h; |
4036 |
+ |
} |
4037 |
+ |
|
4038 |
+ |
public final String toString() { |
4039 |
+ |
StringBuilder sb = new StringBuilder(); |
4040 |
+ |
sb.append('['); |
4041 |
+ |
Iterator<?> it = iterator(); |
4042 |
+ |
if (it.hasNext()) { |
4043 |
+ |
for (;;) { |
4044 |
+ |
Object e = it.next(); |
4045 |
+ |
sb.append(e == this ? "(this Collection)" : e); |
4046 |
+ |
if (!it.hasNext()) |
4047 |
+ |
break; |
4048 |
+ |
sb.append(',').append(' '); |
4049 |
+ |
} |
4050 |
+ |
} |
4051 |
+ |
return sb.append(']').toString(); |
4052 |
+ |
} |
4053 |
+ |
|
4054 |
+ |
public final boolean containsAll(Collection<?> c) { |
4055 |
+ |
if (c != this) { |
4056 |
+ |
for (Iterator<?> it = c.iterator(); it.hasNext();) { |
4057 |
+ |
Object e = it.next(); |
4058 |
+ |
if (e == null || !contains(e)) |
4059 |
+ |
return false; |
4060 |
+ |
} |
4061 |
+ |
} |
4062 |
+ |
return true; |
4063 |
+ |
} |
4064 |
+ |
|
4065 |
+ |
public final boolean removeAll(Collection<?> c) { |
4066 |
+ |
boolean modified = false; |
4067 |
+ |
for (Iterator<?> it = iterator(); it.hasNext();) { |
4068 |
+ |
if (c.contains(it.next())) { |
4069 |
+ |
it.remove(); |
4070 |
+ |
modified = true; |
4071 |
+ |
} |
4072 |
+ |
} |
4073 |
+ |
return modified; |
4074 |
+ |
} |
4075 |
+ |
|
4076 |
+ |
public final boolean retainAll(Collection<?> c) { |
4077 |
+ |
boolean modified = false; |
4078 |
+ |
for (Iterator<?> it = iterator(); it.hasNext();) { |
4079 |
+ |
if (!c.contains(it.next())) { |
4080 |
+ |
it.remove(); |
4081 |
+ |
modified = true; |
4082 |
+ |
} |
4083 |
+ |
} |
4084 |
+ |
return modified; |
4085 |
+ |
} |
4086 |
+ |
|
4087 |
+ |
} |
4088 |
+ |
|
4089 |
+ |
/** |
4090 |
+ |
* A view of a ConcurrentHashMapV8 as a {@link Set} of keys, in |
4091 |
+ |
* which additions may optionally be enabled by mapping to a |
4092 |
+ |
* common value. This class cannot be directly instantiated. See |
4093 |
+ |
* {@link #keySet}, {@link #keySet(Object)}, {@link #newKeySet()}, |
4094 |
+ |
* {@link #newKeySet(int)}. |
4095 |
+ |
*/ |
4096 |
+ |
public static class KeySetView<K,V> extends CHMView<K,V> implements Set<K>, java.io.Serializable { |
4097 |
+ |
private static final long serialVersionUID = 7249069246763182397L; |
4098 |
+ |
private final V value; |
4099 |
+ |
KeySetView(ConcurrentHashMapV8<K, V> map, V value) { // non-public |
4100 |
+ |
super(map); |
4101 |
+ |
this.value = value; |
4102 |
+ |
} |
4103 |
+ |
|
4104 |
+ |
/** |
4105 |
+ |
* Returns the default mapped value for additions, |
4106 |
+ |
* or {@code null} if additions are not supported. |
4107 |
+ |
* |
4108 |
+ |
* @return the default mapped value for additions, or {@code null} |
4109 |
+ |
* if not supported. |
4110 |
+ |
*/ |
4111 |
+ |
public V getMappedValue() { return value; } |
4112 |
+ |
|
4113 |
+ |
// implement Set API |
4114 |
+ |
|
4115 |
+ |
public boolean contains(Object o) { return map.containsKey(o); } |
4116 |
+ |
public boolean remove(Object o) { return map.remove(o) != null; } |
4117 |
+ |
|
4118 |
+ |
/** |
4119 |
+ |
* Returns a "weakly consistent" iterator that will never |
4120 |
+ |
* throw {@link ConcurrentModificationException}, and |
4121 |
+ |
* guarantees to traverse elements as they existed upon |
4122 |
+ |
* construction of the iterator, and may (but is not |
4123 |
+ |
* guaranteed to) reflect any modifications subsequent to |
4124 |
+ |
* construction. |
4125 |
+ |
* |
4126 |
+ |
* @return an iterator over the keys of this map |
4127 |
+ |
*/ |
4128 |
+ |
public Iterator<K> iterator() { return new KeyIterator<K,V>(map); } |
4129 |
+ |
public boolean add(K e) { |
4130 |
+ |
V v; |
4131 |
+ |
if ((v = value) == null) |
4132 |
+ |
throw new UnsupportedOperationException(); |
4133 |
+ |
if (e == null) |
4134 |
+ |
throw new NullPointerException(); |
4135 |
+ |
return map.internalPutIfAbsent(e, v) == null; |
4136 |
+ |
} |
4137 |
+ |
public boolean addAll(Collection<? extends K> c) { |
4138 |
+ |
boolean added = false; |
4139 |
+ |
V v; |
4140 |
+ |
if ((v = value) == null) |
4141 |
+ |
throw new UnsupportedOperationException(); |
4142 |
+ |
for (K e : c) { |
4143 |
+ |
if (e == null) |
4144 |
+ |
throw new NullPointerException(); |
4145 |
+ |
if (map.internalPutIfAbsent(e, v) == null) |
4146 |
+ |
added = true; |
4147 |
+ |
} |
4148 |
+ |
return added; |
4149 |
+ |
} |
4150 |
+ |
public boolean equals(Object o) { |
4151 |
+ |
Set<?> c; |
4152 |
+ |
return ((o instanceof Set) && |
4153 |
+ |
((c = (Set<?>)o) == this || |
4154 |
+ |
(containsAll(c) && c.containsAll(this)))); |
4155 |
+ |
} |
4156 |
+ |
|
4157 |
+ |
/** |
4158 |
+ |
* Performs the given action for each key. |
4159 |
+ |
* |
4160 |
+ |
* @param action the action |
4161 |
+ |
*/ |
4162 |
+ |
public void forEach(Action<K> action) { |
4163 |
+ |
ForkJoinTasks.forEachKey |
4164 |
+ |
(map, action).invoke(); |
4165 |
+ |
} |
4166 |
+ |
|
4167 |
+ |
/** |
4168 |
+ |
* Performs the given action for each non-null transformation |
4169 |
+ |
* of each key. |
4170 |
+ |
* |
4171 |
+ |
* @param transformer a function returning the transformation |
4172 |
+ |
* for an element, or null of there is no transformation (in |
4173 |
+ |
* which case the action is not applied). |
4174 |
+ |
* @param action the action |
4175 |
+ |
*/ |
4176 |
+ |
public <U> void forEach(Fun<? super K, ? extends U> transformer, |
4177 |
+ |
Action<U> action) { |
4178 |
+ |
ForkJoinTasks.forEachKey |
4179 |
+ |
(map, transformer, action).invoke(); |
4180 |
+ |
} |
4181 |
+ |
|
4182 |
+ |
/** |
4183 |
+ |
* Returns a non-null result from applying the given search |
4184 |
+ |
* function on each key, or null if none. Upon success, |
4185 |
+ |
* further element processing is suppressed and the results of |
4186 |
+ |
* any other parallel invocations of the search function are |
4187 |
+ |
* ignored. |
4188 |
+ |
* |
4189 |
+ |
* @param searchFunction a function returning a non-null |
4190 |
+ |
* result on success, else null |
4191 |
+ |
* @return a non-null result from applying the given search |
4192 |
+ |
* function on each key, or null if none |
4193 |
+ |
*/ |
4194 |
+ |
public <U> U search(Fun<? super K, ? extends U> searchFunction) { |
4195 |
+ |
return ForkJoinTasks.searchKeys |
4196 |
+ |
(map, searchFunction).invoke(); |
4197 |
+ |
} |
4198 |
+ |
|
4199 |
+ |
/** |
4200 |
+ |
* Returns the result of accumulating all keys using the given |
4201 |
+ |
* reducer to combine values, or null if none. |
4202 |
+ |
* |
4203 |
+ |
* @param reducer a commutative associative combining function |
4204 |
+ |
* @return the result of accumulating all keys using the given |
4205 |
+ |
* reducer to combine values, or null if none |
4206 |
+ |
*/ |
4207 |
+ |
public K reduce(BiFun<? super K, ? super K, ? extends K> reducer) { |
4208 |
+ |
return ForkJoinTasks.reduceKeys |
4209 |
+ |
(map, reducer).invoke(); |
4210 |
+ |
} |
4211 |
+ |
|
4212 |
+ |
/** |
4213 |
+ |
* Returns the result of accumulating the given transformation |
4214 |
+ |
* of all keys using the given reducer to combine values, and |
4215 |
+ |
* the given basis as an identity value. |
4216 |
+ |
* |
4217 |
+ |
* @param transformer a function returning the transformation |
4218 |
+ |
* for an element |
4219 |
+ |
* @param basis the identity (initial default value) for the reduction |
4220 |
+ |
* @param reducer a commutative associative combining function |
4221 |
+ |
* @return the result of accumulating the given transformation |
4222 |
+ |
* of all keys |
4223 |
+ |
*/ |
4224 |
+ |
public double reduceToDouble(ObjectToDouble<? super K> transformer, |
4225 |
+ |
double basis, |
4226 |
+ |
DoubleByDoubleToDouble reducer) { |
4227 |
+ |
return ForkJoinTasks.reduceKeysToDouble |
4228 |
+ |
(map, transformer, basis, reducer).invoke(); |
4229 |
+ |
} |
4230 |
+ |
|
4231 |
+ |
|
4232 |
+ |
/** |
4233 |
+ |
* Returns the result of accumulating the given transformation |
4234 |
+ |
* of all keys using the given reducer to combine values, and |
4235 |
+ |
* the given basis as an identity value. |
4236 |
+ |
* |
4237 |
+ |
* @param transformer a function returning the transformation |
4238 |
+ |
* for an element |
4239 |
+ |
* @param basis the identity (initial default value) for the reduction |
4240 |
+ |
* @param reducer a commutative associative combining function |
4241 |
+ |
* @return the result of accumulating the given transformation |
4242 |
+ |
* of all keys |
4243 |
+ |
*/ |
4244 |
+ |
public long reduceToLong(ObjectToLong<? super K> transformer, |
4245 |
+ |
long basis, |
4246 |
+ |
LongByLongToLong reducer) { |
4247 |
+ |
return ForkJoinTasks.reduceKeysToLong |
4248 |
+ |
(map, transformer, basis, reducer).invoke(); |
4249 |
+ |
} |
4250 |
+ |
|
4251 |
+ |
/** |
4252 |
+ |
* Returns the result of accumulating the given transformation |
4253 |
+ |
* of all keys using the given reducer to combine values, and |
4254 |
+ |
* the given basis as an identity value. |
4255 |
+ |
* |
4256 |
+ |
* @param transformer a function returning the transformation |
4257 |
+ |
* for an element |
4258 |
+ |
* @param basis the identity (initial default value) for the reduction |
4259 |
+ |
* @param reducer a commutative associative combining function |
4260 |
+ |
* @return the result of accumulating the given transformation |
4261 |
+ |
* of all keys |
4262 |
+ |
*/ |
4263 |
+ |
public int reduceToInt(ObjectToInt<? super K> transformer, |
4264 |
+ |
int basis, |
4265 |
+ |
IntByIntToInt reducer) { |
4266 |
+ |
return ForkJoinTasks.reduceKeysToInt |
4267 |
+ |
(map, transformer, basis, reducer).invoke(); |
4268 |
+ |
} |
4269 |
+ |
|
4270 |
+ |
} |
4271 |
+ |
|
4272 |
+ |
/** |
4273 |
+ |
* A view of a ConcurrentHashMapV8 as a {@link Collection} of |
4274 |
+ |
* values, in which additions are disabled. This class cannot be |
4275 |
+ |
* directly instantiated. See {@link #values}, |
4276 |
+ |
* |
4277 |
+ |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
4278 |
+ |
* that will never throw {@link ConcurrentModificationException}, |
4279 |
+ |
* and guarantees to traverse elements as they existed upon |
4280 |
+ |
* construction of the iterator, and may (but is not guaranteed to) |
4281 |
+ |
* reflect any modifications subsequent to construction. |
4282 |
+ |
*/ |
4283 |
+ |
public static final class ValuesView<K,V> extends CHMView<K,V> |
4284 |
+ |
implements Collection<V> { |
4285 |
+ |
ValuesView(ConcurrentHashMapV8<K, V> map) { super(map); } |
4286 |
+ |
public final boolean contains(Object o) { return map.containsValue(o); } |
4287 |
+ |
public final boolean remove(Object o) { |
4288 |
+ |
if (o != null) { |
4289 |
+ |
Iterator<V> it = new ValueIterator<K,V>(map); |
4290 |
+ |
while (it.hasNext()) { |
4291 |
+ |
if (o.equals(it.next())) { |
4292 |
+ |
it.remove(); |
4293 |
+ |
return true; |
4294 |
+ |
} |
4295 |
+ |
} |
4296 |
+ |
} |
4297 |
+ |
return false; |
4298 |
+ |
} |
4299 |
+ |
|
4300 |
+ |
/** |
4301 |
+ |
* Returns a "weakly consistent" iterator that will never |
4302 |
+ |
* throw {@link ConcurrentModificationException}, and |
4303 |
+ |
* guarantees to traverse elements as they existed upon |
4304 |
+ |
* construction of the iterator, and may (but is not |
4305 |
+ |
* guaranteed to) reflect any modifications subsequent to |
4306 |
+ |
* construction. |
4307 |
+ |
* |
4308 |
+ |
* @return an iterator over the values of this map |
4309 |
+ |
*/ |
4310 |
+ |
public final Iterator<V> iterator() { |
4311 |
+ |
return new ValueIterator<K,V>(map); |
4312 |
+ |
} |
4313 |
+ |
public final boolean add(V e) { |
4314 |
+ |
throw new UnsupportedOperationException(); |
4315 |
+ |
} |
4316 |
+ |
public final boolean addAll(Collection<? extends V> c) { |
4317 |
+ |
throw new UnsupportedOperationException(); |
4318 |
+ |
} |
4319 |
+ |
|
4320 |
+ |
/** |
4321 |
+ |
* Performs the given action for each value. |
4322 |
+ |
* |
4323 |
+ |
* @param action the action |
4324 |
+ |
*/ |
4325 |
+ |
public void forEach(Action<V> action) { |
4326 |
+ |
ForkJoinTasks.forEachValue |
4327 |
+ |
(map, action).invoke(); |
4328 |
+ |
} |
4329 |
+ |
|
4330 |
+ |
/** |
4331 |
+ |
* Performs the given action for each non-null transformation |
4332 |
+ |
* of each value. |
4333 |
+ |
* |
4334 |
+ |
* @param transformer a function returning the transformation |
4335 |
+ |
* for an element, or null of there is no transformation (in |
4336 |
+ |
* which case the action is not applied). |
4337 |
+ |
*/ |
4338 |
+ |
public <U> void forEach(Fun<? super V, ? extends U> transformer, |
4339 |
+ |
Action<U> action) { |
4340 |
+ |
ForkJoinTasks.forEachValue |
4341 |
+ |
(map, transformer, action).invoke(); |
4342 |
+ |
} |
4343 |
+ |
|
4344 |
+ |
/** |
4345 |
+ |
* Returns a non-null result from applying the given search |
4346 |
+ |
* function on each value, or null if none. Upon success, |
4347 |
+ |
* further element processing is suppressed and the results of |
4348 |
+ |
* any other parallel invocations of the search function are |
4349 |
+ |
* ignored. |
4350 |
+ |
* |
4351 |
+ |
* @param searchFunction a function returning a non-null |
4352 |
+ |
* result on success, else null |
4353 |
+ |
* @return a non-null result from applying the given search |
4354 |
+ |
* function on each value, or null if none |
4355 |
+ |
* |
4356 |
+ |
*/ |
4357 |
+ |
public <U> U search(Fun<? super V, ? extends U> searchFunction) { |
4358 |
+ |
return ForkJoinTasks.searchValues |
4359 |
+ |
(map, searchFunction).invoke(); |
4360 |
+ |
} |
4361 |
+ |
|
4362 |
+ |
/** |
4363 |
+ |
* Returns the result of accumulating all values using the |
4364 |
+ |
* given reducer to combine values, or null if none. |
4365 |
+ |
* |
4366 |
+ |
* @param reducer a commutative associative combining function |
4367 |
+ |
* @return the result of accumulating all values |
4368 |
+ |
*/ |
4369 |
+ |
public V reduce(BiFun<? super V, ? super V, ? extends V> reducer) { |
4370 |
+ |
return ForkJoinTasks.reduceValues |
4371 |
+ |
(map, reducer).invoke(); |
4372 |
+ |
} |
4373 |
+ |
|
4374 |
+ |
/** |
4375 |
+ |
* Returns the result of accumulating the given transformation |
4376 |
+ |
* of all values using the given reducer to combine values, or |
4377 |
+ |
* null if none. |
4378 |
+ |
* |
4379 |
+ |
* @param transformer a function returning the transformation |
4380 |
+ |
* for an element, or null of there is no transformation (in |
4381 |
+ |
* which case it is not combined). |
4382 |
+ |
* @param reducer a commutative associative combining function |
4383 |
+ |
* @return the result of accumulating the given transformation |
4384 |
+ |
* of all values |
4385 |
+ |
*/ |
4386 |
+ |
public <U> U reduce(Fun<? super V, ? extends U> transformer, |
4387 |
+ |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4388 |
+ |
return ForkJoinTasks.reduceValues |
4389 |
+ |
(map, transformer, reducer).invoke(); |
4390 |
+ |
} |
4391 |
+ |
|
4392 |
+ |
/** |
4393 |
+ |
* Returns the result of accumulating the given transformation |
4394 |
+ |
* of all values using the given reducer to combine values, |
4395 |
+ |
* and the given basis as an identity value. |
4396 |
+ |
* |
4397 |
+ |
* @param transformer a function returning the transformation |
4398 |
+ |
* for an element |
4399 |
+ |
* @param basis the identity (initial default value) for the reduction |
4400 |
+ |
* @param reducer a commutative associative combining function |
4401 |
+ |
* @return the result of accumulating the given transformation |
4402 |
+ |
* of all values |
4403 |
+ |
*/ |
4404 |
+ |
public double reduceToDouble(ObjectToDouble<? super V> transformer, |
4405 |
+ |
double basis, |
4406 |
+ |
DoubleByDoubleToDouble reducer) { |
4407 |
+ |
return ForkJoinTasks.reduceValuesToDouble |
4408 |
+ |
(map, transformer, basis, reducer).invoke(); |
4409 |
+ |
} |
4410 |
+ |
|
4411 |
+ |
/** |
4412 |
+ |
* Returns the result of accumulating the given transformation |
4413 |
+ |
* of all values using the given reducer to combine values, |
4414 |
+ |
* and the given basis as an identity value. |
4415 |
+ |
* |
4416 |
+ |
* @param transformer a function returning the transformation |
4417 |
+ |
* for an element |
4418 |
+ |
* @param basis the identity (initial default value) for the reduction |
4419 |
+ |
* @param reducer a commutative associative combining function |
4420 |
+ |
* @return the result of accumulating the given transformation |
4421 |
+ |
* of all values |
4422 |
+ |
*/ |
4423 |
+ |
public long reduceToLong(ObjectToLong<? super V> transformer, |
4424 |
+ |
long basis, |
4425 |
+ |
LongByLongToLong reducer) { |
4426 |
+ |
return ForkJoinTasks.reduceValuesToLong |
4427 |
+ |
(map, transformer, basis, reducer).invoke(); |
4428 |
+ |
} |
4429 |
+ |
|
4430 |
+ |
/** |
4431 |
+ |
* Returns the result of accumulating the given transformation |
4432 |
+ |
* of all values using the given reducer to combine values, |
4433 |
+ |
* and the given basis as an identity value. |
4434 |
+ |
* |
4435 |
+ |
* @param transformer a function returning the transformation |
4436 |
+ |
* for an element |
4437 |
+ |
* @param basis the identity (initial default value) for the reduction |
4438 |
+ |
* @param reducer a commutative associative combining function |
4439 |
+ |
* @return the result of accumulating the given transformation |
4440 |
+ |
* of all values |
4441 |
+ |
*/ |
4442 |
+ |
public int reduceToInt(ObjectToInt<? super V> transformer, |
4443 |
+ |
int basis, |
4444 |
+ |
IntByIntToInt reducer) { |
4445 |
+ |
return ForkJoinTasks.reduceValuesToInt |
4446 |
+ |
(map, transformer, basis, reducer).invoke(); |
4447 |
+ |
} |
4448 |
+ |
|
4449 |
+ |
} |
4450 |
+ |
|
4451 |
+ |
/** |
4452 |
+ |
* A view of a ConcurrentHashMapV8 as a {@link Set} of (key, value) |
4453 |
+ |
* entries. This class cannot be directly instantiated. See |
4454 |
+ |
* {@link #entrySet}. |
4455 |
+ |
*/ |
4456 |
+ |
public static final class EntrySetView<K,V> extends CHMView<K,V> |
4457 |
+ |
implements Set<Map.Entry<K,V>> { |
4458 |
+ |
EntrySetView(ConcurrentHashMapV8<K, V> map) { super(map); } |
4459 |
+ |
public final boolean contains(Object o) { |
4460 |
+ |
Object k, v, r; Map.Entry<?,?> e; |
4461 |
+ |
return ((o instanceof Map.Entry) && |
4462 |
+ |
(k = (e = (Map.Entry<?,?>)o).getKey()) != null && |
4463 |
+ |
(r = map.get(k)) != null && |
4464 |
+ |
(v = e.getValue()) != null && |
4465 |
+ |
(v == r || v.equals(r))); |
4466 |
+ |
} |
4467 |
+ |
public final boolean remove(Object o) { |
4468 |
+ |
Object k, v; Map.Entry<?,?> e; |
4469 |
+ |
return ((o instanceof Map.Entry) && |
4470 |
+ |
(k = (e = (Map.Entry<?,?>)o).getKey()) != null && |
4471 |
+ |
(v = e.getValue()) != null && |
4472 |
+ |
map.remove(k, v)); |
4473 |
+ |
} |
4474 |
+ |
|
4475 |
+ |
/** |
4476 |
+ |
* Returns a "weakly consistent" iterator that will never |
4477 |
+ |
* throw {@link ConcurrentModificationException}, and |
4478 |
+ |
* guarantees to traverse elements as they existed upon |
4479 |
+ |
* construction of the iterator, and may (but is not |
4480 |
+ |
* guaranteed to) reflect any modifications subsequent to |
4481 |
+ |
* construction. |
4482 |
+ |
* |
4483 |
+ |
* @return an iterator over the entries of this map |
4484 |
+ |
*/ |
4485 |
+ |
public final Iterator<Map.Entry<K,V>> iterator() { |
4486 |
+ |
return new EntryIterator<K,V>(map); |
4487 |
+ |
} |
4488 |
+ |
|
4489 |
+ |
public final boolean add(Entry<K,V> e) { |
4490 |
+ |
K key = e.getKey(); |
4491 |
+ |
V value = e.getValue(); |
4492 |
+ |
if (key == null || value == null) |
4493 |
+ |
throw new NullPointerException(); |
4494 |
+ |
return map.internalPut(key, value) == null; |
4495 |
+ |
} |
4496 |
+ |
public final boolean addAll(Collection<? extends Entry<K,V>> c) { |
4497 |
+ |
boolean added = false; |
4498 |
+ |
for (Entry<K,V> e : c) { |
4499 |
+ |
if (add(e)) |
4500 |
+ |
added = true; |
4501 |
+ |
} |
4502 |
+ |
return added; |
4503 |
+ |
} |
4504 |
+ |
public boolean equals(Object o) { |
4505 |
+ |
Set<?> c; |
4506 |
+ |
return ((o instanceof Set) && |
4507 |
+ |
((c = (Set<?>)o) == this || |
4508 |
+ |
(containsAll(c) && c.containsAll(this)))); |
4509 |
+ |
} |
4510 |
+ |
|
4511 |
+ |
/** |
4512 |
+ |
* Performs the given action for each entry. |
4513 |
+ |
* |
4514 |
+ |
* @param action the action |
4515 |
+ |
*/ |
4516 |
+ |
public void forEach(Action<Map.Entry<K,V>> action) { |
4517 |
+ |
ForkJoinTasks.forEachEntry |
4518 |
+ |
(map, action).invoke(); |
4519 |
+ |
} |
4520 |
+ |
|
4521 |
+ |
/** |
4522 |
+ |
* Performs the given action for each non-null transformation |
4523 |
+ |
* of each entry. |
4524 |
+ |
* |
4525 |
+ |
* @param transformer a function returning the transformation |
4526 |
+ |
* for an element, or null of there is no transformation (in |
4527 |
+ |
* which case the action is not applied). |
4528 |
+ |
* @param action the action |
4529 |
+ |
*/ |
4530 |
+ |
public <U> void forEach(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4531 |
+ |
Action<U> action) { |
4532 |
+ |
ForkJoinTasks.forEachEntry |
4533 |
+ |
(map, transformer, action).invoke(); |
4534 |
+ |
} |
4535 |
+ |
|
4536 |
+ |
/** |
4537 |
+ |
* Returns a non-null result from applying the given search |
4538 |
+ |
* function on each entry, or null if none. Upon success, |
4539 |
+ |
* further element processing is suppressed and the results of |
4540 |
+ |
* any other parallel invocations of the search function are |
4541 |
+ |
* ignored. |
4542 |
+ |
* |
4543 |
+ |
* @param searchFunction a function returning a non-null |
4544 |
+ |
* result on success, else null |
4545 |
+ |
* @return a non-null result from applying the given search |
4546 |
+ |
* function on each entry, or null if none |
4547 |
+ |
*/ |
4548 |
+ |
public <U> U search(Fun<Map.Entry<K,V>, ? extends U> searchFunction) { |
4549 |
+ |
return ForkJoinTasks.searchEntries |
4550 |
+ |
(map, searchFunction).invoke(); |
4551 |
+ |
} |
4552 |
+ |
|
4553 |
+ |
/** |
4554 |
+ |
* Returns the result of accumulating all entries using the |
4555 |
+ |
* given reducer to combine values, or null if none. |
4556 |
+ |
* |
4557 |
+ |
* @param reducer a commutative associative combining function |
4558 |
+ |
* @return the result of accumulating all entries |
4559 |
+ |
*/ |
4560 |
+ |
public Map.Entry<K,V> reduce(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
4561 |
+ |
return ForkJoinTasks.reduceEntries |
4562 |
+ |
(map, reducer).invoke(); |
4563 |
+ |
} |
4564 |
+ |
|
4565 |
+ |
/** |
4566 |
+ |
* Returns the result of accumulating the given transformation |
4567 |
+ |
* of all entries using the given reducer to combine values, |
4568 |
+ |
* or null if none. |
4569 |
+ |
* |
4570 |
+ |
* @param transformer a function returning the transformation |
4571 |
+ |
* for an element, or null of there is no transformation (in |
4572 |
+ |
* which case it is not combined). |
4573 |
+ |
* @param reducer a commutative associative combining function |
4574 |
+ |
* @return the result of accumulating the given transformation |
4575 |
+ |
* of all entries |
4576 |
+ |
*/ |
4577 |
+ |
public <U> U reduce(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4578 |
+ |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4579 |
+ |
return ForkJoinTasks.reduceEntries |
4580 |
+ |
(map, transformer, reducer).invoke(); |
4581 |
+ |
} |
4582 |
+ |
|
4583 |
+ |
/** |
4584 |
+ |
* Returns the result of accumulating the given transformation |
4585 |
+ |
* of all entries using the given reducer to combine values, |
4586 |
+ |
* and the given basis as an identity value. |
4587 |
+ |
* |
4588 |
+ |
* @param transformer a function returning the transformation |
4589 |
+ |
* for an element |
4590 |
+ |
* @param basis the identity (initial default value) for the reduction |
4591 |
+ |
* @param reducer a commutative associative combining function |
4592 |
+ |
* @return the result of accumulating the given transformation |
4593 |
+ |
* of all entries |
4594 |
+ |
*/ |
4595 |
+ |
public double reduceToDouble(ObjectToDouble<Map.Entry<K,V>> transformer, |
4596 |
+ |
double basis, |
4597 |
+ |
DoubleByDoubleToDouble reducer) { |
4598 |
+ |
return ForkJoinTasks.reduceEntriesToDouble |
4599 |
+ |
(map, transformer, basis, reducer).invoke(); |
4600 |
+ |
} |
4601 |
+ |
|
4602 |
+ |
/** |
4603 |
+ |
* Returns the result of accumulating the given transformation |
4604 |
+ |
* of all entries using the given reducer to combine values, |
4605 |
+ |
* and the given basis as an identity value. |
4606 |
+ |
* |
4607 |
+ |
* @param transformer a function returning the transformation |
4608 |
+ |
* for an element |
4609 |
+ |
* @param basis the identity (initial default value) for the reduction |
4610 |
+ |
* @param reducer a commutative associative combining function |
4611 |
+ |
* @return the result of accumulating the given transformation |
4612 |
+ |
* of all entries |
4613 |
+ |
*/ |
4614 |
+ |
public long reduceToLong(ObjectToLong<Map.Entry<K,V>> transformer, |
4615 |
+ |
long basis, |
4616 |
+ |
LongByLongToLong reducer) { |
4617 |
+ |
return ForkJoinTasks.reduceEntriesToLong |
4618 |
+ |
(map, transformer, basis, reducer).invoke(); |
4619 |
+ |
} |
4620 |
+ |
|
4621 |
+ |
/** |
4622 |
+ |
* Returns the result of accumulating the given transformation |
4623 |
+ |
* of all entries using the given reducer to combine values, |
4624 |
+ |
* and the given basis as an identity value. |
4625 |
+ |
* |
4626 |
+ |
* @param transformer a function returning the transformation |
4627 |
+ |
* for an element |
4628 |
+ |
* @param basis the identity (initial default value) for the reduction |
4629 |
+ |
* @param reducer a commutative associative combining function |
4630 |
+ |
* @return the result of accumulating the given transformation |
4631 |
+ |
* of all entries |
4632 |
+ |
*/ |
4633 |
+ |
public int reduceToInt(ObjectToInt<Map.Entry<K,V>> transformer, |
4634 |
+ |
int basis, |
4635 |
+ |
IntByIntToInt reducer) { |
4636 |
+ |
return ForkJoinTasks.reduceEntriesToInt |
4637 |
+ |
(map, transformer, basis, reducer).invoke(); |
4638 |
+ |
} |
4639 |
+ |
|
4640 |
+ |
} |
4641 |
+ |
|
4642 |
|
// --------------------------------------------------------------------- |
4643 |
|
|
4644 |
|
/** |
5340 |
|
} |
5341 |
|
} |
5342 |
|
|
4909 |
– |
// FJ methods |
4910 |
– |
|
4911 |
– |
/** |
4912 |
– |
* Propagates completion. Note that all reduce actions |
4913 |
– |
* bypass this method to combine while completing. |
4914 |
– |
*/ |
4915 |
– |
final void tryComplete() { |
4916 |
– |
BulkTask<K,V,?> a = this, s = a; |
4917 |
– |
for (int c;;) { |
4918 |
– |
if ((c = a.pending) == 0) { |
4919 |
– |
if ((a = (s = a).parent) == null) { |
4920 |
– |
s.quietlyComplete(); |
4921 |
– |
break; |
4922 |
– |
} |
4923 |
– |
} |
4924 |
– |
else if (U.compareAndSwapInt(a, PENDING, c, c - 1)) |
4925 |
– |
break; |
4926 |
– |
} |
4927 |
– |
} |
4928 |
– |
|
5343 |
|
/** |
5344 |
|
* Forces root task to complete. |
5345 |
|
* @param ex if null, complete normally, else exceptionally |
5387 |
|
baseLimit = baseSize = t.length; |
5388 |
|
if (t != null) { |
5389 |
|
long n = m.counter.sum(); |
5390 |
< |
int par = (pool = getPool()) == null? |
5390 |
> |
int par = ((pool = getPool()) == null) ? |
5391 |
|
ForkJoinPool.getCommonPoolParallelism() : |
5392 |
|
pool.getParallelism(); |
5393 |
|
int sp = par << 3; // slack of 8 |
5418 |
|
} |
5419 |
|
} |
5420 |
|
|
5421 |
+ |
/** |
5422 |
+ |
* Base class for non-reductive actions |
5423 |
+ |
*/ |
5424 |
+ |
@SuppressWarnings("serial") static abstract class BulkAction<K,V,R> extends BulkTask<K,V,R> { |
5425 |
+ |
BulkAction<K,V,?> nextTask; |
5426 |
+ |
BulkAction(ConcurrentHashMapV8<K,V> map, BulkTask<K,V,?> parent, |
5427 |
+ |
int batch, BulkAction<K,V,?> nextTask) { |
5428 |
+ |
super(map, parent, batch); |
5429 |
+ |
this.nextTask = nextTask; |
5430 |
+ |
} |
5431 |
+ |
|
5432 |
+ |
/** |
5433 |
+ |
* Try to complete task and upward parents. Upon hitting |
5434 |
+ |
* non-completed parent, if a non-FJ task, try to help out the |
5435 |
+ |
* computation. |
5436 |
+ |
*/ |
5437 |
+ |
final void tryComplete(BulkAction<K,V,?> subtasks) { |
5438 |
+ |
BulkTask<K,V,?> a = this, s = a; |
5439 |
+ |
for (int c;;) { |
5440 |
+ |
if ((c = a.pending) == 0) { |
5441 |
+ |
if ((a = (s = a).parent) == null) { |
5442 |
+ |
s.quietlyComplete(); |
5443 |
+ |
break; |
5444 |
+ |
} |
5445 |
+ |
} |
5446 |
+ |
else if (a.casPending(c, c - 1)) { |
5447 |
+ |
if (subtasks != null && !inForkJoinPool()) { |
5448 |
+ |
while ((s = a.parent) != null) |
5449 |
+ |
a = s; |
5450 |
+ |
while (!a.isDone()) { |
5451 |
+ |
BulkAction<K,V,?> next = subtasks.nextTask; |
5452 |
+ |
if (subtasks.tryUnfork()) |
5453 |
+ |
subtasks.exec(); |
5454 |
+ |
if ((subtasks = next) == null) |
5455 |
+ |
break; |
5456 |
+ |
} |
5457 |
+ |
} |
5458 |
+ |
break; |
5459 |
+ |
} |
5460 |
+ |
} |
5461 |
+ |
} |
5462 |
+ |
|
5463 |
+ |
} |
5464 |
+ |
|
5465 |
|
/* |
5466 |
|
* Task classes. Coded in a regular but ugly format/style to |
5467 |
|
* simplify checks that each variant differs in the right way from |
5469 |
|
*/ |
5470 |
|
|
5471 |
|
@SuppressWarnings("serial") static final class ForEachKeyTask<K,V> |
5472 |
< |
extends BulkTask<K,V,Void> { |
5472 |
> |
extends BulkAction<K,V,Void> { |
5473 |
|
final Action<K> action; |
5016 |
– |
ForEachKeyTask<K,V> nextRight; |
5474 |
|
ForEachKeyTask |
5475 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5476 |
< |
ForEachKeyTask<K,V> nextRight, |
5476 |
> |
ForEachKeyTask<K,V> nextTask, |
5477 |
|
Action<K> action) { |
5478 |
< |
super(m, p, b); |
5022 |
< |
this.nextRight = nextRight; |
5478 |
> |
super(m, p, b, nextTask); |
5479 |
|
this.action = action; |
5480 |
|
} |
5481 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5482 |
|
final Action<K> action = this.action; |
5483 |
|
if (action == null) |
5484 |
|
return abortOnNullFunction(); |
5485 |
< |
ForEachKeyTask<K,V> rights = null; |
5485 |
> |
ForEachKeyTask<K,V> subtasks = null; |
5486 |
|
try { |
5487 |
|
int b = batch(), c; |
5488 |
|
while (b > 1 && baseIndex != baseLimit) { |
5489 |
|
do {} while (!casPending(c = pending, c+1)); |
5490 |
< |
(rights = new ForEachKeyTask<K,V> |
5491 |
< |
(map, this, b >>>= 1, rights, action)).fork(); |
5490 |
> |
(subtasks = new ForEachKeyTask<K,V> |
5491 |
> |
(map, this, b >>>= 1, subtasks, action)).fork(); |
5492 |
|
} |
5493 |
|
while (advance() != null) |
5494 |
|
action.apply((K)nextKey); |
5039 |
– |
tryComplete(); |
5495 |
|
} catch (Throwable ex) { |
5496 |
|
return tryCompleteComputation(ex); |
5497 |
|
} |
5498 |
< |
while (rights != null && rights.tryUnfork()) { |
5044 |
< |
rights.exec(); |
5045 |
< |
rights = rights.nextRight; |
5046 |
< |
} |
5498 |
> |
tryComplete(subtasks); |
5499 |
|
return false; |
5500 |
|
} |
5501 |
|
} |
5502 |
|
|
5503 |
|
@SuppressWarnings("serial") static final class ForEachValueTask<K,V> |
5504 |
< |
extends BulkTask<K,V,Void> { |
5053 |
< |
ForEachValueTask<K,V> nextRight; |
5504 |
> |
extends BulkAction<K,V,Void> { |
5505 |
|
final Action<V> action; |
5506 |
|
ForEachValueTask |
5507 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5508 |
< |
ForEachValueTask<K,V> nextRight, |
5508 |
> |
ForEachValueTask<K,V> nextTask, |
5509 |
|
Action<V> action) { |
5510 |
< |
super(m, p, b); |
5060 |
< |
this.nextRight = nextRight; |
5510 |
> |
super(m, p, b, nextTask); |
5511 |
|
this.action = action; |
5512 |
|
} |
5513 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5514 |
|
final Action<V> action = this.action; |
5515 |
|
if (action == null) |
5516 |
|
return abortOnNullFunction(); |
5517 |
< |
ForEachValueTask<K,V> rights = null; |
5517 |
> |
ForEachValueTask<K,V> subtasks = null; |
5518 |
|
try { |
5519 |
|
int b = batch(), c; |
5520 |
|
while (b > 1 && baseIndex != baseLimit) { |
5521 |
|
do {} while (!casPending(c = pending, c+1)); |
5522 |
< |
(rights = new ForEachValueTask<K,V> |
5523 |
< |
(map, this, b >>>= 1, rights, action)).fork(); |
5522 |
> |
(subtasks = new ForEachValueTask<K,V> |
5523 |
> |
(map, this, b >>>= 1, subtasks, action)).fork(); |
5524 |
|
} |
5525 |
|
Object v; |
5526 |
|
while ((v = advance()) != null) |
5527 |
|
action.apply((V)v); |
5078 |
– |
tryComplete(); |
5528 |
|
} catch (Throwable ex) { |
5529 |
|
return tryCompleteComputation(ex); |
5530 |
|
} |
5531 |
< |
while (rights != null && rights.tryUnfork()) { |
5083 |
< |
rights.exec(); |
5084 |
< |
rights = rights.nextRight; |
5085 |
< |
} |
5531 |
> |
tryComplete(subtasks); |
5532 |
|
return false; |
5533 |
|
} |
5534 |
|
} |
5535 |
|
|
5536 |
|
@SuppressWarnings("serial") static final class ForEachEntryTask<K,V> |
5537 |
< |
extends BulkTask<K,V,Void> { |
5092 |
< |
ForEachEntryTask<K,V> nextRight; |
5537 |
> |
extends BulkAction<K,V,Void> { |
5538 |
|
final Action<Entry<K,V>> action; |
5539 |
|
ForEachEntryTask |
5540 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5541 |
< |
ForEachEntryTask<K,V> nextRight, |
5541 |
> |
ForEachEntryTask<K,V> nextTask, |
5542 |
|
Action<Entry<K,V>> action) { |
5543 |
< |
super(m, p, b); |
5099 |
< |
this.nextRight = nextRight; |
5543 |
> |
super(m, p, b, nextTask); |
5544 |
|
this.action = action; |
5545 |
|
} |
5546 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5547 |
|
final Action<Entry<K,V>> action = this.action; |
5548 |
|
if (action == null) |
5549 |
|
return abortOnNullFunction(); |
5550 |
< |
ForEachEntryTask<K,V> rights = null; |
5550 |
> |
ForEachEntryTask<K,V> subtasks = null; |
5551 |
|
try { |
5552 |
|
int b = batch(), c; |
5553 |
|
while (b > 1 && baseIndex != baseLimit) { |
5554 |
|
do {} while (!casPending(c = pending, c+1)); |
5555 |
< |
(rights = new ForEachEntryTask<K,V> |
5556 |
< |
(map, this, b >>>= 1, rights, action)).fork(); |
5555 |
> |
(subtasks = new ForEachEntryTask<K,V> |
5556 |
> |
(map, this, b >>>= 1, subtasks, action)).fork(); |
5557 |
|
} |
5558 |
|
Object v; |
5559 |
|
while ((v = advance()) != null) |
5560 |
|
action.apply(entryFor((K)nextKey, (V)v)); |
5117 |
– |
tryComplete(); |
5561 |
|
} catch (Throwable ex) { |
5562 |
|
return tryCompleteComputation(ex); |
5563 |
|
} |
5564 |
< |
while (rights != null && rights.tryUnfork()) { |
5122 |
< |
rights.exec(); |
5123 |
< |
rights = rights.nextRight; |
5124 |
< |
} |
5564 |
> |
tryComplete(subtasks); |
5565 |
|
return false; |
5566 |
|
} |
5567 |
|
} |
5568 |
|
|
5569 |
|
@SuppressWarnings("serial") static final class ForEachMappingTask<K,V> |
5570 |
< |
extends BulkTask<K,V,Void> { |
5131 |
< |
ForEachMappingTask<K,V> nextRight; |
5570 |
> |
extends BulkAction<K,V,Void> { |
5571 |
|
final BiAction<K,V> action; |
5572 |
|
ForEachMappingTask |
5573 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5574 |
< |
ForEachMappingTask<K,V> nextRight, |
5574 |
> |
ForEachMappingTask<K,V> nextTask, |
5575 |
|
BiAction<K,V> action) { |
5576 |
< |
super(m, p, b); |
5138 |
< |
this.nextRight = nextRight; |
5576 |
> |
super(m, p, b, nextTask); |
5577 |
|
this.action = action; |
5578 |
|
} |
5579 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5580 |
|
final BiAction<K,V> action = this.action; |
5581 |
|
if (action == null) |
5582 |
|
return abortOnNullFunction(); |
5583 |
< |
ForEachMappingTask<K,V> rights = null; |
5583 |
> |
ForEachMappingTask<K,V> subtasks = null; |
5584 |
|
try { |
5585 |
|
int b = batch(), c; |
5586 |
|
while (b > 1 && baseIndex != baseLimit) { |
5587 |
|
do {} while (!casPending(c = pending, c+1)); |
5588 |
< |
(rights = new ForEachMappingTask<K,V> |
5589 |
< |
(map, this, b >>>= 1, rights, action)).fork(); |
5588 |
> |
(subtasks = new ForEachMappingTask<K,V> |
5589 |
> |
(map, this, b >>>= 1, subtasks, action)).fork(); |
5590 |
|
} |
5591 |
|
Object v; |
5592 |
|
while ((v = advance()) != null) |
5593 |
|
action.apply((K)nextKey, (V)v); |
5156 |
– |
tryComplete(); |
5594 |
|
} catch (Throwable ex) { |
5595 |
|
return tryCompleteComputation(ex); |
5596 |
|
} |
5597 |
< |
while (rights != null && rights.tryUnfork()) { |
5161 |
< |
rights.exec(); |
5162 |
< |
rights = rights.nextRight; |
5163 |
< |
} |
5597 |
> |
tryComplete(subtasks); |
5598 |
|
return false; |
5599 |
|
} |
5600 |
|
} |
5601 |
|
|
5602 |
|
@SuppressWarnings("serial") static final class ForEachTransformedKeyTask<K,V,U> |
5603 |
< |
extends BulkTask<K,V,Void> { |
5170 |
< |
ForEachTransformedKeyTask<K,V,U> nextRight; |
5603 |
> |
extends BulkAction<K,V,Void> { |
5604 |
|
final Fun<? super K, ? extends U> transformer; |
5605 |
|
final Action<U> action; |
5606 |
|
ForEachTransformedKeyTask |
5607 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5608 |
< |
ForEachTransformedKeyTask<K,V,U> nextRight, |
5608 |
> |
ForEachTransformedKeyTask<K,V,U> nextTask, |
5609 |
|
Fun<? super K, ? extends U> transformer, |
5610 |
|
Action<U> action) { |
5611 |
< |
super(m, p, b); |
5179 |
< |
this.nextRight = nextRight; |
5611 |
> |
super(m, p, b, nextTask); |
5612 |
|
this.transformer = transformer; |
5613 |
|
this.action = action; |
5614 |
|
|
5619 |
|
final Action<U> action = this.action; |
5620 |
|
if (transformer == null || action == null) |
5621 |
|
return abortOnNullFunction(); |
5622 |
< |
ForEachTransformedKeyTask<K,V,U> rights = null; |
5622 |
> |
ForEachTransformedKeyTask<K,V,U> subtasks = null; |
5623 |
|
try { |
5624 |
|
int b = batch(), c; |
5625 |
|
while (b > 1 && baseIndex != baseLimit) { |
5626 |
|
do {} while (!casPending(c = pending, c+1)); |
5627 |
< |
(rights = new ForEachTransformedKeyTask<K,V,U> |
5628 |
< |
(map, this, b >>>= 1, rights, transformer, action)).fork(); |
5627 |
> |
(subtasks = new ForEachTransformedKeyTask<K,V,U> |
5628 |
> |
(map, this, b >>>= 1, subtasks, transformer, action)).fork(); |
5629 |
|
} |
5630 |
|
U u; |
5631 |
|
while (advance() != null) { |
5632 |
|
if ((u = transformer.apply((K)nextKey)) != null) |
5633 |
|
action.apply(u); |
5634 |
|
} |
5203 |
– |
tryComplete(); |
5635 |
|
} catch (Throwable ex) { |
5636 |
|
return tryCompleteComputation(ex); |
5637 |
|
} |
5638 |
< |
while (rights != null && rights.tryUnfork()) { |
5208 |
< |
rights.exec(); |
5209 |
< |
rights = rights.nextRight; |
5210 |
< |
} |
5638 |
> |
tryComplete(subtasks); |
5639 |
|
return false; |
5640 |
|
} |
5641 |
|
} |
5642 |
|
|
5643 |
|
@SuppressWarnings("serial") static final class ForEachTransformedValueTask<K,V,U> |
5644 |
< |
extends BulkTask<K,V,Void> { |
5217 |
< |
ForEachTransformedValueTask<K,V,U> nextRight; |
5644 |
> |
extends BulkAction<K,V,Void> { |
5645 |
|
final Fun<? super V, ? extends U> transformer; |
5646 |
|
final Action<U> action; |
5647 |
|
ForEachTransformedValueTask |
5648 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5649 |
< |
ForEachTransformedValueTask<K,V,U> nextRight, |
5649 |
> |
ForEachTransformedValueTask<K,V,U> nextTask, |
5650 |
|
Fun<? super V, ? extends U> transformer, |
5651 |
|
Action<U> action) { |
5652 |
< |
super(m, p, b); |
5226 |
< |
this.nextRight = nextRight; |
5652 |
> |
super(m, p, b, nextTask); |
5653 |
|
this.transformer = transformer; |
5654 |
|
this.action = action; |
5655 |
|
|
5660 |
|
final Action<U> action = this.action; |
5661 |
|
if (transformer == null || action == null) |
5662 |
|
return abortOnNullFunction(); |
5663 |
< |
ForEachTransformedValueTask<K,V,U> rights = null; |
5663 |
> |
ForEachTransformedValueTask<K,V,U> subtasks = null; |
5664 |
|
try { |
5665 |
|
int b = batch(), c; |
5666 |
|
while (b > 1 && baseIndex != baseLimit) { |
5667 |
|
do {} while (!casPending(c = pending, c+1)); |
5668 |
< |
(rights = new ForEachTransformedValueTask<K,V,U> |
5669 |
< |
(map, this, b >>>= 1, rights, transformer, action)).fork(); |
5668 |
> |
(subtasks = new ForEachTransformedValueTask<K,V,U> |
5669 |
> |
(map, this, b >>>= 1, subtasks, transformer, action)).fork(); |
5670 |
|
} |
5671 |
|
Object v; U u; |
5672 |
|
while ((v = advance()) != null) { |
5673 |
|
if ((u = transformer.apply((V)v)) != null) |
5674 |
|
action.apply(u); |
5675 |
|
} |
5250 |
– |
tryComplete(); |
5676 |
|
} catch (Throwable ex) { |
5677 |
|
return tryCompleteComputation(ex); |
5678 |
|
} |
5679 |
< |
while (rights != null && rights.tryUnfork()) { |
5255 |
< |
rights.exec(); |
5256 |
< |
rights = rights.nextRight; |
5257 |
< |
} |
5679 |
> |
tryComplete(subtasks); |
5680 |
|
return false; |
5681 |
|
} |
5682 |
|
} |
5683 |
|
|
5684 |
|
@SuppressWarnings("serial") static final class ForEachTransformedEntryTask<K,V,U> |
5685 |
< |
extends BulkTask<K,V,Void> { |
5264 |
< |
ForEachTransformedEntryTask<K,V,U> nextRight; |
5685 |
> |
extends BulkAction<K,V,Void> { |
5686 |
|
final Fun<Map.Entry<K,V>, ? extends U> transformer; |
5687 |
|
final Action<U> action; |
5688 |
|
ForEachTransformedEntryTask |
5689 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5690 |
< |
ForEachTransformedEntryTask<K,V,U> nextRight, |
5690 |
> |
ForEachTransformedEntryTask<K,V,U> nextTask, |
5691 |
|
Fun<Map.Entry<K,V>, ? extends U> transformer, |
5692 |
|
Action<U> action) { |
5693 |
< |
super(m, p, b); |
5273 |
< |
this.nextRight = nextRight; |
5693 |
> |
super(m, p, b, nextTask); |
5694 |
|
this.transformer = transformer; |
5695 |
|
this.action = action; |
5696 |
|
|
5701 |
|
final Action<U> action = this.action; |
5702 |
|
if (transformer == null || action == null) |
5703 |
|
return abortOnNullFunction(); |
5704 |
< |
ForEachTransformedEntryTask<K,V,U> rights = null; |
5704 |
> |
ForEachTransformedEntryTask<K,V,U> subtasks = null; |
5705 |
|
try { |
5706 |
|
int b = batch(), c; |
5707 |
|
while (b > 1 && baseIndex != baseLimit) { |
5708 |
|
do {} while (!casPending(c = pending, c+1)); |
5709 |
< |
(rights = new ForEachTransformedEntryTask<K,V,U> |
5710 |
< |
(map, this, b >>>= 1, rights, transformer, action)).fork(); |
5709 |
> |
(subtasks = new ForEachTransformedEntryTask<K,V,U> |
5710 |
> |
(map, this, b >>>= 1, subtasks, transformer, action)).fork(); |
5711 |
|
} |
5712 |
|
Object v; U u; |
5713 |
|
while ((v = advance()) != null) { |
5714 |
|
if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null) |
5715 |
|
action.apply(u); |
5716 |
|
} |
5297 |
– |
tryComplete(); |
5717 |
|
} catch (Throwable ex) { |
5718 |
|
return tryCompleteComputation(ex); |
5719 |
|
} |
5720 |
< |
while (rights != null && rights.tryUnfork()) { |
5302 |
< |
rights.exec(); |
5303 |
< |
rights = rights.nextRight; |
5304 |
< |
} |
5720 |
> |
tryComplete(subtasks); |
5721 |
|
return false; |
5722 |
|
} |
5723 |
|
} |
5724 |
|
|
5725 |
|
@SuppressWarnings("serial") static final class ForEachTransformedMappingTask<K,V,U> |
5726 |
< |
extends BulkTask<K,V,Void> { |
5311 |
< |
ForEachTransformedMappingTask<K,V,U> nextRight; |
5726 |
> |
extends BulkAction<K,V,Void> { |
5727 |
|
final BiFun<? super K, ? super V, ? extends U> transformer; |
5728 |
|
final Action<U> action; |
5729 |
|
ForEachTransformedMappingTask |
5730 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5731 |
< |
ForEachTransformedMappingTask<K,V,U> nextRight, |
5731 |
> |
ForEachTransformedMappingTask<K,V,U> nextTask, |
5732 |
|
BiFun<? super K, ? super V, ? extends U> transformer, |
5733 |
|
Action<U> action) { |
5734 |
< |
super(m, p, b); |
5320 |
< |
this.nextRight = nextRight; |
5734 |
> |
super(m, p, b, nextTask); |
5735 |
|
this.transformer = transformer; |
5736 |
|
this.action = action; |
5737 |
|
|
5742 |
|
final Action<U> action = this.action; |
5743 |
|
if (transformer == null || action == null) |
5744 |
|
return abortOnNullFunction(); |
5745 |
< |
ForEachTransformedMappingTask<K,V,U> rights = null; |
5745 |
> |
ForEachTransformedMappingTask<K,V,U> subtasks = null; |
5746 |
|
try { |
5747 |
|
int b = batch(), c; |
5748 |
|
while (b > 1 && baseIndex != baseLimit) { |
5749 |
|
do {} while (!casPending(c = pending, c+1)); |
5750 |
< |
(rights = new ForEachTransformedMappingTask<K,V,U> |
5751 |
< |
(map, this, b >>>= 1, rights, transformer, action)).fork(); |
5750 |
> |
(subtasks = new ForEachTransformedMappingTask<K,V,U> |
5751 |
> |
(map, this, b >>>= 1, subtasks, transformer, action)).fork(); |
5752 |
|
} |
5753 |
|
Object v; U u; |
5754 |
|
while ((v = advance()) != null) { |
5755 |
|
if ((u = transformer.apply((K)nextKey, (V)v)) != null) |
5756 |
|
action.apply(u); |
5757 |
|
} |
5344 |
– |
tryComplete(); |
5758 |
|
} catch (Throwable ex) { |
5759 |
|
return tryCompleteComputation(ex); |
5760 |
|
} |
5761 |
< |
while (rights != null && rights.tryUnfork()) { |
5349 |
< |
rights.exec(); |
5350 |
< |
rights = rights.nextRight; |
5351 |
< |
} |
5761 |
> |
tryComplete(subtasks); |
5762 |
|
return false; |
5763 |
|
} |
5764 |
|
} |
5765 |
|
|
5766 |
|
@SuppressWarnings("serial") static final class SearchKeysTask<K,V,U> |
5767 |
< |
extends BulkTask<K,V,U> { |
5358 |
< |
SearchKeysTask<K,V,U> nextRight; |
5767 |
> |
extends BulkAction<K,V,U> { |
5768 |
|
final Fun<? super K, ? extends U> searchFunction; |
5769 |
|
final AtomicReference<U> result; |
5770 |
|
SearchKeysTask |
5771 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5772 |
< |
SearchKeysTask<K,V,U> nextRight, |
5772 |
> |
SearchKeysTask<K,V,U> nextTask, |
5773 |
|
Fun<? super K, ? extends U> searchFunction, |
5774 |
|
AtomicReference<U> result) { |
5775 |
< |
super(m, p, b); |
5367 |
< |
this.nextRight = nextRight; |
5775 |
> |
super(m, p, b, nextTask); |
5776 |
|
this.searchFunction = searchFunction; this.result = result; |
5777 |
|
} |
5778 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5781 |
|
this.searchFunction; |
5782 |
|
if (searchFunction == null || result == null) |
5783 |
|
return abortOnNullFunction(); |
5784 |
< |
SearchKeysTask<K,V,U> rights = null; |
5784 |
> |
SearchKeysTask<K,V,U> subtasks = null; |
5785 |
|
try { |
5786 |
|
int b = batch(), c; |
5787 |
|
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5788 |
|
do {} while (!casPending(c = pending, c+1)); |
5789 |
< |
(rights = new SearchKeysTask<K,V,U> |
5790 |
< |
(map, this, b >>>= 1, rights, searchFunction, result)).fork(); |
5789 |
> |
(subtasks = new SearchKeysTask<K,V,U> |
5790 |
> |
(map, this, b >>>= 1, subtasks, searchFunction, result)).fork(); |
5791 |
|
} |
5792 |
|
U u; |
5793 |
|
while (result.get() == null && advance() != null) { |
5797 |
|
break; |
5798 |
|
} |
5799 |
|
} |
5392 |
– |
tryComplete(); |
5800 |
|
} catch (Throwable ex) { |
5801 |
|
return tryCompleteComputation(ex); |
5802 |
|
} |
5803 |
< |
while (rights != null && result.get() == null && rights.tryUnfork()) { |
5397 |
< |
rights.exec(); |
5398 |
< |
rights = rights.nextRight; |
5399 |
< |
} |
5803 |
> |
tryComplete(subtasks); |
5804 |
|
return false; |
5805 |
|
} |
5806 |
|
public final U getRawResult() { return result.get(); } |
5807 |
|
} |
5808 |
|
|
5809 |
|
@SuppressWarnings("serial") static final class SearchValuesTask<K,V,U> |
5810 |
< |
extends BulkTask<K,V,U> { |
5407 |
< |
SearchValuesTask<K,V,U> nextRight; |
5810 |
> |
extends BulkAction<K,V,U> { |
5811 |
|
final Fun<? super V, ? extends U> searchFunction; |
5812 |
|
final AtomicReference<U> result; |
5813 |
|
SearchValuesTask |
5814 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5815 |
< |
SearchValuesTask<K,V,U> nextRight, |
5815 |
> |
SearchValuesTask<K,V,U> nextTask, |
5816 |
|
Fun<? super V, ? extends U> searchFunction, |
5817 |
|
AtomicReference<U> result) { |
5818 |
< |
super(m, p, b); |
5416 |
< |
this.nextRight = nextRight; |
5818 |
> |
super(m, p, b, nextTask); |
5819 |
|
this.searchFunction = searchFunction; this.result = result; |
5820 |
|
} |
5821 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5824 |
|
this.searchFunction; |
5825 |
|
if (searchFunction == null || result == null) |
5826 |
|
return abortOnNullFunction(); |
5827 |
< |
SearchValuesTask<K,V,U> rights = null; |
5827 |
> |
SearchValuesTask<K,V,U> subtasks = null; |
5828 |
|
try { |
5829 |
|
int b = batch(), c; |
5830 |
|
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5831 |
|
do {} while (!casPending(c = pending, c+1)); |
5832 |
< |
(rights = new SearchValuesTask<K,V,U> |
5833 |
< |
(map, this, b >>>= 1, rights, searchFunction, result)).fork(); |
5832 |
> |
(subtasks = new SearchValuesTask<K,V,U> |
5833 |
> |
(map, this, b >>>= 1, subtasks, searchFunction, result)).fork(); |
5834 |
|
} |
5835 |
|
Object v; U u; |
5836 |
|
while (result.get() == null && (v = advance()) != null) { |
5840 |
|
break; |
5841 |
|
} |
5842 |
|
} |
5441 |
– |
tryComplete(); |
5843 |
|
} catch (Throwable ex) { |
5844 |
|
return tryCompleteComputation(ex); |
5845 |
|
} |
5846 |
< |
while (rights != null && result.get() == null && rights.tryUnfork()) { |
5446 |
< |
rights.exec(); |
5447 |
< |
rights = rights.nextRight; |
5448 |
< |
} |
5846 |
> |
tryComplete(subtasks); |
5847 |
|
return false; |
5848 |
|
} |
5849 |
|
public final U getRawResult() { return result.get(); } |
5850 |
|
} |
5851 |
|
|
5852 |
|
@SuppressWarnings("serial") static final class SearchEntriesTask<K,V,U> |
5853 |
< |
extends BulkTask<K,V,U> { |
5456 |
< |
SearchEntriesTask<K,V,U> nextRight; |
5853 |
> |
extends BulkAction<K,V,U> { |
5854 |
|
final Fun<Entry<K,V>, ? extends U> searchFunction; |
5855 |
|
final AtomicReference<U> result; |
5856 |
|
SearchEntriesTask |
5857 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5858 |
< |
SearchEntriesTask<K,V,U> nextRight, |
5858 |
> |
SearchEntriesTask<K,V,U> nextTask, |
5859 |
|
Fun<Entry<K,V>, ? extends U> searchFunction, |
5860 |
|
AtomicReference<U> result) { |
5861 |
< |
super(m, p, b); |
5465 |
< |
this.nextRight = nextRight; |
5861 |
> |
super(m, p, b, nextTask); |
5862 |
|
this.searchFunction = searchFunction; this.result = result; |
5863 |
|
} |
5864 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5867 |
|
this.searchFunction; |
5868 |
|
if (searchFunction == null || result == null) |
5869 |
|
return abortOnNullFunction(); |
5870 |
< |
SearchEntriesTask<K,V,U> rights = null; |
5870 |
> |
SearchEntriesTask<K,V,U> subtasks = null; |
5871 |
|
try { |
5872 |
|
int b = batch(), c; |
5873 |
|
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5874 |
|
do {} while (!casPending(c = pending, c+1)); |
5875 |
< |
(rights = new SearchEntriesTask<K,V,U> |
5876 |
< |
(map, this, b >>>= 1, rights, searchFunction, result)).fork(); |
5875 |
> |
(subtasks = new SearchEntriesTask<K,V,U> |
5876 |
> |
(map, this, b >>>= 1, subtasks, searchFunction, result)).fork(); |
5877 |
|
} |
5878 |
|
Object v; U u; |
5879 |
|
while (result.get() == null && (v = advance()) != null) { |
5883 |
|
break; |
5884 |
|
} |
5885 |
|
} |
5490 |
– |
tryComplete(); |
5886 |
|
} catch (Throwable ex) { |
5887 |
|
return tryCompleteComputation(ex); |
5888 |
|
} |
5889 |
< |
while (rights != null && result.get() == null && rights.tryUnfork()) { |
5495 |
< |
rights.exec(); |
5496 |
< |
rights = rights.nextRight; |
5497 |
< |
} |
5889 |
> |
tryComplete(subtasks); |
5890 |
|
return false; |
5891 |
|
} |
5892 |
|
public final U getRawResult() { return result.get(); } |
5893 |
|
} |
5894 |
|
|
5895 |
|
@SuppressWarnings("serial") static final class SearchMappingsTask<K,V,U> |
5896 |
< |
extends BulkTask<K,V,U> { |
5505 |
< |
SearchMappingsTask<K,V,U> nextRight; |
5896 |
> |
extends BulkAction<K,V,U> { |
5897 |
|
final BiFun<? super K, ? super V, ? extends U> searchFunction; |
5898 |
|
final AtomicReference<U> result; |
5899 |
|
SearchMappingsTask |
5900 |
|
(ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b, |
5901 |
< |
SearchMappingsTask<K,V,U> nextRight, |
5901 |
> |
SearchMappingsTask<K,V,U> nextTask, |
5902 |
|
BiFun<? super K, ? super V, ? extends U> searchFunction, |
5903 |
|
AtomicReference<U> result) { |
5904 |
< |
super(m, p, b); |
5514 |
< |
this.nextRight = nextRight; |
5904 |
> |
super(m, p, b, nextTask); |
5905 |
|
this.searchFunction = searchFunction; this.result = result; |
5906 |
|
} |
5907 |
|
@SuppressWarnings("unchecked") public final boolean exec() { |
5910 |
|
this.searchFunction; |
5911 |
|
if (searchFunction == null || result == null) |
5912 |
|
return abortOnNullFunction(); |
5913 |
< |
SearchMappingsTask<K,V,U> rights = null; |
5913 |
> |
SearchMappingsTask<K,V,U> subtasks = null; |
5914 |
|
try { |
5915 |
|
int b = batch(), c; |
5916 |
|
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5917 |
|
do {} while (!casPending(c = pending, c+1)); |
5918 |
< |
(rights = new SearchMappingsTask<K,V,U> |
5919 |
< |
(map, this, b >>>= 1, rights, searchFunction, result)).fork(); |
5918 |
> |
(subtasks = new SearchMappingsTask<K,V,U> |
5919 |
> |
(map, this, b >>>= 1, subtasks, searchFunction, result)).fork(); |
5920 |
|
} |
5921 |
|
Object v; U u; |
5922 |
|
while (result.get() == null && (v = advance()) != null) { |
5926 |
|
break; |
5927 |
|
} |
5928 |
|
} |
5539 |
– |
tryComplete(); |
5929 |
|
} catch (Throwable ex) { |
5930 |
|
return tryCompleteComputation(ex); |
5931 |
|
} |
5932 |
< |
while (rights != null && result.get() == null && rights.tryUnfork()) { |
5544 |
< |
rights.exec(); |
5545 |
< |
rights = rights.nextRight; |
5546 |
< |
} |
5932 |
> |
tryComplete(subtasks); |
5933 |
|
return false; |
5934 |
|
} |
5935 |
|
public final U getRawResult() { return result.get(); } |
5984 |
|
} catch (Throwable ex) { |
5985 |
|
return tryCompleteComputation(ex); |
5986 |
|
} |
5987 |
< |
for (ReduceKeysTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
5988 |
< |
s.exec(); |
5987 |
> |
ReduceKeysTask<K,V> s = rights; |
5988 |
> |
if (s != null && !inForkJoinPool()) { |
5989 |
> |
do { |
5990 |
> |
if (s.tryUnfork()) |
5991 |
> |
s.exec(); |
5992 |
> |
} while ((s = s.nextRight) != null); |
5993 |
> |
} |
5994 |
|
return false; |
5995 |
|
} |
5996 |
|
public final K getRawResult() { return result; } |
6046 |
|
} catch (Throwable ex) { |
6047 |
|
return tryCompleteComputation(ex); |
6048 |
|
} |
6049 |
< |
for (ReduceValuesTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6050 |
< |
s.exec(); |
6049 |
> |
ReduceValuesTask<K,V> s = rights; |
6050 |
> |
if (s != null && !inForkJoinPool()) { |
6051 |
> |
do { |
6052 |
> |
if (s.tryUnfork()) |
6053 |
> |
s.exec(); |
6054 |
> |
} while ((s = s.nextRight) != null); |
6055 |
> |
} |
6056 |
|
return false; |
6057 |
|
} |
6058 |
|
public final V getRawResult() { return result; } |
6108 |
|
} catch (Throwable ex) { |
6109 |
|
return tryCompleteComputation(ex); |
6110 |
|
} |
6111 |
< |
for (ReduceEntriesTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6112 |
< |
s.exec(); |
6111 |
> |
ReduceEntriesTask<K,V> s = rights; |
6112 |
> |
if (s != null && !inForkJoinPool()) { |
6113 |
> |
do { |
6114 |
> |
if (s.tryUnfork()) |
6115 |
> |
s.exec(); |
6116 |
> |
} while ((s = s.nextRight) != null); |
6117 |
> |
} |
6118 |
|
return false; |
6119 |
|
} |
6120 |
|
public final Map.Entry<K,V> getRawResult() { return result; } |
6174 |
|
} catch (Throwable ex) { |
6175 |
|
return tryCompleteComputation(ex); |
6176 |
|
} |
6177 |
< |
for (MapReduceKeysTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6178 |
< |
s.exec(); |
6177 |
> |
MapReduceKeysTask<K,V,U> s = rights; |
6178 |
> |
if (s != null && !inForkJoinPool()) { |
6179 |
> |
do { |
6180 |
> |
if (s.tryUnfork()) |
6181 |
> |
s.exec(); |
6182 |
> |
} while ((s = s.nextRight) != null); |
6183 |
> |
} |
6184 |
|
return false; |
6185 |
|
} |
6186 |
|
public final U getRawResult() { return result; } |
6241 |
|
} catch (Throwable ex) { |
6242 |
|
return tryCompleteComputation(ex); |
6243 |
|
} |
6244 |
< |
for (MapReduceValuesTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6245 |
< |
s.exec(); |
6244 |
> |
MapReduceValuesTask<K,V,U> s = rights; |
6245 |
> |
if (s != null && !inForkJoinPool()) { |
6246 |
> |
do { |
6247 |
> |
if (s.tryUnfork()) |
6248 |
> |
s.exec(); |
6249 |
> |
} while ((s = s.nextRight) != null); |
6250 |
> |
} |
6251 |
|
return false; |
6252 |
|
} |
6253 |
|
public final U getRawResult() { return result; } |
6308 |
|
} catch (Throwable ex) { |
6309 |
|
return tryCompleteComputation(ex); |
6310 |
|
} |
6311 |
< |
for (MapReduceEntriesTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6312 |
< |
s.exec(); |
6311 |
> |
MapReduceEntriesTask<K,V,U> s = rights; |
6312 |
> |
if (s != null && !inForkJoinPool()) { |
6313 |
> |
do { |
6314 |
> |
if (s.tryUnfork()) |
6315 |
> |
s.exec(); |
6316 |
> |
} while ((s = s.nextRight) != null); |
6317 |
> |
} |
6318 |
|
return false; |
6319 |
|
} |
6320 |
|
public final U getRawResult() { return result; } |
6375 |
|
} catch (Throwable ex) { |
6376 |
|
return tryCompleteComputation(ex); |
6377 |
|
} |
6378 |
< |
for (MapReduceMappingsTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6379 |
< |
s.exec(); |
6378 |
> |
MapReduceMappingsTask<K,V,U> s = rights; |
6379 |
> |
if (s != null && !inForkJoinPool()) { |
6380 |
> |
do { |
6381 |
> |
if (s.tryUnfork()) |
6382 |
> |
s.exec(); |
6383 |
> |
} while ((s = s.nextRight) != null); |
6384 |
> |
} |
6385 |
|
return false; |
6386 |
|
} |
6387 |
|
public final U getRawResult() { return result; } |
6440 |
|
} catch (Throwable ex) { |
6441 |
|
return tryCompleteComputation(ex); |
6442 |
|
} |
6443 |
< |
for (MapReduceKeysToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6444 |
< |
s.exec(); |
6443 |
> |
MapReduceKeysToDoubleTask<K,V> s = rights; |
6444 |
> |
if (s != null && !inForkJoinPool()) { |
6445 |
> |
do { |
6446 |
> |
if (s.tryUnfork()) |
6447 |
> |
s.exec(); |
6448 |
> |
} while ((s = s.nextRight) != null); |
6449 |
> |
} |
6450 |
|
return false; |
6451 |
|
} |
6452 |
|
public final Double getRawResult() { return result; } |
6506 |
|
} catch (Throwable ex) { |
6507 |
|
return tryCompleteComputation(ex); |
6508 |
|
} |
6509 |
< |
for (MapReduceValuesToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6510 |
< |
s.exec(); |
6509 |
> |
MapReduceValuesToDoubleTask<K,V> s = rights; |
6510 |
> |
if (s != null && !inForkJoinPool()) { |
6511 |
> |
do { |
6512 |
> |
if (s.tryUnfork()) |
6513 |
> |
s.exec(); |
6514 |
> |
} while ((s = s.nextRight) != null); |
6515 |
> |
} |
6516 |
|
return false; |
6517 |
|
} |
6518 |
|
public final Double getRawResult() { return result; } |
6572 |
|
} catch (Throwable ex) { |
6573 |
|
return tryCompleteComputation(ex); |
6574 |
|
} |
6575 |
< |
for (MapReduceEntriesToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6576 |
< |
s.exec(); |
6575 |
> |
MapReduceEntriesToDoubleTask<K,V> s = rights; |
6576 |
> |
if (s != null && !inForkJoinPool()) { |
6577 |
> |
do { |
6578 |
> |
if (s.tryUnfork()) |
6579 |
> |
s.exec(); |
6580 |
> |
} while ((s = s.nextRight) != null); |
6581 |
> |
} |
6582 |
|
return false; |
6583 |
|
} |
6584 |
|
public final Double getRawResult() { return result; } |
6638 |
|
} catch (Throwable ex) { |
6639 |
|
return tryCompleteComputation(ex); |
6640 |
|
} |
6641 |
< |
for (MapReduceMappingsToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6642 |
< |
s.exec(); |
6641 |
> |
MapReduceMappingsToDoubleTask<K,V> s = rights; |
6642 |
> |
if (s != null && !inForkJoinPool()) { |
6643 |
> |
do { |
6644 |
> |
if (s.tryUnfork()) |
6645 |
> |
s.exec(); |
6646 |
> |
} while ((s = s.nextRight) != null); |
6647 |
> |
} |
6648 |
|
return false; |
6649 |
|
} |
6650 |
|
public final Double getRawResult() { return result; } |
6703 |
|
} catch (Throwable ex) { |
6704 |
|
return tryCompleteComputation(ex); |
6705 |
|
} |
6706 |
< |
for (MapReduceKeysToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6707 |
< |
s.exec(); |
6706 |
> |
MapReduceKeysToLongTask<K,V> s = rights; |
6707 |
> |
if (s != null && !inForkJoinPool()) { |
6708 |
> |
do { |
6709 |
> |
if (s.tryUnfork()) |
6710 |
> |
s.exec(); |
6711 |
> |
} while ((s = s.nextRight) != null); |
6712 |
> |
} |
6713 |
|
return false; |
6714 |
|
} |
6715 |
|
public final Long getRawResult() { return result; } |
6769 |
|
} catch (Throwable ex) { |
6770 |
|
return tryCompleteComputation(ex); |
6771 |
|
} |
6772 |
< |
for (MapReduceValuesToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6773 |
< |
s.exec(); |
6772 |
> |
MapReduceValuesToLongTask<K,V> s = rights; |
6773 |
> |
if (s != null && !inForkJoinPool()) { |
6774 |
> |
do { |
6775 |
> |
if (s.tryUnfork()) |
6776 |
> |
s.exec(); |
6777 |
> |
} while ((s = s.nextRight) != null); |
6778 |
> |
} |
6779 |
|
return false; |
6780 |
|
} |
6781 |
|
public final Long getRawResult() { return result; } |
6835 |
|
} catch (Throwable ex) { |
6836 |
|
return tryCompleteComputation(ex); |
6837 |
|
} |
6838 |
< |
for (MapReduceEntriesToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6839 |
< |
s.exec(); |
6838 |
> |
MapReduceEntriesToLongTask<K,V> s = rights; |
6839 |
> |
if (s != null && !inForkJoinPool()) { |
6840 |
> |
do { |
6841 |
> |
if (s.tryUnfork()) |
6842 |
> |
s.exec(); |
6843 |
> |
} while ((s = s.nextRight) != null); |
6844 |
> |
} |
6845 |
|
return false; |
6846 |
|
} |
6847 |
|
public final Long getRawResult() { return result; } |
6901 |
|
} catch (Throwable ex) { |
6902 |
|
return tryCompleteComputation(ex); |
6903 |
|
} |
6904 |
< |
for (MapReduceMappingsToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6905 |
< |
s.exec(); |
6904 |
> |
MapReduceMappingsToLongTask<K,V> s = rights; |
6905 |
> |
if (s != null && !inForkJoinPool()) { |
6906 |
> |
do { |
6907 |
> |
if (s.tryUnfork()) |
6908 |
> |
s.exec(); |
6909 |
> |
} while ((s = s.nextRight) != null); |
6910 |
> |
} |
6911 |
|
return false; |
6912 |
|
} |
6913 |
|
public final Long getRawResult() { return result; } |
6966 |
|
} catch (Throwable ex) { |
6967 |
|
return tryCompleteComputation(ex); |
6968 |
|
} |
6969 |
< |
for (MapReduceKeysToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
6970 |
< |
s.exec(); |
6969 |
> |
MapReduceKeysToIntTask<K,V> s = rights; |
6970 |
> |
if (s != null && !inForkJoinPool()) { |
6971 |
> |
do { |
6972 |
> |
if (s.tryUnfork()) |
6973 |
> |
s.exec(); |
6974 |
> |
} while ((s = s.nextRight) != null); |
6975 |
> |
} |
6976 |
|
return false; |
6977 |
|
} |
6978 |
|
public final Integer getRawResult() { return result; } |
7032 |
|
} catch (Throwable ex) { |
7033 |
|
return tryCompleteComputation(ex); |
7034 |
|
} |
7035 |
< |
for (MapReduceValuesToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
7036 |
< |
s.exec(); |
7035 |
> |
MapReduceValuesToIntTask<K,V> s = rights; |
7036 |
> |
if (s != null && !inForkJoinPool()) { |
7037 |
> |
do { |
7038 |
> |
if (s.tryUnfork()) |
7039 |
> |
s.exec(); |
7040 |
> |
} while ((s = s.nextRight) != null); |
7041 |
> |
} |
7042 |
|
return false; |
7043 |
|
} |
7044 |
|
public final Integer getRawResult() { return result; } |
7098 |
|
} catch (Throwable ex) { |
7099 |
|
return tryCompleteComputation(ex); |
7100 |
|
} |
7101 |
< |
for (MapReduceEntriesToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
7102 |
< |
s.exec(); |
7101 |
> |
MapReduceEntriesToIntTask<K,V> s = rights; |
7102 |
> |
if (s != null && !inForkJoinPool()) { |
7103 |
> |
do { |
7104 |
> |
if (s.tryUnfork()) |
7105 |
> |
s.exec(); |
7106 |
> |
} while ((s = s.nextRight) != null); |
7107 |
> |
} |
7108 |
|
return false; |
7109 |
|
} |
7110 |
|
public final Integer getRawResult() { return result; } |
7164 |
|
} catch (Throwable ex) { |
7165 |
|
return tryCompleteComputation(ex); |
7166 |
|
} |
7167 |
< |
for (MapReduceMappingsToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight) |
7168 |
< |
s.exec(); |
7167 |
> |
MapReduceMappingsToIntTask<K,V> s = rights; |
7168 |
> |
if (s != null && !inForkJoinPool()) { |
7169 |
> |
do { |
7170 |
> |
if (s.tryUnfork()) |
7171 |
> |
s.exec(); |
7172 |
> |
} while ((s = s.nextRight) != null); |
7173 |
> |
} |
7174 |
|
return false; |
7175 |
|
} |
7176 |
|
public final Integer getRawResult() { return result; } |