47 |
|
* block, so may overlap with update operations (including {@code put} |
48 |
|
* and {@code remove}). Retrievals reflect the results of the most |
49 |
|
* recently <em>completed</em> update operations holding upon their |
50 |
< |
* onset. For aggregate operations such as {@code putAll} and {@code |
51 |
< |
* clear}, concurrent retrievals may reflect insertion or removal of |
52 |
< |
* only some entries. Similarly, Iterators and Enumerations return |
53 |
< |
* elements reflecting the state of the hash table at some point at or |
54 |
< |
* since the creation of the iterator/enumeration. They do |
55 |
< |
* <em>not</em> throw {@link ConcurrentModificationException}. |
56 |
< |
* However, iterators are designed to be used by only one thread at a |
57 |
< |
* time. Bear in mind that the results of aggregate status methods |
58 |
< |
* including {@code size}, {@code isEmpty}, and {@code containsValue} |
59 |
< |
* are typically useful only when a map is not undergoing concurrent |
60 |
< |
* updates in other threads. Otherwise the results of these methods |
61 |
< |
* reflect transient states that may be adequate for monitoring |
62 |
< |
* or estimation purposes, but not for program control. |
50 |
> |
* onset. (More formally, an update operation for a given key bears a |
51 |
> |
* <em>happens-before</em> relation with any (non-null) retrieval for |
52 |
> |
* that key reporting the updated value.) For aggregate operations |
53 |
> |
* such as {@code putAll} and {@code clear}, concurrent retrievals may |
54 |
> |
* reflect insertion or removal of only some entries. Similarly, |
55 |
> |
* Iterators and Enumerations return elements reflecting the state of |
56 |
> |
* the hash table at some point at or since the creation of the |
57 |
> |
* iterator/enumeration. They do <em>not</em> throw {@link |
58 |
> |
* ConcurrentModificationException}. However, iterators are designed |
59 |
> |
* to be used by only one thread at a time. Bear in mind that the |
60 |
> |
* results of aggregate status methods including {@code size}, {@code |
61 |
> |
* isEmpty}, and {@code containsValue} are typically useful only when |
62 |
> |
* a map is not undergoing concurrent updates in other threads. |
63 |
> |
* Otherwise the results of these methods reflect transient states |
64 |
> |
* that may be adequate for monitoring or estimation purposes, but not |
65 |
> |
* for program control. |
66 |
|
* |
67 |
|
* <p> The table is dynamically expanded when there are too many |
68 |
|
* collisions (i.e., keys that have distinct hash codes but fall into |
540 |
|
* unlocking lock (via a failed CAS from non-waiting LOCKED |
541 |
|
* state), unlockers acquire the sync lock and perform a |
542 |
|
* notifyAll. |
543 |
+ |
* |
544 |
+ |
* The initial sanity check on tab and bounds is not currently |
545 |
+ |
* necessary in the only usages of this method, but enables |
546 |
+ |
* use in other future contexts. |
547 |
|
*/ |
548 |
|
final void tryAwaitLock(Node[] tab, int i) { |
549 |
< |
if (tab != null && i >= 0 && i < tab.length) { // bounds check |
549 |
> |
if (tab != null && i >= 0 && i < tab.length) { // sanity check |
550 |
|
int r = ThreadLocalRandom.current().nextInt(); // randomize spins |
551 |
|
int spins = MAX_SPINS, h; |
552 |
|
while (tabAt(tab, i) == this && ((h = hash) & LOCKED) != 0) { |
722 |
|
* Returns the TreeNode (or null if not found) for the given key |
723 |
|
* starting at given root. |
724 |
|
*/ |
725 |
< |
@SuppressWarnings("unchecked") // suppress Comparable cast warning |
726 |
< |
final TreeNode getTreeNode(int h, Object k, TreeNode p) { |
725 |
> |
@SuppressWarnings("unchecked") final TreeNode getTreeNode |
726 |
> |
(int h, Object k, TreeNode p) { |
727 |
|
Class<?> c = k.getClass(); |
728 |
|
while (p != null) { |
729 |
|
int dir, ph; Object pk; Class<?> pc; |
783 |
|
* Finds or adds a node. |
784 |
|
* @return null if added |
785 |
|
*/ |
786 |
< |
@SuppressWarnings("unchecked") // suppress Comparable cast warning |
787 |
< |
final TreeNode putTreeNode(int h, Object k, Object v) { |
786 |
> |
@SuppressWarnings("unchecked") final TreeNode putTreeNode |
787 |
> |
(int h, Object k, Object v) { |
788 |
|
Class<?> c = k.getClass(); |
789 |
|
TreeNode pp = root, p = null; |
790 |
|
int dir = 0; |
1211 |
|
} |
1212 |
|
|
1213 |
|
/* |
1214 |
< |
* Internal versions of the five insertion methods, each a |
1214 |
> |
* Internal versions of the six insertion methods, each a |
1215 |
|
* little more complicated than the last. All have |
1216 |
|
* the same basic structure as the first (internalPut): |
1217 |
|
* 1. If table uninitialized, create |
1229 |
|
* returns from function call. |
1230 |
|
* * compute uses the same function-call mechanics, but without |
1231 |
|
* the prescans |
1232 |
+ |
* * merge acts as putIfAbsent in the absent case, but invokes the |
1233 |
+ |
* update function if present |
1234 |
|
* * putAll attempts to pre-allocate enough table space |
1235 |
|
* and more lazily performs count updates and checks. |
1236 |
|
* |
1554 |
|
} |
1555 |
|
|
1556 |
|
/** Implementation for compute */ |
1557 |
< |
@SuppressWarnings("unchecked") |
1558 |
< |
private final Object internalCompute(K k, boolean onlyIfPresent, |
1550 |
< |
BiFun<? super K, ? super V, ? extends V> mf) { |
1557 |
> |
@SuppressWarnings("unchecked") private final Object internalCompute |
1558 |
> |
(K k, boolean onlyIfPresent, BiFun<? super K, ? super V, ? extends V> mf) { |
1559 |
|
int h = spread(k.hashCode()); |
1560 |
|
Object val = null; |
1561 |
|
int delta = 0; |
1678 |
|
return val; |
1679 |
|
} |
1680 |
|
|
1681 |
< |
private final Object internalMerge(K k, V v, |
1682 |
< |
BiFun<? super V, ? super V, ? extends V> mf) { |
1681 |
> |
/** Implementation for merge */ |
1682 |
> |
@SuppressWarnings("unchecked") private final Object internalMerge |
1683 |
> |
(K k, V v, BiFun<? super V, ? super V, ? extends V> mf) { |
1684 |
|
int h = spread(k.hashCode()); |
1685 |
|
Object val = null; |
1686 |
|
int delta = 0; |
2010 |
|
for (int i = bin;;) { // start upwards sweep |
2011 |
|
int fh; Node f; |
2012 |
|
if ((f = tabAt(tab, i)) == null) { |
2013 |
< |
if (bin >= 0) { // no lock needed (or available) |
2013 |
> |
if (bin >= 0) { // Unbuffered; no lock needed (or available) |
2014 |
|
if (!casTabAt(tab, i, f, fwd)) |
2015 |
|
continue; |
2016 |
|
} |
2186 |
|
try { |
2187 |
|
if (tabAt(tab, i) == f) { |
2188 |
|
for (Node p = t.first; p != null; p = p.next) { |
2189 |
< |
p.val = null; |
2190 |
< |
--delta; |
2189 |
> |
if (p.val != null) { // (currently always true) |
2190 |
> |
p.val = null; |
2191 |
> |
--delta; |
2192 |
> |
} |
2193 |
|
} |
2194 |
|
t.first = null; |
2195 |
|
t.root = null; |
2211 |
|
try { |
2212 |
|
if (tabAt(tab, i) == f) { |
2213 |
|
for (Node e = f; e != null; e = e.next) { |
2214 |
< |
e.val = null; |
2215 |
< |
--delta; |
2214 |
> |
if (e.val != null) { // (currently always true) |
2215 |
> |
e.val = null; |
2216 |
> |
--delta; |
2217 |
> |
} |
2218 |
|
} |
2219 |
|
setTabAt(tab, i, null); |
2220 |
|
++i; |
2235 |
|
|
2236 |
|
/** |
2237 |
|
* Encapsulates traversal for methods such as containsValue; also |
2238 |
< |
* serves as a base class for other iterators. |
2238 |
> |
* serves as a base class for other iterators and bulk tasks. |
2239 |
|
* |
2240 |
|
* At each step, the iterator snapshots the key ("nextKey") and |
2241 |
|
* value ("nextVal") of a valid node (i.e., one that, at point of |
2273 |
|
* This class extends ForkJoinTask to streamline parallel |
2274 |
|
* iteration in bulk operations (see BulkTask). This adds only an |
2275 |
|
* int of space overhead, which is close enough to negligible in |
2276 |
< |
* cases where it is not needed to not worry about it. |
2276 |
> |
* cases where it is not needed to not worry about it. Because |
2277 |
> |
* ForkJoinTask is Serializable, but iterators need not be, we |
2278 |
> |
* need to add warning suppressions. |
2279 |
|
*/ |
2280 |
< |
static class Traverser<K,V,R> extends ForkJoinTask<R> { |
2280 |
> |
@SuppressWarnings("serial") static class Traverser<K,V,R> extends ForkJoinTask<R> { |
2281 |
|
final ConcurrentHashMapV8<K, V> map; |
2282 |
|
Node next; // the next entry to use |
2283 |
|
Node last; // the last entry used |
2296 |
|
} |
2297 |
|
|
2298 |
|
/** Creates iterator for split() methods */ |
2299 |
< |
Traverser(Traverser<K,V,?> it, boolean split) { |
2299 |
> |
Traverser(Traverser<K,V,?> it) { |
2300 |
|
this.map = it.map; |
2301 |
|
this.tab = it.tab; |
2302 |
|
this.baseSize = it.baseSize; |
2303 |
< |
int lo = it.baseIndex; |
2304 |
< |
int hi = this.baseLimit = it.baseLimit; |
2290 |
< |
int i; |
2291 |
< |
if (split) // adjust parent |
2292 |
< |
i = it.baseLimit = (lo + hi + 1) >>> 1; |
2293 |
< |
else // clone parent |
2294 |
< |
i = lo; |
2295 |
< |
this.index = this.baseIndex = i; |
2303 |
> |
it.baseLimit = this.index = this.baseIndex = |
2304 |
> |
((this.baseLimit = it.baseLimit) + it.baseIndex + 1) >>> 1; |
2305 |
|
} |
2306 |
|
|
2307 |
|
/** |
2467 |
|
* instead of {@link #size} because a ConcurrentHashMap may |
2468 |
|
* contain more mappings than can be represented as an int. The |
2469 |
|
* value returned is a snapshot; the actual count may differ if |
2470 |
< |
* there are ongoing concurrent insertions of removals. |
2470 |
> |
* there are ongoing concurrent insertions or removals. |
2471 |
|
* |
2472 |
|
* @return the number of mappings |
2473 |
|
*/ |
2474 |
|
public long mappingCount() { |
2475 |
|
long n = counter.sum(); |
2476 |
< |
return (n < 0L) ? 0L : n; |
2476 |
> |
return (n < 0L) ? 0L : n; // ignore transient negative values |
2477 |
|
} |
2478 |
|
|
2479 |
|
/** |
2487 |
|
* |
2488 |
|
* @throws NullPointerException if the specified key is null |
2489 |
|
*/ |
2490 |
< |
@SuppressWarnings("unchecked") |
2482 |
< |
public V get(Object key) { |
2490 |
> |
@SuppressWarnings("unchecked") public V get(Object key) { |
2491 |
|
if (key == null) |
2492 |
|
throw new NullPointerException(); |
2493 |
|
return (V)internalGet(key); |
2494 |
|
} |
2495 |
|
|
2496 |
|
/** |
2497 |
+ |
* Returns the value to which the specified key is mapped, |
2498 |
+ |
* or the gieven defaultValue if this map contains no mapping for the key. |
2499 |
+ |
* |
2500 |
+ |
* @param key the key |
2501 |
+ |
* @param defaultValue the value to return if this map contains |
2502 |
+ |
* no mapping for the given key. |
2503 |
+ |
* @return the mapping for the key, if present; else the defaultValue |
2504 |
+ |
* @throws NullPointerException if the specified key is null |
2505 |
+ |
*/ |
2506 |
+ |
@SuppressWarnings("unchecked") public V getValueOrDefault(Object key, V defaultValue) { |
2507 |
+ |
if (key == null) |
2508 |
+ |
throw new NullPointerException(); |
2509 |
+ |
V v = (V) internalGet(key); |
2510 |
+ |
return v == null ? defaultValue : v; |
2511 |
+ |
} |
2512 |
+ |
|
2513 |
+ |
/** |
2514 |
|
* Tests if the specified object is a key in this table. |
2515 |
|
* |
2516 |
|
* @param key possible key |
2579 |
|
* {@code null} if there was no mapping for {@code key} |
2580 |
|
* @throws NullPointerException if the specified key or value is null |
2581 |
|
*/ |
2582 |
< |
@SuppressWarnings("unchecked") |
2558 |
< |
public V put(K key, V value) { |
2582 |
> |
@SuppressWarnings("unchecked") public V put(K key, V value) { |
2583 |
|
if (key == null || value == null) |
2584 |
|
throw new NullPointerException(); |
2585 |
|
return (V)internalPut(key, value); |
2592 |
|
* or {@code null} if there was no mapping for the key |
2593 |
|
* @throws NullPointerException if the specified key or value is null |
2594 |
|
*/ |
2595 |
< |
@SuppressWarnings("unchecked") |
2572 |
< |
public V putIfAbsent(K key, V value) { |
2595 |
> |
@SuppressWarnings("unchecked") public V putIfAbsent(K key, V value) { |
2596 |
|
if (key == null || value == null) |
2597 |
|
throw new NullPointerException(); |
2598 |
|
return (V)internalPutIfAbsent(key, value); |
2648 |
|
* @throws RuntimeException or Error if the mappingFunction does so, |
2649 |
|
* in which case the mapping is left unestablished |
2650 |
|
*/ |
2651 |
< |
@SuppressWarnings("unchecked") |
2652 |
< |
public V computeIfAbsent(K key, Fun<? super K, ? extends V> mappingFunction) { |
2651 |
> |
@SuppressWarnings("unchecked") public V computeIfAbsent |
2652 |
> |
(K key, Fun<? super K, ? extends V> mappingFunction) { |
2653 |
|
if (key == null || mappingFunction == null) |
2654 |
|
throw new NullPointerException(); |
2655 |
|
return (V)internalComputeIfAbsent(key, mappingFunction); |
2689 |
|
* @throws RuntimeException or Error if the remappingFunction does so, |
2690 |
|
* in which case the mapping is unchanged |
2691 |
|
*/ |
2692 |
< |
public V computeIfPresent(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) { |
2692 |
> |
@SuppressWarnings("unchecked") public V computeIfPresent |
2693 |
> |
(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) { |
2694 |
|
if (key == null || remappingFunction == null) |
2695 |
|
throw new NullPointerException(); |
2696 |
|
return (V)internalCompute(key, true, remappingFunction); |
2736 |
|
* @throws RuntimeException or Error if the remappingFunction does so, |
2737 |
|
* in which case the mapping is unchanged |
2738 |
|
*/ |
2739 |
< |
// @SuppressWarnings("unchecked") |
2740 |
< |
public V compute(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) { |
2739 |
> |
@SuppressWarnings("unchecked") public V compute |
2740 |
> |
(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) { |
2741 |
|
if (key == null || remappingFunction == null) |
2742 |
|
throw new NullPointerException(); |
2743 |
|
return (V)internalCompute(key, false, remappingFunction); |
2768 |
|
* so the computation should be short and simple, and must not |
2769 |
|
* attempt to update any other mappings of this Map. |
2770 |
|
*/ |
2771 |
< |
// @SuppressWarnings("unchecked") |
2772 |
< |
public V merge(K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) { |
2771 |
> |
@SuppressWarnings("unchecked") public V merge |
2772 |
> |
(K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) { |
2773 |
|
if (key == null || value == null || remappingFunction == null) |
2774 |
|
throw new NullPointerException(); |
2775 |
|
return (V)internalMerge(key, value, remappingFunction); |
2784 |
|
* {@code null} if there was no mapping for {@code key} |
2785 |
|
* @throws NullPointerException if the specified key is null |
2786 |
|
*/ |
2787 |
< |
@SuppressWarnings("unchecked") |
2764 |
< |
public V remove(Object key) { |
2787 |
> |
@SuppressWarnings("unchecked") public V remove(Object key) { |
2788 |
|
if (key == null) |
2789 |
|
throw new NullPointerException(); |
2790 |
|
return (V)internalReplace(key, null, null); |
2821 |
|
* or {@code null} if there was no mapping for the key |
2822 |
|
* @throws NullPointerException if the specified key or value is null |
2823 |
|
*/ |
2824 |
< |
@SuppressWarnings("unchecked") |
2802 |
< |
public V replace(K key, V value) { |
2824 |
> |
@SuppressWarnings("unchecked") public V replace(K key, V value) { |
2825 |
|
if (key == null || value == null) |
2826 |
|
throw new NullPointerException(); |
2827 |
|
return (V)internalReplace(key, value, null); |
3027 |
|
|
3028 |
|
/* ----------------Iterators -------------- */ |
3029 |
|
|
3030 |
< |
static final class KeyIterator<K,V> extends Traverser<K,V,Object> |
3030 |
> |
@SuppressWarnings("serial") static final class KeyIterator<K,V> extends Traverser<K,V,Object> |
3031 |
|
implements Spliterator<K>, Enumeration<K> { |
3032 |
|
KeyIterator(ConcurrentHashMapV8<K, V> map) { super(map); } |
3033 |
< |
KeyIterator(Traverser<K,V,Object> it, boolean split) { |
3034 |
< |
super(it, split); |
3033 |
> |
KeyIterator(Traverser<K,V,Object> it) { |
3034 |
> |
super(it); |
3035 |
|
} |
3036 |
|
public KeyIterator<K,V> split() { |
3037 |
|
if (last != null || (next != null && nextVal == null)) |
3038 |
|
throw new IllegalStateException(); |
3039 |
< |
return new KeyIterator<K,V>(this, true); |
3039 |
> |
return new KeyIterator<K,V>(this); |
3040 |
|
} |
3041 |
< |
@SuppressWarnings("unchecked") |
3020 |
< |
public final K next() { |
3041 |
> |
@SuppressWarnings("unchecked") public final K next() { |
3042 |
|
if (nextVal == null && advance() == null) |
3043 |
|
throw new NoSuchElementException(); |
3044 |
|
Object k = nextKey; |
3049 |
|
public final K nextElement() { return next(); } |
3050 |
|
} |
3051 |
|
|
3052 |
< |
static final class ValueIterator<K,V> extends Traverser<K,V,Object> |
3052 |
> |
@SuppressWarnings("serial") static final class ValueIterator<K,V> extends Traverser<K,V,Object> |
3053 |
|
implements Spliterator<V>, Enumeration<V> { |
3054 |
|
ValueIterator(ConcurrentHashMapV8<K, V> map) { super(map); } |
3055 |
< |
ValueIterator(Traverser<K,V,Object> it, boolean split) { |
3056 |
< |
super(it, split); |
3055 |
> |
ValueIterator(Traverser<K,V,Object> it) { |
3056 |
> |
super(it); |
3057 |
|
} |
3058 |
|
public ValueIterator<K,V> split() { |
3059 |
|
if (last != null || (next != null && nextVal == null)) |
3060 |
|
throw new IllegalStateException(); |
3061 |
< |
return new ValueIterator<K,V>(this, true); |
3061 |
> |
return new ValueIterator<K,V>(this); |
3062 |
|
} |
3063 |
|
|
3064 |
< |
@SuppressWarnings("unchecked") |
3044 |
< |
public final V next() { |
3064 |
> |
@SuppressWarnings("unchecked") public final V next() { |
3065 |
|
Object v; |
3066 |
|
if ((v = nextVal) == null && (v = advance()) == null) |
3067 |
|
throw new NoSuchElementException(); |
3072 |
|
public final V nextElement() { return next(); } |
3073 |
|
} |
3074 |
|
|
3075 |
< |
static final class EntryIterator<K,V> extends Traverser<K,V,Object> |
3075 |
> |
@SuppressWarnings("serial") static final class EntryIterator<K,V> extends Traverser<K,V,Object> |
3076 |
|
implements Spliterator<Map.Entry<K,V>> { |
3077 |
|
EntryIterator(ConcurrentHashMapV8<K, V> map) { super(map); } |
3078 |
< |
EntryIterator(Traverser<K,V,Object> it, boolean split) { |
3079 |
< |
super(it, split); |
3078 |
> |
EntryIterator(Traverser<K,V,Object> it) { |
3079 |
> |
super(it); |
3080 |
|
} |
3081 |
|
public EntryIterator<K,V> split() { |
3082 |
|
if (last != null || (next != null && nextVal == null)) |
3083 |
|
throw new IllegalStateException(); |
3084 |
< |
return new EntryIterator<K,V>(this, true); |
3084 |
> |
return new EntryIterator<K,V>(this); |
3085 |
|
} |
3086 |
|
|
3087 |
< |
@SuppressWarnings("unchecked") |
3068 |
< |
public final Map.Entry<K,V> next() { |
3087 |
> |
@SuppressWarnings("unchecked") public final Map.Entry<K,V> next() { |
3088 |
|
Object v; |
3089 |
|
if ((v = nextVal) == null && (v = advance()) == null) |
3090 |
|
throw new NoSuchElementException(); |
3179 |
|
return (i == n) ? r : Arrays.copyOf(r, i); |
3180 |
|
} |
3181 |
|
|
3182 |
< |
@SuppressWarnings("unchecked") |
3164 |
< |
public final <T> T[] toArray(T[] a) { |
3182 |
> |
@SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) { |
3183 |
|
long sz = map.mappingCount(); |
3184 |
|
if (sz > (long)(MAX_ARRAY_SIZE)) |
3185 |
|
throw new OutOfMemoryError(oomeMsg); |
3375 |
|
* for each key-value mapping, followed by a null pair. |
3376 |
|
* The key-value mappings are emitted in no particular order. |
3377 |
|
*/ |
3378 |
< |
@SuppressWarnings("unchecked") |
3361 |
< |
private void writeObject(java.io.ObjectOutputStream s) |
3378 |
> |
@SuppressWarnings("unchecked") private void writeObject(java.io.ObjectOutputStream s) |
3379 |
|
throws java.io.IOException { |
3380 |
|
if (segments == null) { // for serialization compatibility |
3381 |
|
segments = (Segment<K,V>[]) |
3399 |
|
* Reconstitutes the instance from a stream (that is, deserializes it). |
3400 |
|
* @param s the stream |
3401 |
|
*/ |
3402 |
< |
@SuppressWarnings("unchecked") |
3386 |
< |
private void readObject(java.io.ObjectInputStream s) |
3402 |
> |
@SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s) |
3403 |
|
throws java.io.IOException, ClassNotFoundException { |
3404 |
|
s.defaultReadObject(); |
3405 |
|
this.segments = null; // unneeded |
3672 |
|
|
3673 |
|
/** |
3674 |
|
* Returns a non-null result from applying the given search |
3675 |
< |
* function on each (key, value), or null if none. Further |
3676 |
< |
* element processing is suppressed upon success. However, |
3677 |
< |
* this method does not return until other in-progress |
3678 |
< |
* parallel invocations of the search function also complete. |
3675 |
> |
* function on each (key, value), or null if none. Upon |
3676 |
> |
* success, further element processing is suppressed and the |
3677 |
> |
* results of any other parallel invocations of the search |
3678 |
> |
* function are ignored. |
3679 |
|
* |
3680 |
|
* @param searchFunction a function returning a non-null |
3681 |
|
* result on success, else null |
3734 |
|
* @param basis the identity (initial default value) for the reduction |
3735 |
|
* @param reducer a commutative associative combining function |
3736 |
|
* @return the result of accumulating the given transformation |
3737 |
< |
* of all (key, value) pairs using the given reducer to |
3722 |
< |
* combine values, and the given basis as an identity value. |
3737 |
> |
* of all (key, value) pairs |
3738 |
|
*/ |
3739 |
|
public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer, |
3740 |
|
long basis, |
3789 |
|
|
3790 |
|
/** |
3791 |
|
* Returns a non-null result from applying the given search |
3792 |
< |
* function on each key, or null if none. Further element |
3793 |
< |
* processing is suppressed upon success. However, this method |
3794 |
< |
* does not return until other in-progress parallel |
3795 |
< |
* invocations of the search function also complete. |
3792 |
> |
* function on each key, or null if none. Upon success, |
3793 |
> |
* further element processing is suppressed and the results of |
3794 |
> |
* any other parallel invocations of the search function are |
3795 |
> |
* ignored. |
3796 |
|
* |
3797 |
|
* @param searchFunction a function returning a non-null |
3798 |
|
* result on success, else null |
3918 |
|
|
3919 |
|
/** |
3920 |
|
* Returns a non-null result from applying the given search |
3921 |
< |
* function on each value, or null if none. Further element |
3922 |
< |
* processing is suppressed upon success. However, this method |
3923 |
< |
* does not return until other in-progress parallel |
3924 |
< |
* invocations of the search function also complete. |
3921 |
> |
* function on each value, or null if none. Upon success, |
3922 |
> |
* further element processing is suppressed and the results of |
3923 |
> |
* any other parallel invocations of the search function are |
3924 |
> |
* ignored. |
3925 |
|
* |
3926 |
|
* @param searchFunction a function returning a non-null |
3927 |
|
* result on success, else null |
4048 |
|
|
4049 |
|
/** |
4050 |
|
* Returns a non-null result from applying the given search |
4051 |
< |
* function on each entry, or null if none. Further element |
4052 |
< |
* processing is suppressed upon success. However, this method |
4053 |
< |
* does not return until other in-progress parallel |
4054 |
< |
* invocations of the search function also complete. |
4051 |
> |
* function on each entry, or null if none. Upon success, |
4052 |
> |
* further element processing is suppressed and the results of |
4053 |
> |
* any other parallel invocations of the search function are |
4054 |
> |
* ignored. |
4055 |
|
* |
4056 |
|
* @param searchFunction a function returning a non-null |
4057 |
|
* result on success, else null |
4201 |
|
} |
4202 |
|
|
4203 |
|
/** |
4204 |
< |
* Returns a task that when invoked, returns a non-null |
4205 |
< |
* result from applying the given search function on each |
4206 |
< |
* (key, value), or null if none. Further element processing |
4207 |
< |
* is suppressed upon success. However, this method does not |
4208 |
< |
* return until other in-progress parallel invocations of the |
4194 |
< |
* search function also complete. |
4204 |
> |
* Returns a task that when invoked, returns a non-null result |
4205 |
> |
* from applying the given search function on each (key, |
4206 |
> |
* value), or null if none. Upon success, further element |
4207 |
> |
* processing is suppressed and the results of any other |
4208 |
> |
* parallel invocations of the search function are ignored. |
4209 |
|
* |
4210 |
|
* @param map the map |
4211 |
|
* @param searchFunction a function returning a non-null |
4353 |
|
/** |
4354 |
|
* Returns a task that when invoked, returns a non-null result |
4355 |
|
* from applying the given search function on each key, or |
4356 |
< |
* null if none. Further element processing is suppressed |
4357 |
< |
* upon success. However, this method does not return until |
4358 |
< |
* other in-progress parallel invocations of the search |
4345 |
< |
* function also complete. |
4356 |
> |
* null if none. Upon success, further element processing is |
4357 |
> |
* suppressed and the results of any other parallel |
4358 |
> |
* invocations of the search function are ignored. |
4359 |
|
* |
4360 |
|
* @param map the map |
4361 |
|
* @param searchFunction a function returning a non-null |
4387 |
|
return new ReduceKeysTask<K,V> |
4388 |
|
(map, reducer); |
4389 |
|
} |
4390 |
+ |
|
4391 |
|
/** |
4392 |
|
* Returns a task that when invoked, returns the result of |
4393 |
|
* accumulating the given transformation of all keys using the given |
4519 |
|
/** |
4520 |
|
* Returns a task that when invoked, returns a non-null result |
4521 |
|
* from applying the given search function on each value, or |
4522 |
< |
* null if none. Further element processing is suppressed |
4523 |
< |
* upon success. However, this method does not return until |
4524 |
< |
* other in-progress parallel invocations of the search |
4511 |
< |
* function also complete. |
4522 |
> |
* null if none. Upon success, further element processing is |
4523 |
> |
* suppressed and the results of any other parallel |
4524 |
> |
* invocations of the search function are ignored. |
4525 |
|
* |
4526 |
|
* @param map the map |
4527 |
|
* @param searchFunction a function returning a non-null |
4686 |
|
/** |
4687 |
|
* Returns a task that when invoked, returns a non-null result |
4688 |
|
* from applying the given search function on each entry, or |
4689 |
< |
* null if none. Further element processing is suppressed |
4690 |
< |
* upon success. However, this method does not return until |
4691 |
< |
* other in-progress parallel invocations of the search |
4679 |
< |
* function also complete. |
4689 |
> |
* null if none. Upon success, further element processing is |
4690 |
> |
* suppressed and the results of any other parallel |
4691 |
> |
* invocations of the search function are ignored. |
4692 |
|
* |
4693 |
|
* @param map the map |
4694 |
|
* @param searchFunction a function returning a non-null |
4830 |
|
* exceptions are handled in a simpler manner, by just trying to |
4831 |
|
* complete root task exceptionally. |
4832 |
|
*/ |
4833 |
< |
static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> { |
4833 |
> |
@SuppressWarnings("serial") static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> { |
4834 |
|
final BulkTask<K,V,?> parent; // completion target |
4835 |
|
int batch; // split control |
4836 |
|
int pending; // completion control |
4843 |
|
} |
4844 |
|
|
4845 |
|
/** Constructor for subtasks */ |
4846 |
< |
BulkTask(BulkTask<K,V,?> parent, int batch, boolean split) { |
4847 |
< |
super(parent, split); |
4846 |
> |
BulkTask(BulkTask<K,V,?> parent, int batch) { |
4847 |
> |
super(parent); |
4848 |
|
this.parent = parent; |
4849 |
|
this.batch = batch; |
4850 |
|
} |
4870 |
|
} |
4871 |
|
|
4872 |
|
/** |
4873 |
< |
* Forces root task to throw exception unless already complete. |
4873 |
> |
* Forces root task to complete. |
4874 |
> |
* @param ex if null, complete normally, else exceptionally |
4875 |
> |
* @return false to simplify use |
4876 |
|
*/ |
4877 |
< |
final void tryAbortComputation(Throwable ex) { |
4877 |
> |
final boolean tryCompleteComputation(Throwable ex) { |
4878 |
|
for (BulkTask<K,V,?> a = this;;) { |
4879 |
|
BulkTask<K,V,?> p = a.parent; |
4880 |
|
if (p == null) { |
4881 |
< |
a.completeExceptionally(ex); |
4882 |
< |
break; |
4881 |
> |
if (ex != null) |
4882 |
> |
a.completeExceptionally(ex); |
4883 |
> |
else |
4884 |
> |
a.quietlyComplete(); |
4885 |
> |
return false; |
4886 |
|
} |
4887 |
|
a = p; |
4888 |
|
} |
4889 |
|
} |
4890 |
|
|
4891 |
< |
public final boolean exec() { |
4892 |
< |
try { |
4893 |
< |
compute(); |
4894 |
< |
} |
4895 |
< |
catch (Throwable ex) { |
4879 |
< |
tryAbortComputation(ex); |
4880 |
< |
} |
4881 |
< |
return false; |
4891 |
> |
/** |
4892 |
> |
* Version of tryCompleteComputation for function screening checks |
4893 |
> |
*/ |
4894 |
> |
final boolean abortOnNullFunction() { |
4895 |
> |
return tryCompleteComputation(new Error("Unexpected null function")); |
4896 |
|
} |
4897 |
|
|
4884 |
– |
public abstract void compute(); |
4885 |
– |
|
4898 |
|
// utilities |
4899 |
|
|
4900 |
|
/** CompareAndSet pending count */ |
4920 |
|
} |
4921 |
|
|
4922 |
|
/** |
4911 |
– |
* Error message for hoisted null checks of functions |
4912 |
– |
*/ |
4913 |
– |
static final String NullFunctionMessage = |
4914 |
– |
"Unexpected null function"; |
4915 |
– |
|
4916 |
– |
/** |
4923 |
|
* Returns exportable snapshot entry. |
4924 |
|
*/ |
4925 |
|
static <K,V> AbstractMap.SimpleEntry<K,V> entryFor(K k, V v) { |
4926 |
< |
return new AbstractMap.SimpleEntry(k, v); |
4926 |
> |
return new AbstractMap.SimpleEntry<K,V>(k, v); |
4927 |
|
} |
4928 |
|
|
4929 |
|
// Unsafe mechanics |
4931 |
|
private static final long PENDING; |
4932 |
|
static { |
4933 |
|
try { |
4934 |
< |
U = sun.misc.Unsafe.getUnsafe(); |
4934 |
> |
U = getUnsafe(); |
4935 |
|
PENDING = U.objectFieldOffset |
4936 |
|
(BulkTask.class.getDeclaredField("pending")); |
4937 |
|
} catch (Exception e) { |
4946 |
|
* others. |
4947 |
|
*/ |
4948 |
|
|
4949 |
< |
static final class ForEachKeyTask<K,V> |
4949 |
> |
@SuppressWarnings("serial") static final class ForEachKeyTask<K,V> |
4950 |
|
extends BulkTask<K,V,Void> { |
4951 |
|
final Action<K> action; |
4952 |
|
ForEachKeyTask |
4956 |
|
this.action = action; |
4957 |
|
} |
4958 |
|
ForEachKeyTask |
4959 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
4959 |
> |
(BulkTask<K,V,?> p, int b, |
4960 |
|
Action<K> action) { |
4961 |
< |
super(p, b, split); |
4961 |
> |
super(p, b); |
4962 |
|
this.action = action; |
4963 |
|
} |
4964 |
< |
public final void compute() { |
4964 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
4965 |
|
final Action<K> action = this.action; |
4966 |
|
if (action == null) |
4967 |
< |
throw new Error(NullFunctionMessage); |
4968 |
< |
int b = batch(), c; |
4969 |
< |
while (b > 1 && baseIndex != baseLimit) { |
4970 |
< |
do {} while (!casPending(c = pending, c+1)); |
4971 |
< |
new ForEachKeyTask<K,V>(this, b >>>= 1, true, action).fork(); |
4967 |
> |
return abortOnNullFunction(); |
4968 |
> |
try { |
4969 |
> |
int b = batch(), c; |
4970 |
> |
while (b > 1 && baseIndex != baseLimit) { |
4971 |
> |
do {} while (!casPending(c = pending, c+1)); |
4972 |
> |
new ForEachKeyTask<K,V>(this, b >>>= 1, action).fork(); |
4973 |
> |
} |
4974 |
> |
while (advance() != null) |
4975 |
> |
action.apply((K)nextKey); |
4976 |
> |
tryComplete(); |
4977 |
> |
} catch (Throwable ex) { |
4978 |
> |
return tryCompleteComputation(ex); |
4979 |
|
} |
4980 |
< |
while (advance() != null) |
4968 |
< |
action.apply((K)nextKey); |
4969 |
< |
tryComplete(); |
4980 |
> |
return false; |
4981 |
|
} |
4982 |
|
} |
4983 |
|
|
4984 |
< |
static final class ForEachValueTask<K,V> |
4984 |
> |
@SuppressWarnings("serial") static final class ForEachValueTask<K,V> |
4985 |
|
extends BulkTask<K,V,Void> { |
4986 |
|
final Action<V> action; |
4987 |
|
ForEachValueTask |
4991 |
|
this.action = action; |
4992 |
|
} |
4993 |
|
ForEachValueTask |
4994 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
4994 |
> |
(BulkTask<K,V,?> p, int b, |
4995 |
|
Action<V> action) { |
4996 |
< |
super(p, b, split); |
4996 |
> |
super(p, b); |
4997 |
|
this.action = action; |
4998 |
|
} |
4999 |
< |
public final void compute() { |
4999 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5000 |
|
final Action<V> action = this.action; |
5001 |
|
if (action == null) |
5002 |
< |
throw new Error(NullFunctionMessage); |
5003 |
< |
int b = batch(), c; |
5004 |
< |
while (b > 1 && baseIndex != baseLimit) { |
5005 |
< |
do {} while (!casPending(c = pending, c+1)); |
5006 |
< |
new ForEachValueTask<K,V>(this, b >>>= 1, true, action).fork(); |
5002 |
> |
return abortOnNullFunction(); |
5003 |
> |
try { |
5004 |
> |
int b = batch(), c; |
5005 |
> |
while (b > 1 && baseIndex != baseLimit) { |
5006 |
> |
do {} while (!casPending(c = pending, c+1)); |
5007 |
> |
new ForEachValueTask<K,V>(this, b >>>= 1, action).fork(); |
5008 |
> |
} |
5009 |
> |
Object v; |
5010 |
> |
while ((v = advance()) != null) |
5011 |
> |
action.apply((V)v); |
5012 |
> |
tryComplete(); |
5013 |
> |
} catch (Throwable ex) { |
5014 |
> |
return tryCompleteComputation(ex); |
5015 |
|
} |
5016 |
< |
Object v; |
4998 |
< |
while ((v = advance()) != null) |
4999 |
< |
action.apply((V)v); |
5000 |
< |
tryComplete(); |
5016 |
> |
return false; |
5017 |
|
} |
5018 |
|
} |
5019 |
|
|
5020 |
< |
static final class ForEachEntryTask<K,V> |
5020 |
> |
@SuppressWarnings("serial") static final class ForEachEntryTask<K,V> |
5021 |
|
extends BulkTask<K,V,Void> { |
5022 |
|
final Action<Entry<K,V>> action; |
5023 |
|
ForEachEntryTask |
5027 |
|
this.action = action; |
5028 |
|
} |
5029 |
|
ForEachEntryTask |
5030 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5030 |
> |
(BulkTask<K,V,?> p, int b, |
5031 |
|
Action<Entry<K,V>> action) { |
5032 |
< |
super(p, b, split); |
5032 |
> |
super(p, b); |
5033 |
|
this.action = action; |
5034 |
|
} |
5035 |
< |
public final void compute() { |
5035 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5036 |
|
final Action<Entry<K,V>> action = this.action; |
5037 |
|
if (action == null) |
5038 |
< |
throw new Error(NullFunctionMessage); |
5039 |
< |
int b = batch(), c; |
5040 |
< |
while (b > 1 && baseIndex != baseLimit) { |
5041 |
< |
do {} while (!casPending(c = pending, c+1)); |
5042 |
< |
new ForEachEntryTask<K,V>(this, b >>>= 1, true, action).fork(); |
5038 |
> |
return abortOnNullFunction(); |
5039 |
> |
try { |
5040 |
> |
int b = batch(), c; |
5041 |
> |
while (b > 1 && baseIndex != baseLimit) { |
5042 |
> |
do {} while (!casPending(c = pending, c+1)); |
5043 |
> |
new ForEachEntryTask<K,V>(this, b >>>= 1, action).fork(); |
5044 |
> |
} |
5045 |
> |
Object v; |
5046 |
> |
while ((v = advance()) != null) |
5047 |
> |
action.apply(entryFor((K)nextKey, (V)v)); |
5048 |
> |
tryComplete(); |
5049 |
> |
} catch (Throwable ex) { |
5050 |
> |
return tryCompleteComputation(ex); |
5051 |
|
} |
5052 |
< |
Object v; |
5029 |
< |
while ((v = advance()) != null) |
5030 |
< |
action.apply(entryFor((K)nextKey, (V)v)); |
5031 |
< |
tryComplete(); |
5052 |
> |
return false; |
5053 |
|
} |
5054 |
|
} |
5055 |
|
|
5056 |
< |
static final class ForEachMappingTask<K,V> |
5056 |
> |
@SuppressWarnings("serial") static final class ForEachMappingTask<K,V> |
5057 |
|
extends BulkTask<K,V,Void> { |
5058 |
|
final BiAction<K,V> action; |
5059 |
|
ForEachMappingTask |
5063 |
|
this.action = action; |
5064 |
|
} |
5065 |
|
ForEachMappingTask |
5066 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5066 |
> |
(BulkTask<K,V,?> p, int b, |
5067 |
|
BiAction<K,V> action) { |
5068 |
< |
super(p, b, split); |
5068 |
> |
super(p, b); |
5069 |
|
this.action = action; |
5070 |
|
} |
5071 |
|
|
5072 |
< |
public final void compute() { |
5072 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5073 |
|
final BiAction<K,V> action = this.action; |
5074 |
|
if (action == null) |
5075 |
< |
throw new Error(NullFunctionMessage); |
5076 |
< |
int b = batch(), c; |
5077 |
< |
while (b > 1 && baseIndex != baseLimit) { |
5078 |
< |
do {} while (!casPending(c = pending, c+1)); |
5079 |
< |
new ForEachMappingTask<K,V>(this, b >>>= 1, true, |
5080 |
< |
action).fork(); |
5075 |
> |
return abortOnNullFunction(); |
5076 |
> |
try { |
5077 |
> |
int b = batch(), c; |
5078 |
> |
while (b > 1 && baseIndex != baseLimit) { |
5079 |
> |
do {} while (!casPending(c = pending, c+1)); |
5080 |
> |
new ForEachMappingTask<K,V>(this, b >>>= 1, |
5081 |
> |
action).fork(); |
5082 |
> |
} |
5083 |
> |
Object v; |
5084 |
> |
while ((v = advance()) != null) |
5085 |
> |
action.apply((K)nextKey, (V)v); |
5086 |
> |
tryComplete(); |
5087 |
> |
} catch (Throwable ex) { |
5088 |
> |
return tryCompleteComputation(ex); |
5089 |
|
} |
5090 |
< |
Object v; |
5062 |
< |
while ((v = advance()) != null) |
5063 |
< |
action.apply((K)nextKey, (V)v); |
5064 |
< |
tryComplete(); |
5090 |
> |
return false; |
5091 |
|
} |
5092 |
|
} |
5093 |
|
|
5094 |
< |
static final class ForEachTransformedKeyTask<K,V,U> |
5094 |
> |
@SuppressWarnings("serial") static final class ForEachTransformedKeyTask<K,V,U> |
5095 |
|
extends BulkTask<K,V,Void> { |
5096 |
|
final Fun<? super K, ? extends U> transformer; |
5097 |
|
final Action<U> action; |
5105 |
|
|
5106 |
|
} |
5107 |
|
ForEachTransformedKeyTask |
5108 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5108 |
> |
(BulkTask<K,V,?> p, int b, |
5109 |
|
Fun<? super K, ? extends U> transformer, |
5110 |
|
Action<U> action) { |
5111 |
< |
super(p, b, split); |
5111 |
> |
super(p, b); |
5112 |
|
this.transformer = transformer; |
5113 |
|
this.action = action; |
5114 |
|
} |
5115 |
< |
public final void compute() { |
5115 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5116 |
|
final Fun<? super K, ? extends U> transformer = |
5117 |
|
this.transformer; |
5118 |
|
final Action<U> action = this.action; |
5119 |
|
if (transformer == null || action == null) |
5120 |
< |
throw new Error(NullFunctionMessage); |
5121 |
< |
int b = batch(), c; |
5122 |
< |
while (b > 1 && baseIndex != baseLimit) { |
5123 |
< |
do {} while (!casPending(c = pending, c+1)); |
5124 |
< |
new ForEachTransformedKeyTask<K,V,U> |
5125 |
< |
(this, b >>>= 1, true, transformer, action).fork(); |
5126 |
< |
} |
5127 |
< |
U u; |
5128 |
< |
while (advance() != null) { |
5129 |
< |
if ((u = transformer.apply((K)nextKey)) != null) |
5130 |
< |
action.apply(u); |
5120 |
> |
return abortOnNullFunction(); |
5121 |
> |
try { |
5122 |
> |
int b = batch(), c; |
5123 |
> |
while (b > 1 && baseIndex != baseLimit) { |
5124 |
> |
do {} while (!casPending(c = pending, c+1)); |
5125 |
> |
new ForEachTransformedKeyTask<K,V,U> |
5126 |
> |
(this, b >>>= 1, transformer, action).fork(); |
5127 |
> |
} |
5128 |
> |
U u; |
5129 |
> |
while (advance() != null) { |
5130 |
> |
if ((u = transformer.apply((K)nextKey)) != null) |
5131 |
> |
action.apply(u); |
5132 |
> |
} |
5133 |
> |
tryComplete(); |
5134 |
> |
} catch (Throwable ex) { |
5135 |
> |
return tryCompleteComputation(ex); |
5136 |
|
} |
5137 |
< |
tryComplete(); |
5137 |
> |
return false; |
5138 |
|
} |
5139 |
|
} |
5140 |
|
|
5141 |
< |
static final class ForEachTransformedValueTask<K,V,U> |
5141 |
> |
@SuppressWarnings("serial") static final class ForEachTransformedValueTask<K,V,U> |
5142 |
|
extends BulkTask<K,V,Void> { |
5143 |
|
final Fun<? super V, ? extends U> transformer; |
5144 |
|
final Action<U> action; |
5152 |
|
|
5153 |
|
} |
5154 |
|
ForEachTransformedValueTask |
5155 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5155 |
> |
(BulkTask<K,V,?> p, int b, |
5156 |
|
Fun<? super V, ? extends U> transformer, |
5157 |
|
Action<U> action) { |
5158 |
< |
super(p, b, split); |
5158 |
> |
super(p, b); |
5159 |
|
this.transformer = transformer; |
5160 |
|
this.action = action; |
5161 |
|
} |
5162 |
< |
public final void compute() { |
5162 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5163 |
|
final Fun<? super V, ? extends U> transformer = |
5164 |
|
this.transformer; |
5165 |
|
final Action<U> action = this.action; |
5166 |
|
if (transformer == null || action == null) |
5167 |
< |
throw new Error(NullFunctionMessage); |
5168 |
< |
int b = batch(), c; |
5169 |
< |
while (b > 1 && baseIndex != baseLimit) { |
5170 |
< |
do {} while (!casPending(c = pending, c+1)); |
5171 |
< |
new ForEachTransformedValueTask<K,V,U> |
5172 |
< |
(this, b >>>= 1, true, transformer, action).fork(); |
5173 |
< |
} |
5174 |
< |
Object v; U u; |
5175 |
< |
while ((v = advance()) != null) { |
5176 |
< |
if ((u = transformer.apply((V)v)) != null) |
5177 |
< |
action.apply(u); |
5167 |
> |
return abortOnNullFunction(); |
5168 |
> |
try { |
5169 |
> |
int b = batch(), c; |
5170 |
> |
while (b > 1 && baseIndex != baseLimit) { |
5171 |
> |
do {} while (!casPending(c = pending, c+1)); |
5172 |
> |
new ForEachTransformedValueTask<K,V,U> |
5173 |
> |
(this, b >>>= 1, transformer, action).fork(); |
5174 |
> |
} |
5175 |
> |
Object v; U u; |
5176 |
> |
while ((v = advance()) != null) { |
5177 |
> |
if ((u = transformer.apply((V)v)) != null) |
5178 |
> |
action.apply(u); |
5179 |
> |
} |
5180 |
> |
tryComplete(); |
5181 |
> |
} catch (Throwable ex) { |
5182 |
> |
return tryCompleteComputation(ex); |
5183 |
|
} |
5184 |
< |
tryComplete(); |
5184 |
> |
return false; |
5185 |
|
} |
5186 |
|
} |
5187 |
|
|
5188 |
< |
static final class ForEachTransformedEntryTask<K,V,U> |
5188 |
> |
@SuppressWarnings("serial") static final class ForEachTransformedEntryTask<K,V,U> |
5189 |
|
extends BulkTask<K,V,Void> { |
5190 |
|
final Fun<Map.Entry<K,V>, ? extends U> transformer; |
5191 |
|
final Action<U> action; |
5199 |
|
|
5200 |
|
} |
5201 |
|
ForEachTransformedEntryTask |
5202 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5202 |
> |
(BulkTask<K,V,?> p, int b, |
5203 |
|
Fun<Map.Entry<K,V>, ? extends U> transformer, |
5204 |
|
Action<U> action) { |
5205 |
< |
super(p, b, split); |
5205 |
> |
super(p, b); |
5206 |
|
this.transformer = transformer; |
5207 |
|
this.action = action; |
5208 |
|
} |
5209 |
< |
public final void compute() { |
5209 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5210 |
|
final Fun<Map.Entry<K,V>, ? extends U> transformer = |
5211 |
|
this.transformer; |
5212 |
|
final Action<U> action = this.action; |
5213 |
|
if (transformer == null || action == null) |
5214 |
< |
throw new Error(NullFunctionMessage); |
5215 |
< |
int b = batch(), c; |
5216 |
< |
while (b > 1 && baseIndex != baseLimit) { |
5217 |
< |
do {} while (!casPending(c = pending, c+1)); |
5218 |
< |
new ForEachTransformedEntryTask<K,V,U> |
5219 |
< |
(this, b >>>= 1, true, transformer, action).fork(); |
5220 |
< |
} |
5221 |
< |
Object v; U u; |
5222 |
< |
while ((v = advance()) != null) { |
5223 |
< |
if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null) |
5224 |
< |
action.apply(u); |
5214 |
> |
return abortOnNullFunction(); |
5215 |
> |
try { |
5216 |
> |
int b = batch(), c; |
5217 |
> |
while (b > 1 && baseIndex != baseLimit) { |
5218 |
> |
do {} while (!casPending(c = pending, c+1)); |
5219 |
> |
new ForEachTransformedEntryTask<K,V,U> |
5220 |
> |
(this, b >>>= 1, transformer, action).fork(); |
5221 |
> |
} |
5222 |
> |
Object v; U u; |
5223 |
> |
while ((v = advance()) != null) { |
5224 |
> |
if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null) |
5225 |
> |
action.apply(u); |
5226 |
> |
} |
5227 |
> |
tryComplete(); |
5228 |
> |
} catch (Throwable ex) { |
5229 |
> |
return tryCompleteComputation(ex); |
5230 |
|
} |
5231 |
< |
tryComplete(); |
5231 |
> |
return false; |
5232 |
|
} |
5233 |
|
} |
5234 |
|
|
5235 |
< |
static final class ForEachTransformedMappingTask<K,V,U> |
5235 |
> |
@SuppressWarnings("serial") static final class ForEachTransformedMappingTask<K,V,U> |
5236 |
|
extends BulkTask<K,V,Void> { |
5237 |
|
final BiFun<? super K, ? super V, ? extends U> transformer; |
5238 |
|
final Action<U> action; |
5246 |
|
|
5247 |
|
} |
5248 |
|
ForEachTransformedMappingTask |
5249 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5249 |
> |
(BulkTask<K,V,?> p, int b, |
5250 |
|
BiFun<? super K, ? super V, ? extends U> transformer, |
5251 |
|
Action<U> action) { |
5252 |
< |
super(p, b, split); |
5252 |
> |
super(p, b); |
5253 |
|
this.transformer = transformer; |
5254 |
|
this.action = action; |
5255 |
|
} |
5256 |
< |
public final void compute() { |
5256 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5257 |
|
final BiFun<? super K, ? super V, ? extends U> transformer = |
5258 |
|
this.transformer; |
5259 |
|
final Action<U> action = this.action; |
5260 |
|
if (transformer == null || action == null) |
5261 |
< |
throw new Error(NullFunctionMessage); |
5262 |
< |
int b = batch(), c; |
5263 |
< |
while (b > 1 && baseIndex != baseLimit) { |
5264 |
< |
do {} while (!casPending(c = pending, c+1)); |
5265 |
< |
new ForEachTransformedMappingTask<K,V,U> |
5266 |
< |
(this, b >>>= 1, true, transformer, action).fork(); |
5267 |
< |
} |
5268 |
< |
Object v; U u; |
5269 |
< |
while ((v = advance()) != null) { |
5270 |
< |
if ((u = transformer.apply((K)nextKey, (V)v)) != null) |
5271 |
< |
action.apply(u); |
5261 |
> |
return abortOnNullFunction(); |
5262 |
> |
try { |
5263 |
> |
int b = batch(), c; |
5264 |
> |
while (b > 1 && baseIndex != baseLimit) { |
5265 |
> |
do {} while (!casPending(c = pending, c+1)); |
5266 |
> |
new ForEachTransformedMappingTask<K,V,U> |
5267 |
> |
(this, b >>>= 1, transformer, action).fork(); |
5268 |
> |
} |
5269 |
> |
Object v; U u; |
5270 |
> |
while ((v = advance()) != null) { |
5271 |
> |
if ((u = transformer.apply((K)nextKey, (V)v)) != null) |
5272 |
> |
action.apply(u); |
5273 |
> |
} |
5274 |
> |
tryComplete(); |
5275 |
> |
} catch (Throwable ex) { |
5276 |
> |
return tryCompleteComputation(ex); |
5277 |
|
} |
5278 |
< |
tryComplete(); |
5278 |
> |
return false; |
5279 |
|
} |
5280 |
|
} |
5281 |
|
|
5282 |
< |
static final class SearchKeysTask<K,V,U> |
5282 |
> |
@SuppressWarnings("serial") static final class SearchKeysTask<K,V,U> |
5283 |
|
extends BulkTask<K,V,U> { |
5284 |
|
final Fun<? super K, ? extends U> searchFunction; |
5285 |
|
final AtomicReference<U> result; |
5291 |
|
this.searchFunction = searchFunction; this.result = result; |
5292 |
|
} |
5293 |
|
SearchKeysTask |
5294 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5294 |
> |
(BulkTask<K,V,?> p, int b, |
5295 |
|
Fun<? super K, ? extends U> searchFunction, |
5296 |
|
AtomicReference<U> result) { |
5297 |
< |
super(p, b, split); |
5297 |
> |
super(p, b); |
5298 |
|
this.searchFunction = searchFunction; this.result = result; |
5299 |
|
} |
5300 |
< |
public final void compute() { |
5300 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5301 |
|
AtomicReference<U> result = this.result; |
5302 |
|
final Fun<? super K, ? extends U> searchFunction = |
5303 |
|
this.searchFunction; |
5304 |
|
if (searchFunction == null || result == null) |
5305 |
< |
throw new Error(NullFunctionMessage); |
5306 |
< |
int b = batch(), c; |
5307 |
< |
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5308 |
< |
do {} while (!casPending(c = pending, c+1)); |
5309 |
< |
new SearchKeysTask<K,V,U>(this, b >>>= 1, true, |
5310 |
< |
searchFunction, result).fork(); |
5311 |
< |
} |
5266 |
< |
U u; |
5267 |
< |
while (result.get() == null && advance() != null) { |
5268 |
< |
if ((u = searchFunction.apply((K)nextKey)) != null) { |
5269 |
< |
result.compareAndSet(null, u); |
5270 |
< |
break; |
5305 |
> |
return abortOnNullFunction(); |
5306 |
> |
try { |
5307 |
> |
int b = batch(), c; |
5308 |
> |
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5309 |
> |
do {} while (!casPending(c = pending, c+1)); |
5310 |
> |
new SearchKeysTask<K,V,U>(this, b >>>= 1, |
5311 |
> |
searchFunction, result).fork(); |
5312 |
|
} |
5313 |
+ |
U u; |
5314 |
+ |
while (result.get() == null && advance() != null) { |
5315 |
+ |
if ((u = searchFunction.apply((K)nextKey)) != null) { |
5316 |
+ |
if (result.compareAndSet(null, u)) |
5317 |
+ |
tryCompleteComputation(null); |
5318 |
+ |
break; |
5319 |
+ |
} |
5320 |
+ |
} |
5321 |
+ |
tryComplete(); |
5322 |
+ |
} catch (Throwable ex) { |
5323 |
+ |
return tryCompleteComputation(ex); |
5324 |
|
} |
5325 |
< |
tryComplete(); |
5325 |
> |
return false; |
5326 |
|
} |
5327 |
|
public final U getRawResult() { return result.get(); } |
5328 |
|
} |
5329 |
|
|
5330 |
< |
static final class SearchValuesTask<K,V,U> |
5330 |
> |
@SuppressWarnings("serial") static final class SearchValuesTask<K,V,U> |
5331 |
|
extends BulkTask<K,V,U> { |
5332 |
|
final Fun<? super V, ? extends U> searchFunction; |
5333 |
|
final AtomicReference<U> result; |
5339 |
|
this.searchFunction = searchFunction; this.result = result; |
5340 |
|
} |
5341 |
|
SearchValuesTask |
5342 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5342 |
> |
(BulkTask<K,V,?> p, int b, |
5343 |
|
Fun<? super V, ? extends U> searchFunction, |
5344 |
|
AtomicReference<U> result) { |
5345 |
< |
super(p, b, split); |
5345 |
> |
super(p, b); |
5346 |
|
this.searchFunction = searchFunction; this.result = result; |
5347 |
|
} |
5348 |
< |
public final void compute() { |
5348 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5349 |
|
AtomicReference<U> result = this.result; |
5350 |
|
final Fun<? super V, ? extends U> searchFunction = |
5351 |
|
this.searchFunction; |
5352 |
|
if (searchFunction == null || result == null) |
5353 |
< |
throw new Error(NullFunctionMessage); |
5354 |
< |
int b = batch(), c; |
5355 |
< |
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5356 |
< |
do {} while (!casPending(c = pending, c+1)); |
5357 |
< |
new SearchValuesTask<K,V,U>(this, b >>>= 1, true, |
5358 |
< |
searchFunction, result).fork(); |
5359 |
< |
} |
5360 |
< |
Object v; U u; |
5361 |
< |
while (result.get() == null && (v = advance()) != null) { |
5362 |
< |
if ((u = searchFunction.apply((V)v)) != null) { |
5363 |
< |
result.compareAndSet(null, u); |
5364 |
< |
break; |
5353 |
> |
return abortOnNullFunction(); |
5354 |
> |
try { |
5355 |
> |
int b = batch(), c; |
5356 |
> |
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5357 |
> |
do {} while (!casPending(c = pending, c+1)); |
5358 |
> |
new SearchValuesTask<K,V,U>(this, b >>>= 1, |
5359 |
> |
searchFunction, result).fork(); |
5360 |
> |
} |
5361 |
> |
Object v; U u; |
5362 |
> |
while (result.get() == null && (v = advance()) != null) { |
5363 |
> |
if ((u = searchFunction.apply((V)v)) != null) { |
5364 |
> |
if (result.compareAndSet(null, u)) |
5365 |
> |
tryCompleteComputation(null); |
5366 |
> |
break; |
5367 |
> |
} |
5368 |
|
} |
5369 |
+ |
tryComplete(); |
5370 |
+ |
} catch (Throwable ex) { |
5371 |
+ |
return tryCompleteComputation(ex); |
5372 |
|
} |
5373 |
< |
tryComplete(); |
5373 |
> |
return false; |
5374 |
|
} |
5375 |
|
public final U getRawResult() { return result.get(); } |
5376 |
|
} |
5377 |
|
|
5378 |
< |
static final class SearchEntriesTask<K,V,U> |
5378 |
> |
@SuppressWarnings("serial") static final class SearchEntriesTask<K,V,U> |
5379 |
|
extends BulkTask<K,V,U> { |
5380 |
|
final Fun<Entry<K,V>, ? extends U> searchFunction; |
5381 |
|
final AtomicReference<U> result; |
5387 |
|
this.searchFunction = searchFunction; this.result = result; |
5388 |
|
} |
5389 |
|
SearchEntriesTask |
5390 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5390 |
> |
(BulkTask<K,V,?> p, int b, |
5391 |
|
Fun<Entry<K,V>, ? extends U> searchFunction, |
5392 |
|
AtomicReference<U> result) { |
5393 |
< |
super(p, b, split); |
5393 |
> |
super(p, b); |
5394 |
|
this.searchFunction = searchFunction; this.result = result; |
5395 |
|
} |
5396 |
< |
public final void compute() { |
5396 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5397 |
|
AtomicReference<U> result = this.result; |
5398 |
|
final Fun<Entry<K,V>, ? extends U> searchFunction = |
5399 |
|
this.searchFunction; |
5400 |
|
if (searchFunction == null || result == null) |
5401 |
< |
throw new Error(NullFunctionMessage); |
5402 |
< |
int b = batch(), c; |
5403 |
< |
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5404 |
< |
do {} while (!casPending(c = pending, c+1)); |
5405 |
< |
new SearchEntriesTask<K,V,U>(this, b >>>= 1, true, |
5406 |
< |
searchFunction, result).fork(); |
5407 |
< |
} |
5408 |
< |
Object v; U u; |
5409 |
< |
while (result.get() == null && (v = advance()) != null) { |
5410 |
< |
if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) { |
5411 |
< |
result.compareAndSet(null, u); |
5412 |
< |
break; |
5401 |
> |
return abortOnNullFunction(); |
5402 |
> |
try { |
5403 |
> |
int b = batch(), c; |
5404 |
> |
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5405 |
> |
do {} while (!casPending(c = pending, c+1)); |
5406 |
> |
new SearchEntriesTask<K,V,U>(this, b >>>= 1, |
5407 |
> |
searchFunction, result).fork(); |
5408 |
> |
} |
5409 |
> |
Object v; U u; |
5410 |
> |
while (result.get() == null && (v = advance()) != null) { |
5411 |
> |
if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) { |
5412 |
> |
if (result.compareAndSet(null, u)) |
5413 |
> |
tryCompleteComputation(null); |
5414 |
> |
break; |
5415 |
> |
} |
5416 |
|
} |
5417 |
+ |
tryComplete(); |
5418 |
+ |
} catch (Throwable ex) { |
5419 |
+ |
return tryCompleteComputation(ex); |
5420 |
|
} |
5421 |
< |
tryComplete(); |
5421 |
> |
return false; |
5422 |
|
} |
5423 |
|
public final U getRawResult() { return result.get(); } |
5424 |
|
} |
5425 |
|
|
5426 |
< |
static final class SearchMappingsTask<K,V,U> |
5426 |
> |
@SuppressWarnings("serial") static final class SearchMappingsTask<K,V,U> |
5427 |
|
extends BulkTask<K,V,U> { |
5428 |
|
final BiFun<? super K, ? super V, ? extends U> searchFunction; |
5429 |
|
final AtomicReference<U> result; |
5435 |
|
this.searchFunction = searchFunction; this.result = result; |
5436 |
|
} |
5437 |
|
SearchMappingsTask |
5438 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5438 |
> |
(BulkTask<K,V,?> p, int b, |
5439 |
|
BiFun<? super K, ? super V, ? extends U> searchFunction, |
5440 |
|
AtomicReference<U> result) { |
5441 |
< |
super(p, b, split); |
5441 |
> |
super(p, b); |
5442 |
|
this.searchFunction = searchFunction; this.result = result; |
5443 |
|
} |
5444 |
< |
public final void compute() { |
5444 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5445 |
|
AtomicReference<U> result = this.result; |
5446 |
|
final BiFun<? super K, ? super V, ? extends U> searchFunction = |
5447 |
|
this.searchFunction; |
5448 |
|
if (searchFunction == null || result == null) |
5449 |
< |
throw new Error(NullFunctionMessage); |
5450 |
< |
int b = batch(), c; |
5451 |
< |
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5452 |
< |
do {} while (!casPending(c = pending, c+1)); |
5453 |
< |
new SearchMappingsTask<K,V,U>(this, b >>>= 1, true, |
5454 |
< |
searchFunction, result).fork(); |
5455 |
< |
} |
5456 |
< |
Object v; U u; |
5457 |
< |
while (result.get() == null && (v = advance()) != null) { |
5458 |
< |
if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) { |
5459 |
< |
result.compareAndSet(null, u); |
5460 |
< |
break; |
5449 |
> |
return abortOnNullFunction(); |
5450 |
> |
try { |
5451 |
> |
int b = batch(), c; |
5452 |
> |
while (b > 1 && baseIndex != baseLimit && result.get() == null) { |
5453 |
> |
do {} while (!casPending(c = pending, c+1)); |
5454 |
> |
new SearchMappingsTask<K,V,U>(this, b >>>= 1, |
5455 |
> |
searchFunction, result).fork(); |
5456 |
> |
} |
5457 |
> |
Object v; U u; |
5458 |
> |
while (result.get() == null && (v = advance()) != null) { |
5459 |
> |
if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) { |
5460 |
> |
if (result.compareAndSet(null, u)) |
5461 |
> |
tryCompleteComputation(null); |
5462 |
> |
break; |
5463 |
> |
} |
5464 |
|
} |
5465 |
+ |
tryComplete(); |
5466 |
+ |
} catch (Throwable ex) { |
5467 |
+ |
return tryCompleteComputation(ex); |
5468 |
|
} |
5469 |
< |
tryComplete(); |
5469 |
> |
return false; |
5470 |
|
} |
5471 |
|
public final U getRawResult() { return result.get(); } |
5472 |
|
} |
5473 |
|
|
5474 |
< |
static final class ReduceKeysTask<K,V> |
5474 |
> |
@SuppressWarnings("serial") static final class ReduceKeysTask<K,V> |
5475 |
|
extends BulkTask<K,V,K> { |
5476 |
|
final BiFun<? super K, ? super K, ? extends K> reducer; |
5477 |
|
K result; |
5478 |
< |
ReduceKeysTask<K,V> sibling; |
5478 |
> |
ReduceKeysTask<K,V> rights, nextRight; |
5479 |
|
ReduceKeysTask |
5480 |
|
(ConcurrentHashMapV8<K,V> m, |
5481 |
|
BiFun<? super K, ? super K, ? extends K> reducer) { |
5483 |
|
this.reducer = reducer; |
5484 |
|
} |
5485 |
|
ReduceKeysTask |
5486 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5486 |
> |
(BulkTask<K,V,?> p, int b, |
5487 |
> |
ReduceKeysTask<K,V> nextRight, |
5488 |
|
BiFun<? super K, ? super K, ? extends K> reducer) { |
5489 |
< |
super(p, b, split); |
5489 |
> |
super(p, b); this.nextRight = nextRight; |
5490 |
|
this.reducer = reducer; |
5491 |
|
} |
5492 |
|
|
5493 |
< |
public final void compute() { |
5423 |
< |
ReduceKeysTask<K,V> t = this; |
5493 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5494 |
|
final BiFun<? super K, ? super K, ? extends K> reducer = |
5495 |
|
this.reducer; |
5496 |
|
if (reducer == null) |
5497 |
< |
throw new Error(NullFunctionMessage); |
5498 |
< |
int b = batch(); |
5499 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
5500 |
< |
b >>>= 1; |
5501 |
< |
t.pending = 1; |
5502 |
< |
ReduceKeysTask<K,V> rt = |
5503 |
< |
new ReduceKeysTask<K,V> |
5504 |
< |
(t, b, true, reducer); |
5505 |
< |
t = new ReduceKeysTask<K,V> |
5506 |
< |
(t, b, false, reducer); |
5507 |
< |
t.sibling = rt; |
5438 |
< |
rt.sibling = t; |
5439 |
< |
rt.fork(); |
5440 |
< |
} |
5441 |
< |
K r = null; |
5442 |
< |
while (t.advance() != null) { |
5443 |
< |
K u = (K)t.nextKey; |
5444 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5445 |
< |
} |
5446 |
< |
t.result = r; |
5447 |
< |
for (;;) { |
5448 |
< |
int c; BulkTask<K,V,?> par; ReduceKeysTask<K,V> s, p; K u; |
5449 |
< |
if ((par = t.parent) == null || |
5450 |
< |
!(par instanceof ReduceKeysTask)) { |
5451 |
< |
t.quietlyComplete(); |
5452 |
< |
break; |
5497 |
> |
return abortOnNullFunction(); |
5498 |
> |
try { |
5499 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
5500 |
> |
do {} while (!casPending(c = pending, c+1)); |
5501 |
> |
(rights = new ReduceKeysTask<K,V> |
5502 |
> |
(this, b >>>= 1, rights, reducer)).fork(); |
5503 |
> |
} |
5504 |
> |
K r = null; |
5505 |
> |
while (advance() != null) { |
5506 |
> |
K u = (K)nextKey; |
5507 |
> |
r = (r == null) ? u : reducer.apply(r, u); |
5508 |
|
} |
5509 |
< |
else if ((c = (p = (ReduceKeysTask<K,V>)par).pending) == 0) { |
5510 |
< |
if ((s = t.sibling) != null && (u = s.result) != null) |
5511 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5512 |
< |
(t = p).result = r; |
5509 |
> |
result = r; |
5510 |
> |
for (ReduceKeysTask<K,V> t = this, s;;) { |
5511 |
> |
int c; BulkTask<K,V,?> par; K tr, sr; |
5512 |
> |
if ((c = t.pending) == 0) { |
5513 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
5514 |
> |
if ((sr = s.result) != null) |
5515 |
> |
t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr); |
5516 |
> |
} |
5517 |
> |
if ((par = t.parent) == null || |
5518 |
> |
!(par instanceof ReduceKeysTask)) { |
5519 |
> |
t.quietlyComplete(); |
5520 |
> |
break; |
5521 |
> |
} |
5522 |
> |
t = (ReduceKeysTask<K,V>)par; |
5523 |
> |
} |
5524 |
> |
else if (t.casPending(c, c - 1)) |
5525 |
> |
break; |
5526 |
|
} |
5527 |
< |
else if (p.casPending(c, 0)) |
5528 |
< |
break; |
5527 |
> |
} catch (Throwable ex) { |
5528 |
> |
return tryCompleteComputation(ex); |
5529 |
|
} |
5530 |
+ |
return false; |
5531 |
|
} |
5532 |
|
public final K getRawResult() { return result; } |
5533 |
|
} |
5534 |
|
|
5535 |
< |
static final class ReduceValuesTask<K,V> |
5535 |
> |
@SuppressWarnings("serial") static final class ReduceValuesTask<K,V> |
5536 |
|
extends BulkTask<K,V,V> { |
5537 |
|
final BiFun<? super V, ? super V, ? extends V> reducer; |
5538 |
|
V result; |
5539 |
< |
ReduceValuesTask<K,V> sibling; |
5539 |
> |
ReduceValuesTask<K,V> rights, nextRight; |
5540 |
|
ReduceValuesTask |
5541 |
|
(ConcurrentHashMapV8<K,V> m, |
5542 |
|
BiFun<? super V, ? super V, ? extends V> reducer) { |
5544 |
|
this.reducer = reducer; |
5545 |
|
} |
5546 |
|
ReduceValuesTask |
5547 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5547 |
> |
(BulkTask<K,V,?> p, int b, |
5548 |
> |
ReduceValuesTask<K,V> nextRight, |
5549 |
|
BiFun<? super V, ? super V, ? extends V> reducer) { |
5550 |
< |
super(p, b, split); |
5550 |
> |
super(p, b); this.nextRight = nextRight; |
5551 |
|
this.reducer = reducer; |
5552 |
|
} |
5553 |
|
|
5554 |
< |
public final void compute() { |
5485 |
< |
ReduceValuesTask<K,V> t = this; |
5554 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5555 |
|
final BiFun<? super V, ? super V, ? extends V> reducer = |
5556 |
|
this.reducer; |
5557 |
|
if (reducer == null) |
5558 |
< |
throw new Error(NullFunctionMessage); |
5559 |
< |
int b = batch(); |
5560 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
5561 |
< |
b >>>= 1; |
5562 |
< |
t.pending = 1; |
5563 |
< |
ReduceValuesTask<K,V> rt = |
5564 |
< |
new ReduceValuesTask<K,V> |
5565 |
< |
(t, b, true, reducer); |
5566 |
< |
t = new ReduceValuesTask<K,V> |
5567 |
< |
(t, b, false, reducer); |
5568 |
< |
t.sibling = rt; |
5569 |
< |
rt.sibling = t; |
5501 |
< |
rt.fork(); |
5502 |
< |
} |
5503 |
< |
V r = null; |
5504 |
< |
Object v; |
5505 |
< |
while ((v = t.advance()) != null) { |
5506 |
< |
V u = (V)v; |
5507 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5508 |
< |
} |
5509 |
< |
t.result = r; |
5510 |
< |
for (;;) { |
5511 |
< |
int c; BulkTask<K,V,?> par; ReduceValuesTask<K,V> s, p; V u; |
5512 |
< |
if ((par = t.parent) == null || |
5513 |
< |
!(par instanceof ReduceValuesTask)) { |
5514 |
< |
t.quietlyComplete(); |
5515 |
< |
break; |
5558 |
> |
return abortOnNullFunction(); |
5559 |
> |
try { |
5560 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
5561 |
> |
do {} while (!casPending(c = pending, c+1)); |
5562 |
> |
(rights = new ReduceValuesTask<K,V> |
5563 |
> |
(this, b >>>= 1, rights, reducer)).fork(); |
5564 |
> |
} |
5565 |
> |
V r = null; |
5566 |
> |
Object v; |
5567 |
> |
while ((v = advance()) != null) { |
5568 |
> |
V u = (V)v; |
5569 |
> |
r = (r == null) ? u : reducer.apply(r, u); |
5570 |
|
} |
5571 |
< |
else if ((c = (p = (ReduceValuesTask<K,V>)par).pending) == 0) { |
5572 |
< |
if ((s = t.sibling) != null && (u = s.result) != null) |
5573 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5574 |
< |
(t = p).result = r; |
5571 |
> |
result = r; |
5572 |
> |
for (ReduceValuesTask<K,V> t = this, s;;) { |
5573 |
> |
int c; BulkTask<K,V,?> par; V tr, sr; |
5574 |
> |
if ((c = t.pending) == 0) { |
5575 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
5576 |
> |
if ((sr = s.result) != null) |
5577 |
> |
t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr); |
5578 |
> |
} |
5579 |
> |
if ((par = t.parent) == null || |
5580 |
> |
!(par instanceof ReduceValuesTask)) { |
5581 |
> |
t.quietlyComplete(); |
5582 |
> |
break; |
5583 |
> |
} |
5584 |
> |
t = (ReduceValuesTask<K,V>)par; |
5585 |
> |
} |
5586 |
> |
else if (t.casPending(c, c - 1)) |
5587 |
> |
break; |
5588 |
|
} |
5589 |
< |
else if (p.casPending(c, 0)) |
5590 |
< |
break; |
5589 |
> |
} catch (Throwable ex) { |
5590 |
> |
return tryCompleteComputation(ex); |
5591 |
|
} |
5592 |
+ |
return false; |
5593 |
|
} |
5594 |
|
public final V getRawResult() { return result; } |
5595 |
|
} |
5596 |
|
|
5597 |
< |
static final class ReduceEntriesTask<K,V> |
5597 |
> |
@SuppressWarnings("serial") static final class ReduceEntriesTask<K,V> |
5598 |
|
extends BulkTask<K,V,Map.Entry<K,V>> { |
5599 |
|
final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer; |
5600 |
|
Map.Entry<K,V> result; |
5601 |
< |
ReduceEntriesTask<K,V> sibling; |
5601 |
> |
ReduceEntriesTask<K,V> rights, nextRight; |
5602 |
|
ReduceEntriesTask |
5603 |
|
(ConcurrentHashMapV8<K,V> m, |
5604 |
|
BiFun<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
5606 |
|
this.reducer = reducer; |
5607 |
|
} |
5608 |
|
ReduceEntriesTask |
5609 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5609 |
> |
(BulkTask<K,V,?> p, int b, |
5610 |
> |
ReduceEntriesTask<K,V> nextRight, |
5611 |
|
BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
5612 |
< |
super(p, b, split); |
5612 |
> |
super(p, b); this.nextRight = nextRight; |
5613 |
|
this.reducer = reducer; |
5614 |
|
} |
5615 |
|
|
5616 |
< |
public final void compute() { |
5548 |
< |
ReduceEntriesTask<K,V> t = this; |
5616 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5617 |
|
final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer = |
5618 |
|
this.reducer; |
5619 |
|
if (reducer == null) |
5620 |
< |
throw new Error(NullFunctionMessage); |
5621 |
< |
int b = batch(); |
5622 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
5623 |
< |
b >>>= 1; |
5624 |
< |
t.pending = 1; |
5625 |
< |
ReduceEntriesTask<K,V> rt = |
5626 |
< |
new ReduceEntriesTask<K,V> |
5627 |
< |
(t, b, true, reducer); |
5628 |
< |
t = new ReduceEntriesTask<K,V> |
5629 |
< |
(t, b, false, reducer); |
5630 |
< |
t.sibling = rt; |
5631 |
< |
rt.sibling = t; |
5564 |
< |
rt.fork(); |
5565 |
< |
} |
5566 |
< |
Map.Entry<K,V> r = null; |
5567 |
< |
Object v; |
5568 |
< |
while ((v = t.advance()) != null) { |
5569 |
< |
Map.Entry<K,V> u = entryFor((K)t.nextKey, (V)v); |
5570 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5571 |
< |
} |
5572 |
< |
t.result = r; |
5573 |
< |
for (;;) { |
5574 |
< |
int c; BulkTask<K,V,?> par; ReduceEntriesTask<K,V> s, p; |
5575 |
< |
Map.Entry<K,V> u; |
5576 |
< |
if ((par = t.parent) == null || |
5577 |
< |
!(par instanceof ReduceEntriesTask)) { |
5578 |
< |
t.quietlyComplete(); |
5579 |
< |
break; |
5620 |
> |
return abortOnNullFunction(); |
5621 |
> |
try { |
5622 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
5623 |
> |
do {} while (!casPending(c = pending, c+1)); |
5624 |
> |
(rights = new ReduceEntriesTask<K,V> |
5625 |
> |
(this, b >>>= 1, rights, reducer)).fork(); |
5626 |
> |
} |
5627 |
> |
Map.Entry<K,V> r = null; |
5628 |
> |
Object v; |
5629 |
> |
while ((v = advance()) != null) { |
5630 |
> |
Map.Entry<K,V> u = entryFor((K)nextKey, (V)v); |
5631 |
> |
r = (r == null) ? u : reducer.apply(r, u); |
5632 |
|
} |
5633 |
< |
else if ((c = (p = (ReduceEntriesTask<K,V>)par).pending) == 0) { |
5634 |
< |
if ((s = t.sibling) != null && (u = s.result) != null) |
5635 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5636 |
< |
(t = p).result = r; |
5633 |
> |
result = r; |
5634 |
> |
for (ReduceEntriesTask<K,V> t = this, s;;) { |
5635 |
> |
int c; BulkTask<K,V,?> par; Map.Entry<K,V> tr, sr; |
5636 |
> |
if ((c = t.pending) == 0) { |
5637 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
5638 |
> |
if ((sr = s.result) != null) |
5639 |
> |
t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr); |
5640 |
> |
} |
5641 |
> |
if ((par = t.parent) == null || |
5642 |
> |
!(par instanceof ReduceEntriesTask)) { |
5643 |
> |
t.quietlyComplete(); |
5644 |
> |
break; |
5645 |
> |
} |
5646 |
> |
t = (ReduceEntriesTask<K,V>)par; |
5647 |
> |
} |
5648 |
> |
else if (t.casPending(c, c - 1)) |
5649 |
> |
break; |
5650 |
|
} |
5651 |
< |
else if (p.casPending(c, 0)) |
5652 |
< |
break; |
5651 |
> |
} catch (Throwable ex) { |
5652 |
> |
return tryCompleteComputation(ex); |
5653 |
|
} |
5654 |
+ |
return false; |
5655 |
|
} |
5656 |
|
public final Map.Entry<K,V> getRawResult() { return result; } |
5657 |
|
} |
5658 |
|
|
5659 |
< |
static final class MapReduceKeysTask<K,V,U> |
5659 |
> |
@SuppressWarnings("serial") static final class MapReduceKeysTask<K,V,U> |
5660 |
|
extends BulkTask<K,V,U> { |
5661 |
|
final Fun<? super K, ? extends U> transformer; |
5662 |
|
final BiFun<? super U, ? super U, ? extends U> reducer; |
5663 |
|
U result; |
5664 |
< |
MapReduceKeysTask<K,V,U> sibling; |
5664 |
> |
MapReduceKeysTask<K,V,U> rights, nextRight; |
5665 |
|
MapReduceKeysTask |
5666 |
|
(ConcurrentHashMapV8<K,V> m, |
5667 |
|
Fun<? super K, ? extends U> transformer, |
5671 |
|
this.reducer = reducer; |
5672 |
|
} |
5673 |
|
MapReduceKeysTask |
5674 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5674 |
> |
(BulkTask<K,V,?> p, int b, |
5675 |
> |
MapReduceKeysTask<K,V,U> nextRight, |
5676 |
|
Fun<? super K, ? extends U> transformer, |
5677 |
|
BiFun<? super U, ? super U, ? extends U> reducer) { |
5678 |
< |
super(p, b, split); |
5678 |
> |
super(p, b); this.nextRight = nextRight; |
5679 |
|
this.transformer = transformer; |
5680 |
|
this.reducer = reducer; |
5681 |
|
} |
5682 |
< |
public final void compute() { |
5616 |
< |
MapReduceKeysTask<K,V,U> t = this; |
5682 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5683 |
|
final Fun<? super K, ? extends U> transformer = |
5684 |
|
this.transformer; |
5685 |
|
final BiFun<? super U, ? super U, ? extends U> reducer = |
5686 |
|
this.reducer; |
5687 |
|
if (transformer == null || reducer == null) |
5688 |
< |
throw new Error(NullFunctionMessage); |
5689 |
< |
int b = batch(); |
5690 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
5691 |
< |
b >>>= 1; |
5692 |
< |
t.pending = 1; |
5693 |
< |
MapReduceKeysTask<K,V,U> rt = |
5694 |
< |
new MapReduceKeysTask<K,V,U> |
5695 |
< |
(t, b, true, transformer, reducer); |
5696 |
< |
t = new MapReduceKeysTask<K,V,U> |
5697 |
< |
(t, b, false, transformer, reducer); |
5632 |
< |
t.sibling = rt; |
5633 |
< |
rt.sibling = t; |
5634 |
< |
rt.fork(); |
5635 |
< |
} |
5636 |
< |
U r = null, u; |
5637 |
< |
while (t.advance() != null) { |
5638 |
< |
if ((u = transformer.apply((K)t.nextKey)) != null) |
5639 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5640 |
< |
} |
5641 |
< |
t.result = r; |
5642 |
< |
for (;;) { |
5643 |
< |
int c; BulkTask<K,V,?> par; MapReduceKeysTask<K,V,U> s, p; |
5644 |
< |
if ((par = t.parent) == null || |
5645 |
< |
!(par instanceof MapReduceKeysTask)) { |
5646 |
< |
t.quietlyComplete(); |
5647 |
< |
break; |
5648 |
< |
} |
5649 |
< |
else if ((c = (p = (MapReduceKeysTask<K,V,U>)par).pending) == 0) { |
5650 |
< |
if ((s = t.sibling) != null && (u = s.result) != null) |
5688 |
> |
return abortOnNullFunction(); |
5689 |
> |
try { |
5690 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
5691 |
> |
do {} while (!casPending(c = pending, c+1)); |
5692 |
> |
(rights = new MapReduceKeysTask<K,V,U> |
5693 |
> |
(this, b >>>= 1, rights, transformer, reducer)).fork(); |
5694 |
> |
} |
5695 |
> |
U r = null, u; |
5696 |
> |
while (advance() != null) { |
5697 |
> |
if ((u = transformer.apply((K)nextKey)) != null) |
5698 |
|
r = (r == null) ? u : reducer.apply(r, u); |
5652 |
– |
(t = p).result = r; |
5699 |
|
} |
5700 |
< |
else if (p.casPending(c, 0)) |
5701 |
< |
break; |
5700 |
> |
result = r; |
5701 |
> |
for (MapReduceKeysTask<K,V,U> t = this, s;;) { |
5702 |
> |
int c; BulkTask<K,V,?> par; U tr, sr; |
5703 |
> |
if ((c = t.pending) == 0) { |
5704 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
5705 |
> |
if ((sr = s.result) != null) |
5706 |
> |
t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr); |
5707 |
> |
} |
5708 |
> |
if ((par = t.parent) == null || |
5709 |
> |
!(par instanceof MapReduceKeysTask)) { |
5710 |
> |
t.quietlyComplete(); |
5711 |
> |
break; |
5712 |
> |
} |
5713 |
> |
t = (MapReduceKeysTask<K,V,U>)par; |
5714 |
> |
} |
5715 |
> |
else if (t.casPending(c, c - 1)) |
5716 |
> |
break; |
5717 |
> |
} |
5718 |
> |
} catch (Throwable ex) { |
5719 |
> |
return tryCompleteComputation(ex); |
5720 |
|
} |
5721 |
+ |
return false; |
5722 |
|
} |
5723 |
|
public final U getRawResult() { return result; } |
5724 |
|
} |
5725 |
|
|
5726 |
< |
static final class MapReduceValuesTask<K,V,U> |
5726 |
> |
@SuppressWarnings("serial") static final class MapReduceValuesTask<K,V,U> |
5727 |
|
extends BulkTask<K,V,U> { |
5728 |
|
final Fun<? super V, ? extends U> transformer; |
5729 |
|
final BiFun<? super U, ? super U, ? extends U> reducer; |
5730 |
|
U result; |
5731 |
< |
MapReduceValuesTask<K,V,U> sibling; |
5731 |
> |
MapReduceValuesTask<K,V,U> rights, nextRight; |
5732 |
|
MapReduceValuesTask |
5733 |
|
(ConcurrentHashMapV8<K,V> m, |
5734 |
|
Fun<? super V, ? extends U> transformer, |
5738 |
|
this.reducer = reducer; |
5739 |
|
} |
5740 |
|
MapReduceValuesTask |
5741 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5741 |
> |
(BulkTask<K,V,?> p, int b, |
5742 |
> |
MapReduceValuesTask<K,V,U> nextRight, |
5743 |
|
Fun<? super V, ? extends U> transformer, |
5744 |
|
BiFun<? super U, ? super U, ? extends U> reducer) { |
5745 |
< |
super(p, b, split); |
5745 |
> |
super(p, b); this.nextRight = nextRight; |
5746 |
|
this.transformer = transformer; |
5747 |
|
this.reducer = reducer; |
5748 |
|
} |
5749 |
< |
public final void compute() { |
5684 |
< |
MapReduceValuesTask<K,V,U> t = this; |
5749 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5750 |
|
final Fun<? super V, ? extends U> transformer = |
5751 |
|
this.transformer; |
5752 |
|
final BiFun<? super U, ? super U, ? extends U> reducer = |
5753 |
|
this.reducer; |
5754 |
|
if (transformer == null || reducer == null) |
5755 |
< |
throw new Error(NullFunctionMessage); |
5756 |
< |
int b = batch(); |
5757 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
5758 |
< |
b >>>= 1; |
5759 |
< |
t.pending = 1; |
5760 |
< |
MapReduceValuesTask<K,V,U> rt = |
5761 |
< |
new MapReduceValuesTask<K,V,U> |
5762 |
< |
(t, b, true, transformer, reducer); |
5763 |
< |
t = new MapReduceValuesTask<K,V,U> |
5764 |
< |
(t, b, false, transformer, reducer); |
5765 |
< |
t.sibling = rt; |
5701 |
< |
rt.sibling = t; |
5702 |
< |
rt.fork(); |
5703 |
< |
} |
5704 |
< |
U r = null, u; |
5705 |
< |
Object v; |
5706 |
< |
while ((v = t.advance()) != null) { |
5707 |
< |
if ((u = transformer.apply((V)v)) != null) |
5708 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5709 |
< |
} |
5710 |
< |
t.result = r; |
5711 |
< |
for (;;) { |
5712 |
< |
int c; BulkTask<K,V,?> par; MapReduceValuesTask<K,V,U> s, p; |
5713 |
< |
if ((par = t.parent) == null || |
5714 |
< |
!(par instanceof MapReduceValuesTask)) { |
5715 |
< |
t.quietlyComplete(); |
5716 |
< |
break; |
5717 |
< |
} |
5718 |
< |
else if ((c = (p = (MapReduceValuesTask<K,V,U>)par).pending) == 0) { |
5719 |
< |
if ((s = t.sibling) != null && (u = s.result) != null) |
5755 |
> |
return abortOnNullFunction(); |
5756 |
> |
try { |
5757 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
5758 |
> |
do {} while (!casPending(c = pending, c+1)); |
5759 |
> |
(rights = new MapReduceValuesTask<K,V,U> |
5760 |
> |
(this, b >>>= 1, rights, transformer, reducer)).fork(); |
5761 |
> |
} |
5762 |
> |
U r = null, u; |
5763 |
> |
Object v; |
5764 |
> |
while ((v = advance()) != null) { |
5765 |
> |
if ((u = transformer.apply((V)v)) != null) |
5766 |
|
r = (r == null) ? u : reducer.apply(r, u); |
5721 |
– |
(t = p).result = r; |
5767 |
|
} |
5768 |
< |
else if (p.casPending(c, 0)) |
5769 |
< |
break; |
5768 |
> |
result = r; |
5769 |
> |
for (MapReduceValuesTask<K,V,U> t = this, s;;) { |
5770 |
> |
int c; BulkTask<K,V,?> par; U tr, sr; |
5771 |
> |
if ((c = t.pending) == 0) { |
5772 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
5773 |
> |
if ((sr = s.result) != null) |
5774 |
> |
t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr); |
5775 |
> |
} |
5776 |
> |
if ((par = t.parent) == null || |
5777 |
> |
!(par instanceof MapReduceValuesTask)) { |
5778 |
> |
t.quietlyComplete(); |
5779 |
> |
break; |
5780 |
> |
} |
5781 |
> |
t = (MapReduceValuesTask<K,V,U>)par; |
5782 |
> |
} |
5783 |
> |
else if (t.casPending(c, c - 1)) |
5784 |
> |
break; |
5785 |
> |
} |
5786 |
> |
} catch (Throwable ex) { |
5787 |
> |
return tryCompleteComputation(ex); |
5788 |
|
} |
5789 |
+ |
return false; |
5790 |
|
} |
5791 |
|
public final U getRawResult() { return result; } |
5792 |
|
} |
5793 |
|
|
5794 |
< |
static final class MapReduceEntriesTask<K,V,U> |
5794 |
> |
@SuppressWarnings("serial") static final class MapReduceEntriesTask<K,V,U> |
5795 |
|
extends BulkTask<K,V,U> { |
5796 |
|
final Fun<Map.Entry<K,V>, ? extends U> transformer; |
5797 |
|
final BiFun<? super U, ? super U, ? extends U> reducer; |
5798 |
|
U result; |
5799 |
< |
MapReduceEntriesTask<K,V,U> sibling; |
5799 |
> |
MapReduceEntriesTask<K,V,U> rights, nextRight; |
5800 |
|
MapReduceEntriesTask |
5801 |
|
(ConcurrentHashMapV8<K,V> m, |
5802 |
|
Fun<Map.Entry<K,V>, ? extends U> transformer, |
5806 |
|
this.reducer = reducer; |
5807 |
|
} |
5808 |
|
MapReduceEntriesTask |
5809 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5809 |
> |
(BulkTask<K,V,?> p, int b, |
5810 |
> |
MapReduceEntriesTask<K,V,U> nextRight, |
5811 |
|
Fun<Map.Entry<K,V>, ? extends U> transformer, |
5812 |
|
BiFun<? super U, ? super U, ? extends U> reducer) { |
5813 |
< |
super(p, b, split); |
5813 |
> |
super(p, b); this.nextRight = nextRight; |
5814 |
|
this.transformer = transformer; |
5815 |
|
this.reducer = reducer; |
5816 |
|
} |
5817 |
< |
public final void compute() { |
5753 |
< |
MapReduceEntriesTask<K,V,U> t = this; |
5817 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5818 |
|
final Fun<Map.Entry<K,V>, ? extends U> transformer = |
5819 |
|
this.transformer; |
5820 |
|
final BiFun<? super U, ? super U, ? extends U> reducer = |
5821 |
|
this.reducer; |
5822 |
|
if (transformer == null || reducer == null) |
5823 |
< |
throw new Error(NullFunctionMessage); |
5824 |
< |
int b = batch(); |
5825 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
5826 |
< |
b >>>= 1; |
5827 |
< |
t.pending = 1; |
5828 |
< |
MapReduceEntriesTask<K,V,U> rt = |
5829 |
< |
new MapReduceEntriesTask<K,V,U> |
5830 |
< |
(t, b, true, transformer, reducer); |
5831 |
< |
t = new MapReduceEntriesTask<K,V,U> |
5832 |
< |
(t, b, false, transformer, reducer); |
5833 |
< |
t.sibling = rt; |
5770 |
< |
rt.sibling = t; |
5771 |
< |
rt.fork(); |
5772 |
< |
} |
5773 |
< |
U r = null, u; |
5774 |
< |
Object v; |
5775 |
< |
while ((v = t.advance()) != null) { |
5776 |
< |
if ((u = transformer.apply(entryFor((K)t.nextKey, (V)v))) != null) |
5777 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5778 |
< |
} |
5779 |
< |
t.result = r; |
5780 |
< |
for (;;) { |
5781 |
< |
int c; BulkTask<K,V,?> par; MapReduceEntriesTask<K,V,U> s, p; |
5782 |
< |
if ((par = t.parent) == null || |
5783 |
< |
!(par instanceof MapReduceEntriesTask)) { |
5784 |
< |
t.quietlyComplete(); |
5785 |
< |
break; |
5786 |
< |
} |
5787 |
< |
else if ((c = (p = (MapReduceEntriesTask<K,V,U>)par).pending) == 0) { |
5788 |
< |
if ((s = t.sibling) != null && (u = s.result) != null) |
5823 |
> |
return abortOnNullFunction(); |
5824 |
> |
try { |
5825 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
5826 |
> |
do {} while (!casPending(c = pending, c+1)); |
5827 |
> |
(rights = new MapReduceEntriesTask<K,V,U> |
5828 |
> |
(this, b >>>= 1, rights, transformer, reducer)).fork(); |
5829 |
> |
} |
5830 |
> |
U r = null, u; |
5831 |
> |
Object v; |
5832 |
> |
while ((v = advance()) != null) { |
5833 |
> |
if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null) |
5834 |
|
r = (r == null) ? u : reducer.apply(r, u); |
5790 |
– |
(t = p).result = r; |
5835 |
|
} |
5836 |
< |
else if (p.casPending(c, 0)) |
5837 |
< |
break; |
5836 |
> |
result = r; |
5837 |
> |
for (MapReduceEntriesTask<K,V,U> t = this, s;;) { |
5838 |
> |
int c; BulkTask<K,V,?> par; U tr, sr; |
5839 |
> |
if ((c = t.pending) == 0) { |
5840 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
5841 |
> |
if ((sr = s.result) != null) |
5842 |
> |
t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr); |
5843 |
> |
} |
5844 |
> |
if ((par = t.parent) == null || |
5845 |
> |
!(par instanceof MapReduceEntriesTask)) { |
5846 |
> |
t.quietlyComplete(); |
5847 |
> |
break; |
5848 |
> |
} |
5849 |
> |
t = (MapReduceEntriesTask<K,V,U>)par; |
5850 |
> |
} |
5851 |
> |
else if (t.casPending(c, c - 1)) |
5852 |
> |
break; |
5853 |
> |
} |
5854 |
> |
} catch (Throwable ex) { |
5855 |
> |
return tryCompleteComputation(ex); |
5856 |
|
} |
5857 |
+ |
return false; |
5858 |
|
} |
5859 |
|
public final U getRawResult() { return result; } |
5860 |
|
} |
5861 |
|
|
5862 |
< |
static final class MapReduceMappingsTask<K,V,U> |
5862 |
> |
@SuppressWarnings("serial") static final class MapReduceMappingsTask<K,V,U> |
5863 |
|
extends BulkTask<K,V,U> { |
5864 |
|
final BiFun<? super K, ? super V, ? extends U> transformer; |
5865 |
|
final BiFun<? super U, ? super U, ? extends U> reducer; |
5866 |
|
U result; |
5867 |
< |
MapReduceMappingsTask<K,V,U> sibling; |
5867 |
> |
MapReduceMappingsTask<K,V,U> rights, nextRight; |
5868 |
|
MapReduceMappingsTask |
5869 |
|
(ConcurrentHashMapV8<K,V> m, |
5870 |
|
BiFun<? super K, ? super V, ? extends U> transformer, |
5874 |
|
this.reducer = reducer; |
5875 |
|
} |
5876 |
|
MapReduceMappingsTask |
5877 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5877 |
> |
(BulkTask<K,V,?> p, int b, |
5878 |
> |
MapReduceMappingsTask<K,V,U> nextRight, |
5879 |
|
BiFun<? super K, ? super V, ? extends U> transformer, |
5880 |
|
BiFun<? super U, ? super U, ? extends U> reducer) { |
5881 |
< |
super(p, b, split); |
5881 |
> |
super(p, b); this.nextRight = nextRight; |
5882 |
|
this.transformer = transformer; |
5883 |
|
this.reducer = reducer; |
5884 |
|
} |
5885 |
< |
public final void compute() { |
5822 |
< |
MapReduceMappingsTask<K,V,U> t = this; |
5885 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5886 |
|
final BiFun<? super K, ? super V, ? extends U> transformer = |
5887 |
|
this.transformer; |
5888 |
|
final BiFun<? super U, ? super U, ? extends U> reducer = |
5889 |
|
this.reducer; |
5890 |
|
if (transformer == null || reducer == null) |
5891 |
< |
throw new Error(NullFunctionMessage); |
5892 |
< |
int b = batch(); |
5893 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
5894 |
< |
b >>>= 1; |
5895 |
< |
t.pending = 1; |
5896 |
< |
MapReduceMappingsTask<K,V,U> rt = |
5897 |
< |
new MapReduceMappingsTask<K,V,U> |
5898 |
< |
(t, b, true, transformer, reducer); |
5899 |
< |
t = new MapReduceMappingsTask<K,V,U> |
5900 |
< |
(t, b, false, transformer, reducer); |
5901 |
< |
t.sibling = rt; |
5839 |
< |
rt.sibling = t; |
5840 |
< |
rt.fork(); |
5841 |
< |
} |
5842 |
< |
U r = null, u; |
5843 |
< |
Object v; |
5844 |
< |
while ((v = t.advance()) != null) { |
5845 |
< |
if ((u = transformer.apply((K)t.nextKey, (V)v)) != null) |
5846 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5847 |
< |
} |
5848 |
< |
for (;;) { |
5849 |
< |
int c; BulkTask<K,V,?> par; MapReduceMappingsTask<K,V,U> s, p; |
5850 |
< |
if ((par = t.parent) == null || |
5851 |
< |
!(par instanceof MapReduceMappingsTask)) { |
5852 |
< |
t.quietlyComplete(); |
5853 |
< |
break; |
5854 |
< |
} |
5855 |
< |
else if ((c = (p = (MapReduceMappingsTask<K,V,U>)par).pending) == 0) { |
5856 |
< |
if ((s = t.sibling) != null && (u = s.result) != null) |
5891 |
> |
return abortOnNullFunction(); |
5892 |
> |
try { |
5893 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
5894 |
> |
do {} while (!casPending(c = pending, c+1)); |
5895 |
> |
(rights = new MapReduceMappingsTask<K,V,U> |
5896 |
> |
(this, b >>>= 1, rights, transformer, reducer)).fork(); |
5897 |
> |
} |
5898 |
> |
U r = null, u; |
5899 |
> |
Object v; |
5900 |
> |
while ((v = advance()) != null) { |
5901 |
> |
if ((u = transformer.apply((K)nextKey, (V)v)) != null) |
5902 |
|
r = (r == null) ? u : reducer.apply(r, u); |
5858 |
– |
(t = p).result = r; |
5903 |
|
} |
5904 |
< |
else if (p.casPending(c, 0)) |
5905 |
< |
break; |
5904 |
> |
result = r; |
5905 |
> |
for (MapReduceMappingsTask<K,V,U> t = this, s;;) { |
5906 |
> |
int c; BulkTask<K,V,?> par; U tr, sr; |
5907 |
> |
if ((c = t.pending) == 0) { |
5908 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
5909 |
> |
if ((sr = s.result) != null) |
5910 |
> |
t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr); |
5911 |
> |
} |
5912 |
> |
if ((par = t.parent) == null || |
5913 |
> |
!(par instanceof MapReduceMappingsTask)) { |
5914 |
> |
t.quietlyComplete(); |
5915 |
> |
break; |
5916 |
> |
} |
5917 |
> |
t = (MapReduceMappingsTask<K,V,U>)par; |
5918 |
> |
} |
5919 |
> |
else if (t.casPending(c, c - 1)) |
5920 |
> |
break; |
5921 |
> |
} |
5922 |
> |
} catch (Throwable ex) { |
5923 |
> |
return tryCompleteComputation(ex); |
5924 |
|
} |
5925 |
+ |
return false; |
5926 |
|
} |
5927 |
|
public final U getRawResult() { return result; } |
5928 |
|
} |
5929 |
|
|
5930 |
< |
static final class MapReduceKeysToDoubleTask<K,V> |
5930 |
> |
@SuppressWarnings("serial") static final class MapReduceKeysToDoubleTask<K,V> |
5931 |
|
extends BulkTask<K,V,Double> { |
5932 |
|
final ObjectToDouble<? super K> transformer; |
5933 |
|
final DoubleByDoubleToDouble reducer; |
5934 |
|
final double basis; |
5935 |
|
double result; |
5936 |
< |
MapReduceKeysToDoubleTask<K,V> sibling; |
5936 |
> |
MapReduceKeysToDoubleTask<K,V> rights, nextRight; |
5937 |
|
MapReduceKeysToDoubleTask |
5938 |
|
(ConcurrentHashMapV8<K,V> m, |
5939 |
|
ObjectToDouble<? super K> transformer, |
5944 |
|
this.basis = basis; this.reducer = reducer; |
5945 |
|
} |
5946 |
|
MapReduceKeysToDoubleTask |
5947 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
5947 |
> |
(BulkTask<K,V,?> p, int b, |
5948 |
> |
MapReduceKeysToDoubleTask<K,V> nextRight, |
5949 |
|
ObjectToDouble<? super K> transformer, |
5950 |
|
double basis, |
5951 |
|
DoubleByDoubleToDouble reducer) { |
5952 |
< |
super(p, b, split); |
5952 |
> |
super(p, b); this.nextRight = nextRight; |
5953 |
|
this.transformer = transformer; |
5954 |
|
this.basis = basis; this.reducer = reducer; |
5955 |
|
} |
5956 |
< |
public final void compute() { |
5893 |
< |
MapReduceKeysToDoubleTask<K,V> t = this; |
5956 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
5957 |
|
final ObjectToDouble<? super K> transformer = |
5958 |
|
this.transformer; |
5959 |
|
final DoubleByDoubleToDouble reducer = this.reducer; |
5960 |
|
if (transformer == null || reducer == null) |
5961 |
< |
throw new Error(NullFunctionMessage); |
5962 |
< |
final double id = this.basis; |
5963 |
< |
int b = batch(); |
5964 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
5965 |
< |
b >>>= 1; |
5966 |
< |
t.pending = 1; |
5967 |
< |
MapReduceKeysToDoubleTask<K,V> rt = |
5968 |
< |
new MapReduceKeysToDoubleTask<K,V> |
5969 |
< |
(t, b, true, transformer, id, reducer); |
5970 |
< |
t = new MapReduceKeysToDoubleTask<K,V> |
5971 |
< |
(t, b, false, transformer, id, reducer); |
5972 |
< |
t.sibling = rt; |
5973 |
< |
rt.sibling = t; |
5974 |
< |
rt.fork(); |
5975 |
< |
} |
5976 |
< |
double r = id; |
5977 |
< |
while (t.advance() != null) |
5978 |
< |
r = reducer.apply(r, transformer.apply((K)t.nextKey)); |
5979 |
< |
t.result = r; |
5980 |
< |
for (;;) { |
5981 |
< |
int c; BulkTask<K,V,?> par; MapReduceKeysToDoubleTask<K,V> s, p; |
5982 |
< |
if ((par = t.parent) == null || |
5983 |
< |
!(par instanceof MapReduceKeysToDoubleTask)) { |
5984 |
< |
t.quietlyComplete(); |
5985 |
< |
break; |
5986 |
< |
} |
5987 |
< |
else if ((c = (p = (MapReduceKeysToDoubleTask<K,V>)par).pending) == 0) { |
5925 |
< |
if ((s = t.sibling) != null) |
5926 |
< |
r = reducer.apply(r, s.result); |
5927 |
< |
(t = p).result = r; |
5961 |
> |
return abortOnNullFunction(); |
5962 |
> |
try { |
5963 |
> |
final double id = this.basis; |
5964 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
5965 |
> |
do {} while (!casPending(c = pending, c+1)); |
5966 |
> |
(rights = new MapReduceKeysToDoubleTask<K,V> |
5967 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
5968 |
> |
} |
5969 |
> |
double r = id; |
5970 |
> |
while (advance() != null) |
5971 |
> |
r = reducer.apply(r, transformer.apply((K)nextKey)); |
5972 |
> |
result = r; |
5973 |
> |
for (MapReduceKeysToDoubleTask<K,V> t = this, s;;) { |
5974 |
> |
int c; BulkTask<K,V,?> par; |
5975 |
> |
if ((c = t.pending) == 0) { |
5976 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
5977 |
> |
t.result = reducer.apply(t.result, s.result); |
5978 |
> |
} |
5979 |
> |
if ((par = t.parent) == null || |
5980 |
> |
!(par instanceof MapReduceKeysToDoubleTask)) { |
5981 |
> |
t.quietlyComplete(); |
5982 |
> |
break; |
5983 |
> |
} |
5984 |
> |
t = (MapReduceKeysToDoubleTask<K,V>)par; |
5985 |
> |
} |
5986 |
> |
else if (t.casPending(c, c - 1)) |
5987 |
> |
break; |
5988 |
|
} |
5989 |
< |
else if (p.casPending(c, 0)) |
5990 |
< |
break; |
5989 |
> |
} catch (Throwable ex) { |
5990 |
> |
return tryCompleteComputation(ex); |
5991 |
|
} |
5992 |
+ |
return false; |
5993 |
|
} |
5994 |
|
public final Double getRawResult() { return result; } |
5995 |
|
} |
5996 |
|
|
5997 |
< |
static final class MapReduceValuesToDoubleTask<K,V> |
5997 |
> |
@SuppressWarnings("serial") static final class MapReduceValuesToDoubleTask<K,V> |
5998 |
|
extends BulkTask<K,V,Double> { |
5999 |
|
final ObjectToDouble<? super V> transformer; |
6000 |
|
final DoubleByDoubleToDouble reducer; |
6001 |
|
final double basis; |
6002 |
|
double result; |
6003 |
< |
MapReduceValuesToDoubleTask<K,V> sibling; |
6003 |
> |
MapReduceValuesToDoubleTask<K,V> rights, nextRight; |
6004 |
|
MapReduceValuesToDoubleTask |
6005 |
|
(ConcurrentHashMapV8<K,V> m, |
6006 |
|
ObjectToDouble<? super V> transformer, |
6011 |
|
this.basis = basis; this.reducer = reducer; |
6012 |
|
} |
6013 |
|
MapReduceValuesToDoubleTask |
6014 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6014 |
> |
(BulkTask<K,V,?> p, int b, |
6015 |
> |
MapReduceValuesToDoubleTask<K,V> nextRight, |
6016 |
|
ObjectToDouble<? super V> transformer, |
6017 |
|
double basis, |
6018 |
|
DoubleByDoubleToDouble reducer) { |
6019 |
< |
super(p, b, split); |
6019 |
> |
super(p, b); this.nextRight = nextRight; |
6020 |
|
this.transformer = transformer; |
6021 |
|
this.basis = basis; this.reducer = reducer; |
6022 |
|
} |
6023 |
< |
public final void compute() { |
5962 |
< |
MapReduceValuesToDoubleTask<K,V> t = this; |
6023 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6024 |
|
final ObjectToDouble<? super V> transformer = |
6025 |
|
this.transformer; |
6026 |
|
final DoubleByDoubleToDouble reducer = this.reducer; |
6027 |
|
if (transformer == null || reducer == null) |
6028 |
< |
throw new Error(NullFunctionMessage); |
6029 |
< |
final double id = this.basis; |
6030 |
< |
int b = batch(); |
6031 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6032 |
< |
b >>>= 1; |
6033 |
< |
t.pending = 1; |
6034 |
< |
MapReduceValuesToDoubleTask<K,V> rt = |
6035 |
< |
new MapReduceValuesToDoubleTask<K,V> |
6036 |
< |
(t, b, true, transformer, id, reducer); |
6037 |
< |
t = new MapReduceValuesToDoubleTask<K,V> |
6038 |
< |
(t, b, false, transformer, id, reducer); |
6039 |
< |
t.sibling = rt; |
6040 |
< |
rt.sibling = t; |
6041 |
< |
rt.fork(); |
6042 |
< |
} |
6043 |
< |
double r = id; |
6044 |
< |
Object v; |
6045 |
< |
while ((v = t.advance()) != null) |
6046 |
< |
r = reducer.apply(r, transformer.apply((V)v)); |
6047 |
< |
t.result = r; |
6048 |
< |
for (;;) { |
6049 |
< |
int c; BulkTask<K,V,?> par; MapReduceValuesToDoubleTask<K,V> s, p; |
6050 |
< |
if ((par = t.parent) == null || |
6051 |
< |
!(par instanceof MapReduceValuesToDoubleTask)) { |
6052 |
< |
t.quietlyComplete(); |
6053 |
< |
break; |
6054 |
< |
} |
6055 |
< |
else if ((c = (p = (MapReduceValuesToDoubleTask<K,V>)par).pending) == 0) { |
5995 |
< |
if ((s = t.sibling) != null) |
5996 |
< |
r = reducer.apply(r, s.result); |
5997 |
< |
(t = p).result = r; |
6028 |
> |
return abortOnNullFunction(); |
6029 |
> |
try { |
6030 |
> |
final double id = this.basis; |
6031 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6032 |
> |
do {} while (!casPending(c = pending, c+1)); |
6033 |
> |
(rights = new MapReduceValuesToDoubleTask<K,V> |
6034 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6035 |
> |
} |
6036 |
> |
double r = id; |
6037 |
> |
Object v; |
6038 |
> |
while ((v = advance()) != null) |
6039 |
> |
r = reducer.apply(r, transformer.apply((V)v)); |
6040 |
> |
result = r; |
6041 |
> |
for (MapReduceValuesToDoubleTask<K,V> t = this, s;;) { |
6042 |
> |
int c; BulkTask<K,V,?> par; |
6043 |
> |
if ((c = t.pending) == 0) { |
6044 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6045 |
> |
t.result = reducer.apply(t.result, s.result); |
6046 |
> |
} |
6047 |
> |
if ((par = t.parent) == null || |
6048 |
> |
!(par instanceof MapReduceValuesToDoubleTask)) { |
6049 |
> |
t.quietlyComplete(); |
6050 |
> |
break; |
6051 |
> |
} |
6052 |
> |
t = (MapReduceValuesToDoubleTask<K,V>)par; |
6053 |
> |
} |
6054 |
> |
else if (t.casPending(c, c - 1)) |
6055 |
> |
break; |
6056 |
|
} |
6057 |
< |
else if (p.casPending(c, 0)) |
6058 |
< |
break; |
6057 |
> |
} catch (Throwable ex) { |
6058 |
> |
return tryCompleteComputation(ex); |
6059 |
|
} |
6060 |
+ |
return false; |
6061 |
|
} |
6062 |
|
public final Double getRawResult() { return result; } |
6063 |
|
} |
6064 |
|
|
6065 |
< |
static final class MapReduceEntriesToDoubleTask<K,V> |
6065 |
> |
@SuppressWarnings("serial") static final class MapReduceEntriesToDoubleTask<K,V> |
6066 |
|
extends BulkTask<K,V,Double> { |
6067 |
|
final ObjectToDouble<Map.Entry<K,V>> transformer; |
6068 |
|
final DoubleByDoubleToDouble reducer; |
6069 |
|
final double basis; |
6070 |
|
double result; |
6071 |
< |
MapReduceEntriesToDoubleTask<K,V> sibling; |
6071 |
> |
MapReduceEntriesToDoubleTask<K,V> rights, nextRight; |
6072 |
|
MapReduceEntriesToDoubleTask |
6073 |
|
(ConcurrentHashMapV8<K,V> m, |
6074 |
|
ObjectToDouble<Map.Entry<K,V>> transformer, |
6079 |
|
this.basis = basis; this.reducer = reducer; |
6080 |
|
} |
6081 |
|
MapReduceEntriesToDoubleTask |
6082 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6082 |
> |
(BulkTask<K,V,?> p, int b, |
6083 |
> |
MapReduceEntriesToDoubleTask<K,V> nextRight, |
6084 |
|
ObjectToDouble<Map.Entry<K,V>> transformer, |
6085 |
|
double basis, |
6086 |
|
DoubleByDoubleToDouble reducer) { |
6087 |
< |
super(p, b, split); |
6087 |
> |
super(p, b); this.nextRight = nextRight; |
6088 |
|
this.transformer = transformer; |
6089 |
|
this.basis = basis; this.reducer = reducer; |
6090 |
|
} |
6091 |
< |
public final void compute() { |
6032 |
< |
MapReduceEntriesToDoubleTask<K,V> t = this; |
6091 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6092 |
|
final ObjectToDouble<Map.Entry<K,V>> transformer = |
6093 |
|
this.transformer; |
6094 |
|
final DoubleByDoubleToDouble reducer = this.reducer; |
6095 |
|
if (transformer == null || reducer == null) |
6096 |
< |
throw new Error(NullFunctionMessage); |
6097 |
< |
final double id = this.basis; |
6098 |
< |
int b = batch(); |
6099 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6100 |
< |
b >>>= 1; |
6101 |
< |
t.pending = 1; |
6102 |
< |
MapReduceEntriesToDoubleTask<K,V> rt = |
6103 |
< |
new MapReduceEntriesToDoubleTask<K,V> |
6104 |
< |
(t, b, true, transformer, id, reducer); |
6105 |
< |
t = new MapReduceEntriesToDoubleTask<K,V> |
6106 |
< |
(t, b, false, transformer, id, reducer); |
6107 |
< |
t.sibling = rt; |
6108 |
< |
rt.sibling = t; |
6109 |
< |
rt.fork(); |
6110 |
< |
} |
6111 |
< |
double r = id; |
6112 |
< |
Object v; |
6113 |
< |
while ((v = t.advance()) != null) |
6114 |
< |
r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v))); |
6115 |
< |
t.result = r; |
6116 |
< |
for (;;) { |
6117 |
< |
int c; BulkTask<K,V,?> par; MapReduceEntriesToDoubleTask<K,V> s, p; |
6118 |
< |
if ((par = t.parent) == null || |
6119 |
< |
!(par instanceof MapReduceEntriesToDoubleTask)) { |
6120 |
< |
t.quietlyComplete(); |
6121 |
< |
break; |
6122 |
< |
} |
6123 |
< |
else if ((c = (p = (MapReduceEntriesToDoubleTask<K,V>)par).pending) == 0) { |
6065 |
< |
if ((s = t.sibling) != null) |
6066 |
< |
r = reducer.apply(r, s.result); |
6067 |
< |
(t = p).result = r; |
6096 |
> |
return abortOnNullFunction(); |
6097 |
> |
try { |
6098 |
> |
final double id = this.basis; |
6099 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6100 |
> |
do {} while (!casPending(c = pending, c+1)); |
6101 |
> |
(rights = new MapReduceEntriesToDoubleTask<K,V> |
6102 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6103 |
> |
} |
6104 |
> |
double r = id; |
6105 |
> |
Object v; |
6106 |
> |
while ((v = advance()) != null) |
6107 |
> |
r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v))); |
6108 |
> |
result = r; |
6109 |
> |
for (MapReduceEntriesToDoubleTask<K,V> t = this, s;;) { |
6110 |
> |
int c; BulkTask<K,V,?> par; |
6111 |
> |
if ((c = t.pending) == 0) { |
6112 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6113 |
> |
t.result = reducer.apply(t.result, s.result); |
6114 |
> |
} |
6115 |
> |
if ((par = t.parent) == null || |
6116 |
> |
!(par instanceof MapReduceEntriesToDoubleTask)) { |
6117 |
> |
t.quietlyComplete(); |
6118 |
> |
break; |
6119 |
> |
} |
6120 |
> |
t = (MapReduceEntriesToDoubleTask<K,V>)par; |
6121 |
> |
} |
6122 |
> |
else if (t.casPending(c, c - 1)) |
6123 |
> |
break; |
6124 |
|
} |
6125 |
< |
else if (p.casPending(c, 0)) |
6126 |
< |
break; |
6125 |
> |
} catch (Throwable ex) { |
6126 |
> |
return tryCompleteComputation(ex); |
6127 |
|
} |
6128 |
+ |
return false; |
6129 |
|
} |
6130 |
|
public final Double getRawResult() { return result; } |
6131 |
|
} |
6132 |
|
|
6133 |
< |
static final class MapReduceMappingsToDoubleTask<K,V> |
6133 |
> |
@SuppressWarnings("serial") static final class MapReduceMappingsToDoubleTask<K,V> |
6134 |
|
extends BulkTask<K,V,Double> { |
6135 |
|
final ObjectByObjectToDouble<? super K, ? super V> transformer; |
6136 |
|
final DoubleByDoubleToDouble reducer; |
6137 |
|
final double basis; |
6138 |
|
double result; |
6139 |
< |
MapReduceMappingsToDoubleTask<K,V> sibling; |
6139 |
> |
MapReduceMappingsToDoubleTask<K,V> rights, nextRight; |
6140 |
|
MapReduceMappingsToDoubleTask |
6141 |
|
(ConcurrentHashMapV8<K,V> m, |
6142 |
|
ObjectByObjectToDouble<? super K, ? super V> transformer, |
6147 |
|
this.basis = basis; this.reducer = reducer; |
6148 |
|
} |
6149 |
|
MapReduceMappingsToDoubleTask |
6150 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6150 |
> |
(BulkTask<K,V,?> p, int b, |
6151 |
> |
MapReduceMappingsToDoubleTask<K,V> nextRight, |
6152 |
|
ObjectByObjectToDouble<? super K, ? super V> transformer, |
6153 |
|
double basis, |
6154 |
|
DoubleByDoubleToDouble reducer) { |
6155 |
< |
super(p, b, split); |
6155 |
> |
super(p, b); this.nextRight = nextRight; |
6156 |
|
this.transformer = transformer; |
6157 |
|
this.basis = basis; this.reducer = reducer; |
6158 |
|
} |
6159 |
< |
public final void compute() { |
6102 |
< |
MapReduceMappingsToDoubleTask<K,V> t = this; |
6159 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6160 |
|
final ObjectByObjectToDouble<? super K, ? super V> transformer = |
6161 |
|
this.transformer; |
6162 |
|
final DoubleByDoubleToDouble reducer = this.reducer; |
6163 |
|
if (transformer == null || reducer == null) |
6164 |
< |
throw new Error(NullFunctionMessage); |
6165 |
< |
final double id = this.basis; |
6166 |
< |
int b = batch(); |
6167 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6168 |
< |
b >>>= 1; |
6169 |
< |
t.pending = 1; |
6170 |
< |
MapReduceMappingsToDoubleTask<K,V> rt = |
6171 |
< |
new MapReduceMappingsToDoubleTask<K,V> |
6172 |
< |
(t, b, true, transformer, id, reducer); |
6173 |
< |
t = new MapReduceMappingsToDoubleTask<K,V> |
6174 |
< |
(t, b, false, transformer, id, reducer); |
6175 |
< |
t.sibling = rt; |
6176 |
< |
rt.sibling = t; |
6177 |
< |
rt.fork(); |
6178 |
< |
} |
6179 |
< |
double r = id; |
6180 |
< |
Object v; |
6181 |
< |
while ((v = t.advance()) != null) |
6182 |
< |
r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v)); |
6183 |
< |
t.result = r; |
6184 |
< |
for (;;) { |
6185 |
< |
int c; BulkTask<K,V,?> par; MapReduceMappingsToDoubleTask<K,V> s, p; |
6186 |
< |
if ((par = t.parent) == null || |
6187 |
< |
!(par instanceof MapReduceMappingsToDoubleTask)) { |
6188 |
< |
t.quietlyComplete(); |
6189 |
< |
break; |
6190 |
< |
} |
6191 |
< |
else if ((c = (p = (MapReduceMappingsToDoubleTask<K,V>)par).pending) == 0) { |
6135 |
< |
if ((s = t.sibling) != null) |
6136 |
< |
r = reducer.apply(r, s.result); |
6137 |
< |
(t = p).result = r; |
6164 |
> |
return abortOnNullFunction(); |
6165 |
> |
try { |
6166 |
> |
final double id = this.basis; |
6167 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6168 |
> |
do {} while (!casPending(c = pending, c+1)); |
6169 |
> |
(rights = new MapReduceMappingsToDoubleTask<K,V> |
6170 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6171 |
> |
} |
6172 |
> |
double r = id; |
6173 |
> |
Object v; |
6174 |
> |
while ((v = advance()) != null) |
6175 |
> |
r = reducer.apply(r, transformer.apply((K)nextKey, (V)v)); |
6176 |
> |
result = r; |
6177 |
> |
for (MapReduceMappingsToDoubleTask<K,V> t = this, s;;) { |
6178 |
> |
int c; BulkTask<K,V,?> par; |
6179 |
> |
if ((c = t.pending) == 0) { |
6180 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6181 |
> |
t.result = reducer.apply(t.result, s.result); |
6182 |
> |
} |
6183 |
> |
if ((par = t.parent) == null || |
6184 |
> |
!(par instanceof MapReduceMappingsToDoubleTask)) { |
6185 |
> |
t.quietlyComplete(); |
6186 |
> |
break; |
6187 |
> |
} |
6188 |
> |
t = (MapReduceMappingsToDoubleTask<K,V>)par; |
6189 |
> |
} |
6190 |
> |
else if (t.casPending(c, c - 1)) |
6191 |
> |
break; |
6192 |
|
} |
6193 |
< |
else if (p.casPending(c, 0)) |
6194 |
< |
break; |
6193 |
> |
} catch (Throwable ex) { |
6194 |
> |
return tryCompleteComputation(ex); |
6195 |
|
} |
6196 |
+ |
return false; |
6197 |
|
} |
6198 |
|
public final Double getRawResult() { return result; } |
6199 |
|
} |
6200 |
|
|
6201 |
< |
static final class MapReduceKeysToLongTask<K,V> |
6201 |
> |
@SuppressWarnings("serial") static final class MapReduceKeysToLongTask<K,V> |
6202 |
|
extends BulkTask<K,V,Long> { |
6203 |
|
final ObjectToLong<? super K> transformer; |
6204 |
|
final LongByLongToLong reducer; |
6205 |
|
final long basis; |
6206 |
|
long result; |
6207 |
< |
MapReduceKeysToLongTask<K,V> sibling; |
6207 |
> |
MapReduceKeysToLongTask<K,V> rights, nextRight; |
6208 |
|
MapReduceKeysToLongTask |
6209 |
|
(ConcurrentHashMapV8<K,V> m, |
6210 |
|
ObjectToLong<? super K> transformer, |
6215 |
|
this.basis = basis; this.reducer = reducer; |
6216 |
|
} |
6217 |
|
MapReduceKeysToLongTask |
6218 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6218 |
> |
(BulkTask<K,V,?> p, int b, |
6219 |
> |
MapReduceKeysToLongTask<K,V> nextRight, |
6220 |
|
ObjectToLong<? super K> transformer, |
6221 |
|
long basis, |
6222 |
|
LongByLongToLong reducer) { |
6223 |
< |
super(p, b, split); |
6223 |
> |
super(p, b); this.nextRight = nextRight; |
6224 |
|
this.transformer = transformer; |
6225 |
|
this.basis = basis; this.reducer = reducer; |
6226 |
|
} |
6227 |
< |
public final void compute() { |
6172 |
< |
MapReduceKeysToLongTask<K,V> t = this; |
6227 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6228 |
|
final ObjectToLong<? super K> transformer = |
6229 |
|
this.transformer; |
6230 |
|
final LongByLongToLong reducer = this.reducer; |
6231 |
|
if (transformer == null || reducer == null) |
6232 |
< |
throw new Error(NullFunctionMessage); |
6233 |
< |
final long id = this.basis; |
6234 |
< |
int b = batch(); |
6235 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6236 |
< |
b >>>= 1; |
6237 |
< |
t.pending = 1; |
6238 |
< |
MapReduceKeysToLongTask<K,V> rt = |
6239 |
< |
new MapReduceKeysToLongTask<K,V> |
6240 |
< |
(t, b, true, transformer, id, reducer); |
6241 |
< |
t = new MapReduceKeysToLongTask<K,V> |
6242 |
< |
(t, b, false, transformer, id, reducer); |
6243 |
< |
t.sibling = rt; |
6244 |
< |
rt.sibling = t; |
6245 |
< |
rt.fork(); |
6246 |
< |
} |
6247 |
< |
long r = id; |
6248 |
< |
while (t.advance() != null) |
6249 |
< |
r = reducer.apply(r, transformer.apply((K)t.nextKey)); |
6250 |
< |
t.result = r; |
6251 |
< |
for (;;) { |
6252 |
< |
int c; BulkTask<K,V,?> par; MapReduceKeysToLongTask<K,V> s, p; |
6253 |
< |
if ((par = t.parent) == null || |
6254 |
< |
!(par instanceof MapReduceKeysToLongTask)) { |
6255 |
< |
t.quietlyComplete(); |
6256 |
< |
break; |
6257 |
< |
} |
6258 |
< |
else if ((c = (p = (MapReduceKeysToLongTask<K,V>)par).pending) == 0) { |
6204 |
< |
if ((s = t.sibling) != null) |
6205 |
< |
r = reducer.apply(r, s.result); |
6206 |
< |
(t = p).result = r; |
6232 |
> |
return abortOnNullFunction(); |
6233 |
> |
try { |
6234 |
> |
final long id = this.basis; |
6235 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6236 |
> |
do {} while (!casPending(c = pending, c+1)); |
6237 |
> |
(rights = new MapReduceKeysToLongTask<K,V> |
6238 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6239 |
> |
} |
6240 |
> |
long r = id; |
6241 |
> |
while (advance() != null) |
6242 |
> |
r = reducer.apply(r, transformer.apply((K)nextKey)); |
6243 |
> |
result = r; |
6244 |
> |
for (MapReduceKeysToLongTask<K,V> t = this, s;;) { |
6245 |
> |
int c; BulkTask<K,V,?> par; |
6246 |
> |
if ((c = t.pending) == 0) { |
6247 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6248 |
> |
t.result = reducer.apply(t.result, s.result); |
6249 |
> |
} |
6250 |
> |
if ((par = t.parent) == null || |
6251 |
> |
!(par instanceof MapReduceKeysToLongTask)) { |
6252 |
> |
t.quietlyComplete(); |
6253 |
> |
break; |
6254 |
> |
} |
6255 |
> |
t = (MapReduceKeysToLongTask<K,V>)par; |
6256 |
> |
} |
6257 |
> |
else if (t.casPending(c, c - 1)) |
6258 |
> |
break; |
6259 |
|
} |
6260 |
< |
else if (p.casPending(c, 0)) |
6261 |
< |
break; |
6260 |
> |
} catch (Throwable ex) { |
6261 |
> |
return tryCompleteComputation(ex); |
6262 |
|
} |
6263 |
+ |
return false; |
6264 |
|
} |
6265 |
|
public final Long getRawResult() { return result; } |
6266 |
|
} |
6267 |
|
|
6268 |
< |
static final class MapReduceValuesToLongTask<K,V> |
6268 |
> |
@SuppressWarnings("serial") static final class MapReduceValuesToLongTask<K,V> |
6269 |
|
extends BulkTask<K,V,Long> { |
6270 |
|
final ObjectToLong<? super V> transformer; |
6271 |
|
final LongByLongToLong reducer; |
6272 |
|
final long basis; |
6273 |
|
long result; |
6274 |
< |
MapReduceValuesToLongTask<K,V> sibling; |
6274 |
> |
MapReduceValuesToLongTask<K,V> rights, nextRight; |
6275 |
|
MapReduceValuesToLongTask |
6276 |
|
(ConcurrentHashMapV8<K,V> m, |
6277 |
|
ObjectToLong<? super V> transformer, |
6282 |
|
this.basis = basis; this.reducer = reducer; |
6283 |
|
} |
6284 |
|
MapReduceValuesToLongTask |
6285 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6285 |
> |
(BulkTask<K,V,?> p, int b, |
6286 |
> |
MapReduceValuesToLongTask<K,V> nextRight, |
6287 |
|
ObjectToLong<? super V> transformer, |
6288 |
|
long basis, |
6289 |
|
LongByLongToLong reducer) { |
6290 |
< |
super(p, b, split); |
6290 |
> |
super(p, b); this.nextRight = nextRight; |
6291 |
|
this.transformer = transformer; |
6292 |
|
this.basis = basis; this.reducer = reducer; |
6293 |
|
} |
6294 |
< |
public final void compute() { |
6241 |
< |
MapReduceValuesToLongTask<K,V> t = this; |
6294 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6295 |
|
final ObjectToLong<? super V> transformer = |
6296 |
|
this.transformer; |
6297 |
|
final LongByLongToLong reducer = this.reducer; |
6298 |
|
if (transformer == null || reducer == null) |
6299 |
< |
throw new Error(NullFunctionMessage); |
6300 |
< |
final long id = this.basis; |
6301 |
< |
int b = batch(); |
6302 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6303 |
< |
b >>>= 1; |
6304 |
< |
t.pending = 1; |
6305 |
< |
MapReduceValuesToLongTask<K,V> rt = |
6306 |
< |
new MapReduceValuesToLongTask<K,V> |
6307 |
< |
(t, b, true, transformer, id, reducer); |
6308 |
< |
t = new MapReduceValuesToLongTask<K,V> |
6309 |
< |
(t, b, false, transformer, id, reducer); |
6310 |
< |
t.sibling = rt; |
6311 |
< |
rt.sibling = t; |
6312 |
< |
rt.fork(); |
6313 |
< |
} |
6314 |
< |
long r = id; |
6315 |
< |
Object v; |
6316 |
< |
while ((v = t.advance()) != null) |
6317 |
< |
r = reducer.apply(r, transformer.apply((V)v)); |
6318 |
< |
t.result = r; |
6319 |
< |
for (;;) { |
6320 |
< |
int c; BulkTask<K,V,?> par; MapReduceValuesToLongTask<K,V> s, p; |
6321 |
< |
if ((par = t.parent) == null || |
6322 |
< |
!(par instanceof MapReduceValuesToLongTask)) { |
6323 |
< |
t.quietlyComplete(); |
6324 |
< |
break; |
6325 |
< |
} |
6326 |
< |
else if ((c = (p = (MapReduceValuesToLongTask<K,V>)par).pending) == 0) { |
6274 |
< |
if ((s = t.sibling) != null) |
6275 |
< |
r = reducer.apply(r, s.result); |
6276 |
< |
(t = p).result = r; |
6299 |
> |
return abortOnNullFunction(); |
6300 |
> |
try { |
6301 |
> |
final long id = this.basis; |
6302 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6303 |
> |
do {} while (!casPending(c = pending, c+1)); |
6304 |
> |
(rights = new MapReduceValuesToLongTask<K,V> |
6305 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6306 |
> |
} |
6307 |
> |
long r = id; |
6308 |
> |
Object v; |
6309 |
> |
while ((v = advance()) != null) |
6310 |
> |
r = reducer.apply(r, transformer.apply((V)v)); |
6311 |
> |
result = r; |
6312 |
> |
for (MapReduceValuesToLongTask<K,V> t = this, s;;) { |
6313 |
> |
int c; BulkTask<K,V,?> par; |
6314 |
> |
if ((c = t.pending) == 0) { |
6315 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6316 |
> |
t.result = reducer.apply(t.result, s.result); |
6317 |
> |
} |
6318 |
> |
if ((par = t.parent) == null || |
6319 |
> |
!(par instanceof MapReduceValuesToLongTask)) { |
6320 |
> |
t.quietlyComplete(); |
6321 |
> |
break; |
6322 |
> |
} |
6323 |
> |
t = (MapReduceValuesToLongTask<K,V>)par; |
6324 |
> |
} |
6325 |
> |
else if (t.casPending(c, c - 1)) |
6326 |
> |
break; |
6327 |
|
} |
6328 |
< |
else if (p.casPending(c, 0)) |
6329 |
< |
break; |
6328 |
> |
} catch (Throwable ex) { |
6329 |
> |
return tryCompleteComputation(ex); |
6330 |
|
} |
6331 |
+ |
return false; |
6332 |
|
} |
6333 |
|
public final Long getRawResult() { return result; } |
6334 |
|
} |
6335 |
|
|
6336 |
< |
static final class MapReduceEntriesToLongTask<K,V> |
6336 |
> |
@SuppressWarnings("serial") static final class MapReduceEntriesToLongTask<K,V> |
6337 |
|
extends BulkTask<K,V,Long> { |
6338 |
|
final ObjectToLong<Map.Entry<K,V>> transformer; |
6339 |
|
final LongByLongToLong reducer; |
6340 |
|
final long basis; |
6341 |
|
long result; |
6342 |
< |
MapReduceEntriesToLongTask<K,V> sibling; |
6342 |
> |
MapReduceEntriesToLongTask<K,V> rights, nextRight; |
6343 |
|
MapReduceEntriesToLongTask |
6344 |
|
(ConcurrentHashMapV8<K,V> m, |
6345 |
|
ObjectToLong<Map.Entry<K,V>> transformer, |
6350 |
|
this.basis = basis; this.reducer = reducer; |
6351 |
|
} |
6352 |
|
MapReduceEntriesToLongTask |
6353 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6353 |
> |
(BulkTask<K,V,?> p, int b, |
6354 |
> |
MapReduceEntriesToLongTask<K,V> nextRight, |
6355 |
|
ObjectToLong<Map.Entry<K,V>> transformer, |
6356 |
|
long basis, |
6357 |
|
LongByLongToLong reducer) { |
6358 |
< |
super(p, b, split); |
6358 |
> |
super(p, b); this.nextRight = nextRight; |
6359 |
|
this.transformer = transformer; |
6360 |
|
this.basis = basis; this.reducer = reducer; |
6361 |
|
} |
6362 |
< |
public final void compute() { |
6311 |
< |
MapReduceEntriesToLongTask<K,V> t = this; |
6362 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6363 |
|
final ObjectToLong<Map.Entry<K,V>> transformer = |
6364 |
|
this.transformer; |
6365 |
|
final LongByLongToLong reducer = this.reducer; |
6366 |
|
if (transformer == null || reducer == null) |
6367 |
< |
throw new Error(NullFunctionMessage); |
6368 |
< |
final long id = this.basis; |
6369 |
< |
int b = batch(); |
6370 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6371 |
< |
b >>>= 1; |
6372 |
< |
t.pending = 1; |
6373 |
< |
MapReduceEntriesToLongTask<K,V> rt = |
6374 |
< |
new MapReduceEntriesToLongTask<K,V> |
6375 |
< |
(t, b, true, transformer, id, reducer); |
6376 |
< |
t = new MapReduceEntriesToLongTask<K,V> |
6377 |
< |
(t, b, false, transformer, id, reducer); |
6378 |
< |
t.sibling = rt; |
6379 |
< |
rt.sibling = t; |
6380 |
< |
rt.fork(); |
6381 |
< |
} |
6382 |
< |
long r = id; |
6383 |
< |
Object v; |
6384 |
< |
while ((v = t.advance()) != null) |
6385 |
< |
r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v))); |
6386 |
< |
t.result = r; |
6387 |
< |
for (;;) { |
6388 |
< |
int c; BulkTask<K,V,?> par; MapReduceEntriesToLongTask<K,V> s, p; |
6389 |
< |
if ((par = t.parent) == null || |
6390 |
< |
!(par instanceof MapReduceEntriesToLongTask)) { |
6391 |
< |
t.quietlyComplete(); |
6392 |
< |
break; |
6393 |
< |
} |
6394 |
< |
else if ((c = (p = (MapReduceEntriesToLongTask<K,V>)par).pending) == 0) { |
6344 |
< |
if ((s = t.sibling) != null) |
6345 |
< |
r = reducer.apply(r, s.result); |
6346 |
< |
(t = p).result = r; |
6367 |
> |
return abortOnNullFunction(); |
6368 |
> |
try { |
6369 |
> |
final long id = this.basis; |
6370 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6371 |
> |
do {} while (!casPending(c = pending, c+1)); |
6372 |
> |
(rights = new MapReduceEntriesToLongTask<K,V> |
6373 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6374 |
> |
} |
6375 |
> |
long r = id; |
6376 |
> |
Object v; |
6377 |
> |
while ((v = advance()) != null) |
6378 |
> |
r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v))); |
6379 |
> |
result = r; |
6380 |
> |
for (MapReduceEntriesToLongTask<K,V> t = this, s;;) { |
6381 |
> |
int c; BulkTask<K,V,?> par; |
6382 |
> |
if ((c = t.pending) == 0) { |
6383 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6384 |
> |
t.result = reducer.apply(t.result, s.result); |
6385 |
> |
} |
6386 |
> |
if ((par = t.parent) == null || |
6387 |
> |
!(par instanceof MapReduceEntriesToLongTask)) { |
6388 |
> |
t.quietlyComplete(); |
6389 |
> |
break; |
6390 |
> |
} |
6391 |
> |
t = (MapReduceEntriesToLongTask<K,V>)par; |
6392 |
> |
} |
6393 |
> |
else if (t.casPending(c, c - 1)) |
6394 |
> |
break; |
6395 |
|
} |
6396 |
< |
else if (p.casPending(c, 0)) |
6397 |
< |
break; |
6396 |
> |
} catch (Throwable ex) { |
6397 |
> |
return tryCompleteComputation(ex); |
6398 |
|
} |
6399 |
+ |
return false; |
6400 |
|
} |
6401 |
|
public final Long getRawResult() { return result; } |
6402 |
|
} |
6403 |
|
|
6404 |
< |
static final class MapReduceMappingsToLongTask<K,V> |
6404 |
> |
@SuppressWarnings("serial") static final class MapReduceMappingsToLongTask<K,V> |
6405 |
|
extends BulkTask<K,V,Long> { |
6406 |
|
final ObjectByObjectToLong<? super K, ? super V> transformer; |
6407 |
|
final LongByLongToLong reducer; |
6408 |
|
final long basis; |
6409 |
|
long result; |
6410 |
< |
MapReduceMappingsToLongTask<K,V> sibling; |
6410 |
> |
MapReduceMappingsToLongTask<K,V> rights, nextRight; |
6411 |
|
MapReduceMappingsToLongTask |
6412 |
|
(ConcurrentHashMapV8<K,V> m, |
6413 |
|
ObjectByObjectToLong<? super K, ? super V> transformer, |
6418 |
|
this.basis = basis; this.reducer = reducer; |
6419 |
|
} |
6420 |
|
MapReduceMappingsToLongTask |
6421 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6421 |
> |
(BulkTask<K,V,?> p, int b, |
6422 |
> |
MapReduceMappingsToLongTask<K,V> nextRight, |
6423 |
|
ObjectByObjectToLong<? super K, ? super V> transformer, |
6424 |
|
long basis, |
6425 |
|
LongByLongToLong reducer) { |
6426 |
< |
super(p, b, split); |
6426 |
> |
super(p, b); this.nextRight = nextRight; |
6427 |
|
this.transformer = transformer; |
6428 |
|
this.basis = basis; this.reducer = reducer; |
6429 |
|
} |
6430 |
< |
public final void compute() { |
6381 |
< |
MapReduceMappingsToLongTask<K,V> t = this; |
6430 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6431 |
|
final ObjectByObjectToLong<? super K, ? super V> transformer = |
6432 |
|
this.transformer; |
6433 |
|
final LongByLongToLong reducer = this.reducer; |
6434 |
|
if (transformer == null || reducer == null) |
6435 |
< |
throw new Error(NullFunctionMessage); |
6436 |
< |
final long id = this.basis; |
6437 |
< |
int b = batch(); |
6438 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6439 |
< |
b >>>= 1; |
6440 |
< |
t.pending = 1; |
6441 |
< |
MapReduceMappingsToLongTask<K,V> rt = |
6442 |
< |
new MapReduceMappingsToLongTask<K,V> |
6443 |
< |
(t, b, true, transformer, id, reducer); |
6444 |
< |
t = new MapReduceMappingsToLongTask<K,V> |
6445 |
< |
(t, b, false, transformer, id, reducer); |
6446 |
< |
t.sibling = rt; |
6447 |
< |
rt.sibling = t; |
6448 |
< |
rt.fork(); |
6449 |
< |
} |
6450 |
< |
long r = id; |
6451 |
< |
Object v; |
6452 |
< |
while ((v = t.advance()) != null) |
6453 |
< |
r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v)); |
6454 |
< |
t.result = r; |
6455 |
< |
for (;;) { |
6456 |
< |
int c; BulkTask<K,V,?> par; MapReduceMappingsToLongTask<K,V> s, p; |
6457 |
< |
if ((par = t.parent) == null || |
6458 |
< |
!(par instanceof MapReduceMappingsToLongTask)) { |
6459 |
< |
t.quietlyComplete(); |
6460 |
< |
break; |
6461 |
< |
} |
6462 |
< |
else if ((c = (p = (MapReduceMappingsToLongTask<K,V>)par).pending) == 0) { |
6414 |
< |
if ((s = t.sibling) != null) |
6415 |
< |
r = reducer.apply(r, s.result); |
6416 |
< |
(t = p).result = r; |
6435 |
> |
return abortOnNullFunction(); |
6436 |
> |
try { |
6437 |
> |
final long id = this.basis; |
6438 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6439 |
> |
do {} while (!casPending(c = pending, c+1)); |
6440 |
> |
(rights = new MapReduceMappingsToLongTask<K,V> |
6441 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6442 |
> |
} |
6443 |
> |
long r = id; |
6444 |
> |
Object v; |
6445 |
> |
while ((v = advance()) != null) |
6446 |
> |
r = reducer.apply(r, transformer.apply((K)nextKey, (V)v)); |
6447 |
> |
result = r; |
6448 |
> |
for (MapReduceMappingsToLongTask<K,V> t = this, s;;) { |
6449 |
> |
int c; BulkTask<K,V,?> par; |
6450 |
> |
if ((c = t.pending) == 0) { |
6451 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6452 |
> |
t.result = reducer.apply(t.result, s.result); |
6453 |
> |
} |
6454 |
> |
if ((par = t.parent) == null || |
6455 |
> |
!(par instanceof MapReduceMappingsToLongTask)) { |
6456 |
> |
t.quietlyComplete(); |
6457 |
> |
break; |
6458 |
> |
} |
6459 |
> |
t = (MapReduceMappingsToLongTask<K,V>)par; |
6460 |
> |
} |
6461 |
> |
else if (t.casPending(c, c - 1)) |
6462 |
> |
break; |
6463 |
|
} |
6464 |
< |
else if (p.casPending(c, 0)) |
6465 |
< |
break; |
6464 |
> |
} catch (Throwable ex) { |
6465 |
> |
return tryCompleteComputation(ex); |
6466 |
|
} |
6467 |
+ |
return false; |
6468 |
|
} |
6469 |
|
public final Long getRawResult() { return result; } |
6470 |
|
} |
6471 |
|
|
6472 |
< |
static final class MapReduceKeysToIntTask<K,V> |
6472 |
> |
@SuppressWarnings("serial") static final class MapReduceKeysToIntTask<K,V> |
6473 |
|
extends BulkTask<K,V,Integer> { |
6474 |
|
final ObjectToInt<? super K> transformer; |
6475 |
|
final IntByIntToInt reducer; |
6476 |
|
final int basis; |
6477 |
|
int result; |
6478 |
< |
MapReduceKeysToIntTask<K,V> sibling; |
6478 |
> |
MapReduceKeysToIntTask<K,V> rights, nextRight; |
6479 |
|
MapReduceKeysToIntTask |
6480 |
|
(ConcurrentHashMapV8<K,V> m, |
6481 |
|
ObjectToInt<? super K> transformer, |
6486 |
|
this.basis = basis; this.reducer = reducer; |
6487 |
|
} |
6488 |
|
MapReduceKeysToIntTask |
6489 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6489 |
> |
(BulkTask<K,V,?> p, int b, |
6490 |
> |
MapReduceKeysToIntTask<K,V> nextRight, |
6491 |
|
ObjectToInt<? super K> transformer, |
6492 |
|
int basis, |
6493 |
|
IntByIntToInt reducer) { |
6494 |
< |
super(p, b, split); |
6494 |
> |
super(p, b); this.nextRight = nextRight; |
6495 |
|
this.transformer = transformer; |
6496 |
|
this.basis = basis; this.reducer = reducer; |
6497 |
|
} |
6498 |
< |
public final void compute() { |
6451 |
< |
MapReduceKeysToIntTask<K,V> t = this; |
6498 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6499 |
|
final ObjectToInt<? super K> transformer = |
6500 |
|
this.transformer; |
6501 |
|
final IntByIntToInt reducer = this.reducer; |
6502 |
|
if (transformer == null || reducer == null) |
6503 |
< |
throw new Error(NullFunctionMessage); |
6504 |
< |
final int id = this.basis; |
6505 |
< |
int b = batch(); |
6506 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6507 |
< |
b >>>= 1; |
6508 |
< |
t.pending = 1; |
6509 |
< |
MapReduceKeysToIntTask<K,V> rt = |
6510 |
< |
new MapReduceKeysToIntTask<K,V> |
6511 |
< |
(t, b, true, transformer, id, reducer); |
6512 |
< |
t = new MapReduceKeysToIntTask<K,V> |
6513 |
< |
(t, b, false, transformer, id, reducer); |
6514 |
< |
t.sibling = rt; |
6515 |
< |
rt.sibling = t; |
6516 |
< |
rt.fork(); |
6517 |
< |
} |
6518 |
< |
int r = id; |
6519 |
< |
while (t.advance() != null) |
6520 |
< |
r = reducer.apply(r, transformer.apply((K)t.nextKey)); |
6521 |
< |
t.result = r; |
6522 |
< |
for (;;) { |
6523 |
< |
int c; BulkTask<K,V,?> par; MapReduceKeysToIntTask<K,V> s, p; |
6524 |
< |
if ((par = t.parent) == null || |
6525 |
< |
!(par instanceof MapReduceKeysToIntTask)) { |
6526 |
< |
t.quietlyComplete(); |
6527 |
< |
break; |
6528 |
< |
} |
6529 |
< |
else if ((c = (p = (MapReduceKeysToIntTask<K,V>)par).pending) == 0) { |
6483 |
< |
if ((s = t.sibling) != null) |
6484 |
< |
r = reducer.apply(r, s.result); |
6485 |
< |
(t = p).result = r; |
6503 |
> |
return abortOnNullFunction(); |
6504 |
> |
try { |
6505 |
> |
final int id = this.basis; |
6506 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6507 |
> |
do {} while (!casPending(c = pending, c+1)); |
6508 |
> |
(rights = new MapReduceKeysToIntTask<K,V> |
6509 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6510 |
> |
} |
6511 |
> |
int r = id; |
6512 |
> |
while (advance() != null) |
6513 |
> |
r = reducer.apply(r, transformer.apply((K)nextKey)); |
6514 |
> |
result = r; |
6515 |
> |
for (MapReduceKeysToIntTask<K,V> t = this, s;;) { |
6516 |
> |
int c; BulkTask<K,V,?> par; |
6517 |
> |
if ((c = t.pending) == 0) { |
6518 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6519 |
> |
t.result = reducer.apply(t.result, s.result); |
6520 |
> |
} |
6521 |
> |
if ((par = t.parent) == null || |
6522 |
> |
!(par instanceof MapReduceKeysToIntTask)) { |
6523 |
> |
t.quietlyComplete(); |
6524 |
> |
break; |
6525 |
> |
} |
6526 |
> |
t = (MapReduceKeysToIntTask<K,V>)par; |
6527 |
> |
} |
6528 |
> |
else if (t.casPending(c, c - 1)) |
6529 |
> |
break; |
6530 |
|
} |
6531 |
< |
else if (p.casPending(c, 0)) |
6532 |
< |
break; |
6531 |
> |
} catch (Throwable ex) { |
6532 |
> |
return tryCompleteComputation(ex); |
6533 |
|
} |
6534 |
+ |
return false; |
6535 |
|
} |
6536 |
|
public final Integer getRawResult() { return result; } |
6537 |
|
} |
6538 |
|
|
6539 |
< |
static final class MapReduceValuesToIntTask<K,V> |
6539 |
> |
@SuppressWarnings("serial") static final class MapReduceValuesToIntTask<K,V> |
6540 |
|
extends BulkTask<K,V,Integer> { |
6541 |
|
final ObjectToInt<? super V> transformer; |
6542 |
|
final IntByIntToInt reducer; |
6543 |
|
final int basis; |
6544 |
|
int result; |
6545 |
< |
MapReduceValuesToIntTask<K,V> sibling; |
6545 |
> |
MapReduceValuesToIntTask<K,V> rights, nextRight; |
6546 |
|
MapReduceValuesToIntTask |
6547 |
|
(ConcurrentHashMapV8<K,V> m, |
6548 |
|
ObjectToInt<? super V> transformer, |
6553 |
|
this.basis = basis; this.reducer = reducer; |
6554 |
|
} |
6555 |
|
MapReduceValuesToIntTask |
6556 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6556 |
> |
(BulkTask<K,V,?> p, int b, |
6557 |
> |
MapReduceValuesToIntTask<K,V> nextRight, |
6558 |
|
ObjectToInt<? super V> transformer, |
6559 |
|
int basis, |
6560 |
|
IntByIntToInt reducer) { |
6561 |
< |
super(p, b, split); |
6561 |
> |
super(p, b); this.nextRight = nextRight; |
6562 |
|
this.transformer = transformer; |
6563 |
|
this.basis = basis; this.reducer = reducer; |
6564 |
|
} |
6565 |
< |
public final void compute() { |
6520 |
< |
MapReduceValuesToIntTask<K,V> t = this; |
6565 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6566 |
|
final ObjectToInt<? super V> transformer = |
6567 |
|
this.transformer; |
6568 |
|
final IntByIntToInt reducer = this.reducer; |
6569 |
|
if (transformer == null || reducer == null) |
6570 |
< |
throw new Error(NullFunctionMessage); |
6571 |
< |
final int id = this.basis; |
6572 |
< |
int b = batch(); |
6573 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6574 |
< |
b >>>= 1; |
6575 |
< |
t.pending = 1; |
6576 |
< |
MapReduceValuesToIntTask<K,V> rt = |
6577 |
< |
new MapReduceValuesToIntTask<K,V> |
6578 |
< |
(t, b, true, transformer, id, reducer); |
6579 |
< |
t = new MapReduceValuesToIntTask<K,V> |
6580 |
< |
(t, b, false, transformer, id, reducer); |
6581 |
< |
t.sibling = rt; |
6582 |
< |
rt.sibling = t; |
6583 |
< |
rt.fork(); |
6584 |
< |
} |
6585 |
< |
int r = id; |
6586 |
< |
Object v; |
6587 |
< |
while ((v = t.advance()) != null) |
6588 |
< |
r = reducer.apply(r, transformer.apply((V)v)); |
6589 |
< |
t.result = r; |
6590 |
< |
for (;;) { |
6591 |
< |
int c; BulkTask<K,V,?> par; MapReduceValuesToIntTask<K,V> s, p; |
6592 |
< |
if ((par = t.parent) == null || |
6593 |
< |
!(par instanceof MapReduceValuesToIntTask)) { |
6594 |
< |
t.quietlyComplete(); |
6595 |
< |
break; |
6596 |
< |
} |
6597 |
< |
else if ((c = (p = (MapReduceValuesToIntTask<K,V>)par).pending) == 0) { |
6553 |
< |
if ((s = t.sibling) != null) |
6554 |
< |
r = reducer.apply(r, s.result); |
6555 |
< |
(t = p).result = r; |
6570 |
> |
return abortOnNullFunction(); |
6571 |
> |
try { |
6572 |
> |
final int id = this.basis; |
6573 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6574 |
> |
do {} while (!casPending(c = pending, c+1)); |
6575 |
> |
(rights = new MapReduceValuesToIntTask<K,V> |
6576 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6577 |
> |
} |
6578 |
> |
int r = id; |
6579 |
> |
Object v; |
6580 |
> |
while ((v = advance()) != null) |
6581 |
> |
r = reducer.apply(r, transformer.apply((V)v)); |
6582 |
> |
result = r; |
6583 |
> |
for (MapReduceValuesToIntTask<K,V> t = this, s;;) { |
6584 |
> |
int c; BulkTask<K,V,?> par; |
6585 |
> |
if ((c = t.pending) == 0) { |
6586 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6587 |
> |
t.result = reducer.apply(t.result, s.result); |
6588 |
> |
} |
6589 |
> |
if ((par = t.parent) == null || |
6590 |
> |
!(par instanceof MapReduceValuesToIntTask)) { |
6591 |
> |
t.quietlyComplete(); |
6592 |
> |
break; |
6593 |
> |
} |
6594 |
> |
t = (MapReduceValuesToIntTask<K,V>)par; |
6595 |
> |
} |
6596 |
> |
else if (t.casPending(c, c - 1)) |
6597 |
> |
break; |
6598 |
|
} |
6599 |
< |
else if (p.casPending(c, 0)) |
6600 |
< |
break; |
6599 |
> |
} catch (Throwable ex) { |
6600 |
> |
return tryCompleteComputation(ex); |
6601 |
|
} |
6602 |
+ |
return false; |
6603 |
|
} |
6604 |
|
public final Integer getRawResult() { return result; } |
6605 |
|
} |
6606 |
|
|
6607 |
< |
static final class MapReduceEntriesToIntTask<K,V> |
6607 |
> |
@SuppressWarnings("serial") static final class MapReduceEntriesToIntTask<K,V> |
6608 |
|
extends BulkTask<K,V,Integer> { |
6609 |
|
final ObjectToInt<Map.Entry<K,V>> transformer; |
6610 |
|
final IntByIntToInt reducer; |
6611 |
|
final int basis; |
6612 |
|
int result; |
6613 |
< |
MapReduceEntriesToIntTask<K,V> sibling; |
6613 |
> |
MapReduceEntriesToIntTask<K,V> rights, nextRight; |
6614 |
|
MapReduceEntriesToIntTask |
6615 |
|
(ConcurrentHashMapV8<K,V> m, |
6616 |
|
ObjectToInt<Map.Entry<K,V>> transformer, |
6621 |
|
this.basis = basis; this.reducer = reducer; |
6622 |
|
} |
6623 |
|
MapReduceEntriesToIntTask |
6624 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6624 |
> |
(BulkTask<K,V,?> p, int b, |
6625 |
> |
MapReduceEntriesToIntTask<K,V> nextRight, |
6626 |
|
ObjectToInt<Map.Entry<K,V>> transformer, |
6627 |
|
int basis, |
6628 |
|
IntByIntToInt reducer) { |
6629 |
< |
super(p, b, split); |
6629 |
> |
super(p, b); this.nextRight = nextRight; |
6630 |
|
this.transformer = transformer; |
6631 |
|
this.basis = basis; this.reducer = reducer; |
6632 |
|
} |
6633 |
< |
public final void compute() { |
6590 |
< |
MapReduceEntriesToIntTask<K,V> t = this; |
6633 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6634 |
|
final ObjectToInt<Map.Entry<K,V>> transformer = |
6635 |
|
this.transformer; |
6636 |
|
final IntByIntToInt reducer = this.reducer; |
6637 |
|
if (transformer == null || reducer == null) |
6638 |
< |
throw new Error(NullFunctionMessage); |
6639 |
< |
final int id = this.basis; |
6640 |
< |
int b = batch(); |
6641 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6642 |
< |
b >>>= 1; |
6643 |
< |
t.pending = 1; |
6644 |
< |
MapReduceEntriesToIntTask<K,V> rt = |
6645 |
< |
new MapReduceEntriesToIntTask<K,V> |
6646 |
< |
(t, b, true, transformer, id, reducer); |
6647 |
< |
t = new MapReduceEntriesToIntTask<K,V> |
6648 |
< |
(t, b, false, transformer, id, reducer); |
6649 |
< |
t.sibling = rt; |
6650 |
< |
rt.sibling = t; |
6651 |
< |
rt.fork(); |
6652 |
< |
} |
6653 |
< |
int r = id; |
6654 |
< |
Object v; |
6655 |
< |
while ((v = t.advance()) != null) |
6656 |
< |
r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v))); |
6657 |
< |
t.result = r; |
6658 |
< |
for (;;) { |
6659 |
< |
int c; BulkTask<K,V,?> par; MapReduceEntriesToIntTask<K,V> s, p; |
6660 |
< |
if ((par = t.parent) == null || |
6661 |
< |
!(par instanceof MapReduceEntriesToIntTask)) { |
6662 |
< |
t.quietlyComplete(); |
6663 |
< |
break; |
6664 |
< |
} |
6665 |
< |
else if ((c = (p = (MapReduceEntriesToIntTask<K,V>)par).pending) == 0) { |
6623 |
< |
if ((s = t.sibling) != null) |
6624 |
< |
r = reducer.apply(r, s.result); |
6625 |
< |
(t = p).result = r; |
6638 |
> |
return abortOnNullFunction(); |
6639 |
> |
try { |
6640 |
> |
final int id = this.basis; |
6641 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6642 |
> |
do {} while (!casPending(c = pending, c+1)); |
6643 |
> |
(rights = new MapReduceEntriesToIntTask<K,V> |
6644 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6645 |
> |
} |
6646 |
> |
int r = id; |
6647 |
> |
Object v; |
6648 |
> |
while ((v = advance()) != null) |
6649 |
> |
r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, (V)v))); |
6650 |
> |
result = r; |
6651 |
> |
for (MapReduceEntriesToIntTask<K,V> t = this, s;;) { |
6652 |
> |
int c; BulkTask<K,V,?> par; |
6653 |
> |
if ((c = t.pending) == 0) { |
6654 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6655 |
> |
t.result = reducer.apply(t.result, s.result); |
6656 |
> |
} |
6657 |
> |
if ((par = t.parent) == null || |
6658 |
> |
!(par instanceof MapReduceEntriesToIntTask)) { |
6659 |
> |
t.quietlyComplete(); |
6660 |
> |
break; |
6661 |
> |
} |
6662 |
> |
t = (MapReduceEntriesToIntTask<K,V>)par; |
6663 |
> |
} |
6664 |
> |
else if (t.casPending(c, c - 1)) |
6665 |
> |
break; |
6666 |
|
} |
6667 |
< |
else if (p.casPending(c, 0)) |
6668 |
< |
break; |
6667 |
> |
} catch (Throwable ex) { |
6668 |
> |
return tryCompleteComputation(ex); |
6669 |
|
} |
6670 |
+ |
return false; |
6671 |
|
} |
6672 |
|
public final Integer getRawResult() { return result; } |
6673 |
|
} |
6674 |
|
|
6675 |
< |
static final class MapReduceMappingsToIntTask<K,V> |
6675 |
> |
@SuppressWarnings("serial") static final class MapReduceMappingsToIntTask<K,V> |
6676 |
|
extends BulkTask<K,V,Integer> { |
6677 |
|
final ObjectByObjectToInt<? super K, ? super V> transformer; |
6678 |
|
final IntByIntToInt reducer; |
6679 |
|
final int basis; |
6680 |
|
int result; |
6681 |
< |
MapReduceMappingsToIntTask<K,V> sibling; |
6681 |
> |
MapReduceMappingsToIntTask<K,V> rights, nextRight; |
6682 |
|
MapReduceMappingsToIntTask |
6683 |
|
(ConcurrentHashMapV8<K,V> m, |
6684 |
|
ObjectByObjectToInt<? super K, ? super V> transformer, |
6689 |
|
this.basis = basis; this.reducer = reducer; |
6690 |
|
} |
6691 |
|
MapReduceMappingsToIntTask |
6692 |
< |
(BulkTask<K,V,?> p, int b, boolean split, |
6692 |
> |
(BulkTask<K,V,?> p, int b, |
6693 |
> |
MapReduceMappingsToIntTask<K,V> nextRight, |
6694 |
|
ObjectByObjectToInt<? super K, ? super V> transformer, |
6695 |
|
int basis, |
6696 |
|
IntByIntToInt reducer) { |
6697 |
< |
super(p, b, split); |
6697 |
> |
super(p, b); this.nextRight = nextRight; |
6698 |
|
this.transformer = transformer; |
6699 |
|
this.basis = basis; this.reducer = reducer; |
6700 |
|
} |
6701 |
< |
public final void compute() { |
6660 |
< |
MapReduceMappingsToIntTask<K,V> t = this; |
6701 |
> |
@SuppressWarnings("unchecked") public final boolean exec() { |
6702 |
|
final ObjectByObjectToInt<? super K, ? super V> transformer = |
6703 |
|
this.transformer; |
6704 |
|
final IntByIntToInt reducer = this.reducer; |
6705 |
|
if (transformer == null || reducer == null) |
6706 |
< |
throw new Error(NullFunctionMessage); |
6707 |
< |
final int id = this.basis; |
6708 |
< |
int b = batch(); |
6709 |
< |
while (b > 1 && t.baseIndex != t.baseLimit) { |
6710 |
< |
b >>>= 1; |
6711 |
< |
t.pending = 1; |
6712 |
< |
MapReduceMappingsToIntTask<K,V> rt = |
6713 |
< |
new MapReduceMappingsToIntTask<K,V> |
6714 |
< |
(t, b, true, transformer, id, reducer); |
6715 |
< |
t = new MapReduceMappingsToIntTask<K,V> |
6716 |
< |
(t, b, false, transformer, id, reducer); |
6717 |
< |
t.sibling = rt; |
6718 |
< |
rt.sibling = t; |
6719 |
< |
rt.fork(); |
6720 |
< |
} |
6721 |
< |
int r = id; |
6722 |
< |
Object v; |
6723 |
< |
while ((v = t.advance()) != null) |
6724 |
< |
r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v)); |
6725 |
< |
t.result = r; |
6726 |
< |
for (;;) { |
6727 |
< |
int c; BulkTask<K,V,?> par; MapReduceMappingsToIntTask<K,V> s, p; |
6728 |
< |
if ((par = t.parent) == null || |
6729 |
< |
!(par instanceof MapReduceMappingsToIntTask)) { |
6730 |
< |
t.quietlyComplete(); |
6731 |
< |
break; |
6732 |
< |
} |
6733 |
< |
else if ((c = (p = (MapReduceMappingsToIntTask<K,V>)par).pending) == 0) { |
6693 |
< |
if ((s = t.sibling) != null) |
6694 |
< |
r = reducer.apply(r, s.result); |
6695 |
< |
(t = p).result = r; |
6706 |
> |
return abortOnNullFunction(); |
6707 |
> |
try { |
6708 |
> |
final int id = this.basis; |
6709 |
> |
for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) { |
6710 |
> |
do {} while (!casPending(c = pending, c+1)); |
6711 |
> |
(rights = new MapReduceMappingsToIntTask<K,V> |
6712 |
> |
(this, b >>>= 1, rights, transformer, id, reducer)).fork(); |
6713 |
> |
} |
6714 |
> |
int r = id; |
6715 |
> |
Object v; |
6716 |
> |
while ((v = advance()) != null) |
6717 |
> |
r = reducer.apply(r, transformer.apply((K)nextKey, (V)v)); |
6718 |
> |
result = r; |
6719 |
> |
for (MapReduceMappingsToIntTask<K,V> t = this, s;;) { |
6720 |
> |
int c; BulkTask<K,V,?> par; |
6721 |
> |
if ((c = t.pending) == 0) { |
6722 |
> |
for (s = t.rights; s != null; s = t.rights = s.nextRight) { |
6723 |
> |
t.result = reducer.apply(t.result, s.result); |
6724 |
> |
} |
6725 |
> |
if ((par = t.parent) == null || |
6726 |
> |
!(par instanceof MapReduceMappingsToIntTask)) { |
6727 |
> |
t.quietlyComplete(); |
6728 |
> |
break; |
6729 |
> |
} |
6730 |
> |
t = (MapReduceMappingsToIntTask<K,V>)par; |
6731 |
> |
} |
6732 |
> |
else if (t.casPending(c, c - 1)) |
6733 |
> |
break; |
6734 |
|
} |
6735 |
< |
else if (p.casPending(c, 0)) |
6736 |
< |
break; |
6735 |
> |
} catch (Throwable ex) { |
6736 |
> |
return tryCompleteComputation(ex); |
6737 |
|
} |
6738 |
+ |
return false; |
6739 |
|
} |
6740 |
|
public final Integer getRawResult() { return result; } |
6741 |
|
} |