ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/ConcurrentHashMapV8.java
(Generate patch)

Comparing jsr166/src/jsr166e/ConcurrentHashMapV8.java (file contents):
Revision 1.61 by dl, Thu Sep 13 10:41:37 2012 UTC vs.
Revision 1.74 by jsr166, Tue Oct 30 16:54:26 2012 UTC

# Line 5 | Line 5
5   */
6  
7   package jsr166e;
8 import jsr166e.LongAdder;
9 import jsr166e.ForkJoinPool;
10 import jsr166e.ForkJoinTask;
8  
9   import java.util.Comparator;
10   import java.util.Arrays;
# Line 85 | Line 82 | import java.io.Serializable;
82   * {@code hashCode()} is a sure way to slow down performance of any
83   * hash table.
84   *
85 + * <p> A {@link Set} projection of a ConcurrentHashMapV8 may be created
86 + * (using {@link #newKeySet()} or {@link #newKeySet(int)}), or viewed
87 + * (using {@link #keySet(Object)} when only keys are of interest, and the
88 + * mapped values are (perhaps transiently) not used or all take the
89 + * same mapping value.
90 + *
91 + * <p> A ConcurrentHashMapV8 can be used as scalable frequency map (a
92 + * form of histogram or multiset) by using {@link LongAdder} values
93 + * and initializing via {@link #computeIfAbsent}. For example, to add
94 + * a count to a {@code ConcurrentHashMapV8<String,LongAdder> freqs}, you
95 + * can use {@code freqs.computeIfAbsent(k -> new
96 + * LongAdder()).increment();}
97 + *
98   * <p>This class and its views and iterators implement all of the
99   * <em>optional</em> methods of the {@link Map} and {@link Iterator}
100   * interfaces.
# Line 92 | Line 102 | import java.io.Serializable;
102   * <p> Like {@link Hashtable} but unlike {@link HashMap}, this class
103   * does <em>not</em> allow {@code null} to be used as a key or value.
104   *
105 + * <p>ConcurrentHashMapV8s support parallel operations using the {@link
106 + * ForkJoinPool#commonPool}. (Tasks that may be used in other contexts
107 + * are available in class {@link ForkJoinTasks}). These operations are
108 + * designed to be safely, and often sensibly, applied even with maps
109 + * that are being concurrently updated by other threads; for example,
110 + * when computing a snapshot summary of the values in a shared
111 + * registry.  There are three kinds of operation, each with four
112 + * forms, accepting functions with Keys, Values, Entries, and (Key,
113 + * Value) arguments and/or return values. Because the elements of a
114 + * ConcurrentHashMapV8 are not ordered in any particular way, and may be
115 + * processed in different orders in different parallel executions, the
116 + * correctness of supplied functions should not depend on any
117 + * ordering, or on any other objects or values that may transiently
118 + * change while computation is in progress; and except for forEach
119 + * actions, should ideally be side-effect-free.
120 + *
121 + * <ul>
122 + * <li> forEach: Perform a given action on each element.
123 + * A variant form applies a given transformation on each element
124 + * before performing the action.</li>
125 + *
126 + * <li> search: Return the first available non-null result of
127 + * applying a given function on each element; skipping further
128 + * search when a result is found.</li>
129 + *
130 + * <li> reduce: Accumulate each element.  The supplied reduction
131 + * function cannot rely on ordering (more formally, it should be
132 + * both associative and commutative).  There are five variants:
133 + *
134 + * <ul>
135 + *
136 + * <li> Plain reductions. (There is not a form of this method for
137 + * (key, value) function arguments since there is no corresponding
138 + * return type.)</li>
139 + *
140 + * <li> Mapped reductions that accumulate the results of a given
141 + * function applied to each element.</li>
142 + *
143 + * <li> Reductions to scalar doubles, longs, and ints, using a
144 + * given basis value.</li>
145 + *
146 + * </li>
147 + * </ul>
148 + * </ul>
149 + *
150 + * <p>The concurrency properties of bulk operations follow
151 + * from those of ConcurrentHashMapV8: Any non-null result returned
152 + * from {@code get(key)} and related access methods bears a
153 + * happens-before relation with the associated insertion or
154 + * update.  The result of any bulk operation reflects the
155 + * composition of these per-element relations (but is not
156 + * necessarily atomic with respect to the map as a whole unless it
157 + * is somehow known to be quiescent).  Conversely, because keys
158 + * and values in the map are never null, null serves as a reliable
159 + * atomic indicator of the current lack of any result.  To
160 + * maintain this property, null serves as an implicit basis for
161 + * all non-scalar reduction operations. For the double, long, and
162 + * int versions, the basis should be one that, when combined with
163 + * any other value, returns that other value (more formally, it
164 + * should be the identity element for the reduction). Most common
165 + * reductions have these properties; for example, computing a sum
166 + * with basis 0 or a minimum with basis MAX_VALUE.
167 + *
168 + * <p>Search and transformation functions provided as arguments
169 + * should similarly return null to indicate the lack of any result
170 + * (in which case it is not used). In the case of mapped
171 + * reductions, this also enables transformations to serve as
172 + * filters, returning null (or, in the case of primitive
173 + * specializations, the identity basis) if the element should not
174 + * be combined. You can create compound transformations and
175 + * filterings by composing them yourself under this "null means
176 + * there is nothing there now" rule before using them in search or
177 + * reduce operations.
178 + *
179 + * <p>Methods accepting and/or returning Entry arguments maintain
180 + * key-value associations. They may be useful for example when
181 + * finding the key for the greatest value. Note that "plain" Entry
182 + * arguments can be supplied using {@code new
183 + * AbstractMap.SimpleEntry(k,v)}.
184 + *
185 + * <p> Bulk operations may complete abruptly, throwing an
186 + * exception encountered in the application of a supplied
187 + * function. Bear in mind when handling such exceptions that other
188 + * concurrently executing functions could also have thrown
189 + * exceptions, or would have done so if the first exception had
190 + * not occurred.
191 + *
192 + * <p>Parallel speedups for bulk operations compared to sequential
193 + * processing are common but not guaranteed.  Operations involving
194 + * brief functions on small maps may execute more slowly than
195 + * sequential loops if the underlying work to parallelize the
196 + * computation is more expensive than the computation itself.
197 + * Similarly, parallelization may not lead to much actual parallelism
198 + * if all processors are busy performing unrelated tasks.
199 + *
200 + * <p> All arguments to all task methods must be non-null.
201 + *
202 + * <p><em>jsr166e note: During transition, this class
203 + * uses nested functional interfaces with different names but the
204 + * same forms as those expected for JDK8.<em>
205 + *
206   * <p>This class is a member of the
207   * <a href="{@docRoot}/../technotes/guides/collections/index.html">
208   * Java Collections Framework</a>.
209   *
99 * <p><em>jsr166e note: This class is a candidate replacement for
100 * java.util.concurrent.ConcurrentHashMap.  During transition, this
101 * class declares and uses nested functional interfaces with different
102 * names but the same forms as those expected for JDK8.<em>
103 *
210   * @since 1.5
211   * @author Doug Lea
212   * @param <K> the type of keys maintained by this map
# Line 179 | Line 285 | public class ConcurrentHashMapV8<K, V>
285          Spliterator<T> split();
286      }
287  
288 +    /**
289 +     * A view of a ConcurrentHashMapV8 as a {@link Set} of keys, in
290 +     * which additions may optionally be enabled by mapping to a
291 +     * common value.  This class cannot be directly instantiated. See
292 +     * {@link #keySet}, {@link #keySet(Object)}, {@link #newKeySet()},
293 +     * {@link #newKeySet(int)}.
294 +     *
295 +     * <p>The view's {@code iterator} is a "weakly consistent" iterator
296 +     * that will never throw {@link ConcurrentModificationException},
297 +     * and guarantees to traverse elements as they existed upon
298 +     * construction of the iterator, and may (but is not guaranteed to)
299 +     * reflect any modifications subsequent to construction.
300 +     */
301 +    public static class KeySetView<K,V> extends CHMView<K,V> implements Set<K>, java.io.Serializable {
302 +        private static final long serialVersionUID = 7249069246763182397L;
303 +        private final V value;
304 +        KeySetView(ConcurrentHashMapV8<K, V> map, V value) {  // non-public
305 +            super(map);
306 +            this.value = value;
307 +        }
308 +
309 +        /**
310 +         * Returns the map backing this view.
311 +         *
312 +         * @return the map backing this view
313 +         */
314 +        public ConcurrentHashMapV8<K,V> getMap() { return map; }
315 +
316 +        /**
317 +         * Returns the default mapped value for additions,
318 +         * or {@code null} if additions are not supported.
319 +         *
320 +         * @return the default mapped value for additions, or {@code null}
321 +         * if not supported.
322 +         */
323 +        public V getMappedValue() { return value; }
324 +
325 +        // implement Set API
326 +
327 +        public boolean contains(Object o) { return map.containsKey(o); }
328 +        public boolean remove(Object o)   { return map.remove(o) != null; }
329 +        public Iterator<K> iterator()     { return new KeyIterator<K,V>(map); }
330 +        public boolean add(K e) {
331 +            V v;
332 +            if ((v = value) == null)
333 +                throw new UnsupportedOperationException();
334 +            if (e == null)
335 +                throw new NullPointerException();
336 +            return map.internalPutIfAbsent(e, v) == null;
337 +        }
338 +        public boolean addAll(Collection<? extends K> c) {
339 +            boolean added = false;
340 +            V v;
341 +            if ((v = value) == null)
342 +                throw new UnsupportedOperationException();
343 +            for (K e : c) {
344 +                if (e == null)
345 +                    throw new NullPointerException();
346 +                if (map.internalPutIfAbsent(e, v) == null)
347 +                    added = true;
348 +            }
349 +            return added;
350 +        }
351 +        public boolean equals(Object o) {
352 +            Set<?> c;
353 +            return ((o instanceof Set) &&
354 +                    ((c = (Set<?>)o) == this ||
355 +                     (containsAll(c) && c.containsAll(this))));
356 +        }
357 +    }
358 +
359      /*
360       * Overview:
361       *
# Line 461 | Line 638 | public class ConcurrentHashMapV8<K, V>
638      private transient volatile int sizeCtl;
639  
640      // views
641 <    private transient KeySet<K,V> keySet;
641 >    private transient KeySetView<K,V> keySet;
642      private transient Values<K,V> values;
643      private transient EntrySet<K,V> entrySet;
644  
# Line 2243 | Line 2420 | public class ConcurrentHashMapV8<K, V>
2420       * change (including to null, indicating deletion), field nextVal
2421       * might not be accurate at point of use, but still maintains the
2422       * weak consistency property of holding a value that was once
2423 <     * valid.
2423 >     * valid. To support iterator.remove, the nextKey field is not
2424 >     * updated (nulled out) when the iterator cannot advance.
2425       *
2426       * Internal traversals directly access these fields, as in:
2427       * {@code while (it.advance() != null) { process(it.nextKey); }}
# Line 2280 | Line 2458 | public class ConcurrentHashMapV8<K, V>
2458      @SuppressWarnings("serial") static class Traverser<K,V,R> extends ForkJoinTask<R> {
2459          final ConcurrentHashMapV8<K, V> map;
2460          Node next;           // the next entry to use
2283        Node last;           // the last entry used
2461          Object nextKey;      // cached key field of next
2462          Object nextVal;      // cached val field of next
2463          Node[] tab;          // current table; updated if resized
2464          int index;           // index of bin to use next
2465          int baseIndex;       // current index of initial table
2466          int baseLimit;       // index bound for initial table
2467 <        final int baseSize;  // initial table size
2467 >        int baseSize;        // initial table size
2468  
2469          /** Creates iterator for all entries in the table. */
2470          Traverser(ConcurrentHashMapV8<K, V> map) {
2471 <            this.tab = (this.map = map).table;
2295 <            baseLimit = baseSize = (tab == null) ? 0 : tab.length;
2471 >            this.map = map;
2472          }
2473  
2474          /** Creates iterator for split() methods */
2475          Traverser(Traverser<K,V,?> it) {
2476 <            this.map = it.map;
2477 <            this.tab = it.tab;
2476 >            ConcurrentHashMapV8<K, V> m; Node[] t;
2477 >            if ((m = this.map = it.map) == null)
2478 >                t = null;
2479 >            else if ((t = it.tab) == null && // force parent tab initialization
2480 >                     (t = it.tab = m.table) != null)
2481 >                it.baseLimit = it.baseSize = t.length;
2482 >            this.tab = t;
2483              this.baseSize = it.baseSize;
2484              it.baseLimit = this.index = this.baseIndex =
2485                  ((this.baseLimit = it.baseLimit) + it.baseIndex + 1) >>> 1;
# Line 2309 | Line 2490 | public class ConcurrentHashMapV8<K, V>
2490           * See above for explanation.
2491           */
2492          final Object advance() {
2493 <            Node e = last = next;
2493 >            Node e = next;
2494              Object ev = null;
2495              outer: do {
2496                  if (e != null)                  // advance past used/skipped node
2497                      e = e.next;
2498                  while (e == null) {             // get to next non-null bin
2499 +                    ConcurrentHashMapV8<K, V> m;
2500                      Node[] t; int b, i, n; Object ek; // checks must use locals
2501 <                    if ((b = baseIndex) >= baseLimit || (i = index) < 0 ||
2502 <                        (t = tab) == null || i >= (n = t.length))
2501 >                    if ((t = tab) != null)
2502 >                        n = t.length;
2503 >                    else if ((m = map) != null && (t = tab = m.table) != null)
2504 >                        n = baseLimit = baseSize = t.length;
2505 >                    else
2506                          break outer;
2507 <                    else if ((e = tabAt(t, i)) != null && e.hash == MOVED) {
2507 >                    if ((b = baseIndex) >= baseLimit ||
2508 >                        (i = index) < 0 || i >= n)
2509 >                        break outer;
2510 >                    if ((e = tabAt(t, i)) != null && e.hash == MOVED) {
2511                          if ((ek = e.key) instanceof TreeBin)
2512                              e = ((TreeBin)ek).first;
2513                          else {
# Line 2336 | Line 2524 | public class ConcurrentHashMapV8<K, V>
2524          }
2525  
2526          public final void remove() {
2527 <            if (nextVal == null && last == null)
2528 <                advance();
2341 <            Node e = last;
2342 <            if (e == null)
2527 >            Object k = nextKey;
2528 >            if (k == null && (advance() == null || (k = nextKey) == null))
2529                  throw new IllegalStateException();
2530 <            last = null;
2345 <            map.remove(e.key);
2530 >            map.internalReplace(k, null, null);
2531          }
2532  
2533          public final boolean hasNext() {
# Line 2446 | Line 2631 | public class ConcurrentHashMapV8<K, V>
2631      }
2632  
2633      /**
2634 +     * Creates a new {@link Set} backed by a ConcurrentHashMapV8
2635 +     * from the given type to {@code Boolean.TRUE}.
2636 +     *
2637 +     * @return the new set
2638 +     */
2639 +    public static <K> KeySetView<K,Boolean> newKeySet() {
2640 +        return new KeySetView<K,Boolean>(new ConcurrentHashMapV8<K,Boolean>(),
2641 +                                      Boolean.TRUE);
2642 +    }
2643 +
2644 +    /**
2645 +     * Creates a new {@link Set} backed by a ConcurrentHashMapV8
2646 +     * from the given type to {@code Boolean.TRUE}.
2647 +     *
2648 +     * @param initialCapacity The implementation performs internal
2649 +     * sizing to accommodate this many elements.
2650 +     * @throws IllegalArgumentException if the initial capacity of
2651 +     * elements is negative
2652 +     * @return the new set
2653 +     */
2654 +    public static <K> KeySetView<K,Boolean> newKeySet(int initialCapacity) {
2655 +        return new KeySetView<K,Boolean>(new ConcurrentHashMapV8<K,Boolean>(initialCapacity),
2656 +                                      Boolean.TRUE);
2657 +    }
2658 +
2659 +    /**
2660       * {@inheritDoc}
2661       */
2662      public boolean isEmpty() {
# Line 2464 | Line 2675 | public class ConcurrentHashMapV8<K, V>
2675  
2676      /**
2677       * Returns the number of mappings. This method should be used
2678 <     * instead of {@link #size} because a ConcurrentHashMap may
2678 >     * instead of {@link #size} because a ConcurrentHashMapV8 may
2679       * contain more mappings than can be represented as an int. The
2680       * value returned is a snapshot; the actual count may differ if
2681       * there are ongoing concurrent insertions or removals.
# Line 2494 | Line 2705 | public class ConcurrentHashMapV8<K, V>
2705      }
2706  
2707      /**
2708 +     * Returns the value to which the specified key is mapped,
2709 +     * or the given defaultValue if this map contains no mapping for the key.
2710 +     *
2711 +     * @param key the key
2712 +     * @param defaultValue the value to return if this map contains
2713 +     * no mapping for the given key
2714 +     * @return the mapping for the key, if present; else the defaultValue
2715 +     * @throws NullPointerException if the specified key is null
2716 +     */
2717 +    @SuppressWarnings("unchecked") public V getValueOrDefault(Object key, V defaultValue) {
2718 +        if (key == null)
2719 +            throw new NullPointerException();
2720 +        V v = (V) internalGet(key);
2721 +        return v == null ? defaultValue : v;
2722 +    }
2723 +
2724 +    /**
2725       * Tests if the specified object is a key in this table.
2726       *
2727       * @param  key   possible key
# Line 2622 | Line 2850 | public class ConcurrentHashMapV8<K, V>
2850       * @param key key with which the specified value is to be associated
2851       * @param mappingFunction the function to compute a value
2852       * @return the current (existing or computed) value associated with
2853 <     *         the specified key, or null if the computed value is null.
2853 >     *         the specified key, or null if the computed value is null
2854       * @throws NullPointerException if the specified key or mappingFunction
2855       *         is null
2856       * @throws IllegalStateException if the computation detectably
# Line 2820 | Line 3048 | public class ConcurrentHashMapV8<K, V>
3048      /**
3049       * Returns a {@link Set} view of the keys contained in this map.
3050       * The set is backed by the map, so changes to the map are
3051 <     * reflected in the set, and vice-versa.  The set supports element
2824 <     * removal, which removes the corresponding mapping from this map,
2825 <     * via the {@code Iterator.remove}, {@code Set.remove},
2826 <     * {@code removeAll}, {@code retainAll}, and {@code clear}
2827 <     * operations.  It does not support the {@code add} or
2828 <     * {@code addAll} operations.
3051 >     * reflected in the set, and vice-versa.
3052       *
3053 <     * <p>The view's {@code iterator} is a "weakly consistent" iterator
3054 <     * that will never throw {@link ConcurrentModificationException},
3055 <     * and guarantees to traverse elements as they existed upon
3056 <     * construction of the iterator, and may (but is not guaranteed to)
3057 <     * reflect any modifications subsequent to construction.
3053 >     * @return the set view
3054 >     */
3055 >    public KeySetView<K,V> keySet() {
3056 >        KeySetView<K,V> ks = keySet;
3057 >        return (ks != null) ? ks : (keySet = new KeySetView<K,V>(this, null));
3058 >    }
3059 >
3060 >    /**
3061 >     * Returns a {@link Set} view of the keys in this map, using the
3062 >     * given common mapped value for any additions (i.e., {@link
3063 >     * Collection#add} and {@link Collection#addAll}). This is of
3064 >     * course only appropriate if it is acceptable to use the same
3065 >     * value for all additions from this view.
3066 >     *
3067 >     * @param mappedValue the mapped value to use for any
3068 >     * additions.
3069 >     * @return the set view
3070 >     * @throws NullPointerException if the mappedValue is null
3071       */
3072 <    public Set<K> keySet() {
3073 <        KeySet<K,V> ks = keySet;
3074 <        return (ks != null) ? ks : (keySet = new KeySet<K,V>(this));
3072 >    public KeySetView<K,V> keySet(V mappedValue) {
3073 >        if (mappedValue == null)
3074 >            throw new NullPointerException();
3075 >        return new KeySetView<K,V>(this, mappedValue);
3076      }
3077  
3078      /**
# Line 3017 | Line 3254 | public class ConcurrentHashMapV8<K, V>
3254              super(it);
3255          }
3256          public KeyIterator<K,V> split() {
3257 <            if (last != null || (next != null && nextVal == null))
3257 >            if (nextKey != null)
3258                  throw new IllegalStateException();
3259              return new KeyIterator<K,V>(this);
3260          }
# Line 3039 | Line 3276 | public class ConcurrentHashMapV8<K, V>
3276              super(it);
3277          }
3278          public ValueIterator<K,V> split() {
3279 <            if (last != null || (next != null && nextVal == null))
3279 >            if (nextKey != null)
3280                  throw new IllegalStateException();
3281              return new ValueIterator<K,V>(this);
3282          }
# Line 3062 | Line 3299 | public class ConcurrentHashMapV8<K, V>
3299              super(it);
3300          }
3301          public EntryIterator<K,V> split() {
3302 <            if (last != null || (next != null && nextVal == null))
3302 >            if (nextKey != null)
3303                  throw new IllegalStateException();
3304              return new EntryIterator<K,V>(this);
3305          }
# Line 3250 | Line 3487 | public class ConcurrentHashMapV8<K, V>
3487  
3488      }
3489  
3253    static final class KeySet<K,V> extends CHMView<K,V> implements Set<K> {
3254        KeySet(ConcurrentHashMapV8<K, V> map)  {
3255            super(map);
3256        }
3257        public final boolean contains(Object o) { return map.containsKey(o); }
3258        public final boolean remove(Object o)   { return map.remove(o) != null; }
3259        public final Iterator<K> iterator() {
3260            return new KeyIterator<K,V>(map);
3261        }
3262        public final boolean add(K e) {
3263            throw new UnsupportedOperationException();
3264        }
3265        public final boolean addAll(Collection<? extends K> c) {
3266            throw new UnsupportedOperationException();
3267        }
3268        public boolean equals(Object o) {
3269            Set<?> c;
3270            return ((o instanceof Set) &&
3271                    ((c = (Set<?>)o) == this ||
3272                     (containsAll(c) && c.containsAll(this))));
3273        }
3274    }
3275
3276
3490      static final class Values<K,V> extends CHMView<K,V>
3491          implements Collection<V> {
3492          Values(ConcurrentHashMapV8<K, V> map)   { super(map); }
# Line 3503 | Line 3716 | public class ConcurrentHashMapV8<K, V>
3716      // -------------------------------------------------------
3717  
3718      /**
3719 <     * Returns an extended {@link Parallel} view of this map using the
3507 <     * given executor for bulk parallel operations.
3719 >     * Performs the given action for each (key, value).
3720       *
3721 <     * @param executor the executor
3510 <     * @return a parallel view
3721 >     * @param action the action
3722       */
3723 <    public Parallel parallel(ForkJoinPool executor)  {
3724 <        return new Parallel(executor);
3723 >    public void forEach(BiAction<K,V> action) {
3724 >        ForkJoinTasks.forEach
3725 >            (this, action).invoke();
3726      }
3727  
3728      /**
3729 <     * An extended view of a ConcurrentHashMap supporting bulk
3730 <     * parallel operations. These operations are designed to be
3731 <     * safely, and often sensibly, applied even with maps that are
3732 <     * being concurrently updated by other threads; for example, when
3733 <     * computing a snapshot summary of the values in a shared
3734 <     * registry.  There are three kinds of operation, each with four
3735 <     * forms, accepting functions with Keys, Values, Entries, and
3524 <     * (Key, Value) arguments and/or return values. Because the
3525 <     * elements of a ConcurrentHashMap are not ordered in any
3526 <     * particular way, and may be processed in different orders in
3527 <     * different parallel executions, the correctness of supplied
3528 <     * functions should not depend on any ordering, or on any other
3529 <     * objects or values that may transiently change while computation
3530 <     * is in progress; and except for forEach actions, should ideally
3531 <     * be side-effect-free.
3532 <     *
3533 <     * <ul>
3534 <     * <li> forEach: Perform a given action on each element.
3535 <     * A variant form applies a given transformation on each element
3536 <     * before performing the action.</li>
3537 <     *
3538 <     * <li> search: Return the first available non-null result of
3539 <     * applying a given function on each element; skipping further
3540 <     * search when a result is found.</li>
3541 <     *
3542 <     * <li> reduce: Accumulate each element.  The supplied reduction
3543 <     * function cannot rely on ordering (more formally, it should be
3544 <     * both associative and commutative).  There are five variants:
3545 <     *
3546 <     * <ul>
3547 <     *
3548 <     * <li> Plain reductions. (There is not a form of this method for
3549 <     * (key, value) function arguments since there is no corresponding
3550 <     * return type.)</li>
3551 <     *
3552 <     * <li> Mapped reductions that accumulate the results of a given
3553 <     * function applied to each element.</li>
3554 <     *
3555 <     * <li> Reductions to scalar doubles, longs, and ints, using a
3556 <     * given basis value.</li>
3557 <     *
3558 <     * </li>
3559 <     * </ul>
3560 <     * </ul>
3561 <     *
3562 <     * <p>The concurrency properties of the bulk operations follow
3563 <     * from those of ConcurrentHashMap: Any non-null result returned
3564 <     * from {@code get(key)} and related access methods bears a
3565 <     * happens-before relation with the associated insertion or
3566 <     * update.  The result of any bulk operation reflects the
3567 <     * composition of these per-element relations (but is not
3568 <     * necessarily atomic with respect to the map as a whole unless it
3569 <     * is somehow known to be quiescent).  Conversely, because keys
3570 <     * and values in the map are never null, null serves as a reliable
3571 <     * atomic indicator of the current lack of any result.  To
3572 <     * maintain this property, null serves as an implicit basis for
3573 <     * all non-scalar reduction operations. For the double, long, and
3574 <     * int versions, the basis should be one that, when combined with
3575 <     * any other value, returns that other value (more formally, it
3576 <     * should be the identity element for the reduction). Most common
3577 <     * reductions have these properties; for example, computing a sum
3578 <     * with basis 0 or a minimum with basis MAX_VALUE.
3579 <     *
3580 <     * <p>Search and transformation functions provided as arguments
3581 <     * should similarly return null to indicate the lack of any result
3582 <     * (in which case it is not used). In the case of mapped
3583 <     * reductions, this also enables transformations to serve as
3584 <     * filters, returning null (or, in the case of primitive
3585 <     * specializations, the identity basis) if the element should not
3586 <     * be combined. You can create compound transformations and
3587 <     * filterings by composing them yourself under this "null means
3588 <     * there is nothing there now" rule before using them in search or
3589 <     * reduce operations.
3590 <     *
3591 <     * <p>Methods accepting and/or returning Entry arguments maintain
3592 <     * key-value associations. They may be useful for example when
3593 <     * finding the key for the greatest value. Note that "plain" Entry
3594 <     * arguments can be supplied using {@code new
3595 <     * AbstractMap.SimpleEntry(k,v)}.
3596 <     *
3597 <     * <p> Bulk operations may complete abruptly, throwing an
3598 <     * exception encountered in the application of a supplied
3599 <     * function. Bear in mind when handling such exceptions that other
3600 <     * concurrently executing functions could also have thrown
3601 <     * exceptions, or would have done so if the first exception had
3602 <     * not occurred.
3603 <     *
3604 <     * <p>Parallel speedups compared to sequential processing are
3605 <     * common but not guaranteed.  Operations involving brief
3606 <     * functions on small maps may execute more slowly than sequential
3607 <     * loops if the underlying work to parallelize the computation is
3608 <     * more expensive than the computation itself. Similarly,
3609 <     * parallelization may not lead to much actual parallelism if all
3610 <     * processors are busy performing unrelated tasks.
3611 <     *
3612 <     * <p> All arguments to all task methods must be non-null.
3613 <     *
3614 <     * <p><em>jsr166e note: During transition, this class
3615 <     * uses nested functional interfaces with different names but the
3616 <     * same forms as those expected for JDK8.<em>
3729 >     * Performs the given action for each non-null transformation
3730 >     * of each (key, value).
3731 >     *
3732 >     * @param transformer a function returning the transformation
3733 >     * for an element, or null of there is no transformation (in
3734 >     * which case the action is not applied).
3735 >     * @param action the action
3736       */
3737 <    public class Parallel {
3738 <        final ForkJoinPool fjp;
3737 >    public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
3738 >                            Action<U> action) {
3739 >        ForkJoinTasks.forEach
3740 >            (this, transformer, action).invoke();
3741 >    }
3742  
3743 <        /**
3744 <         * Returns an extended view of this map using the given
3745 <         * executor for bulk parallel operations.
3746 <         *
3747 <         * @param executor the executor
3748 <         */
3749 <        public Parallel(ForkJoinPool executor)  {
3750 <            this.fjp = executor;
3751 <        }
3743 >    /**
3744 >     * Returns a non-null result from applying the given search
3745 >     * function on each (key, value), or null if none.  Upon
3746 >     * success, further element processing is suppressed and the
3747 >     * results of any other parallel invocations of the search
3748 >     * function are ignored.
3749 >     *
3750 >     * @param searchFunction a function returning a non-null
3751 >     * result on success, else null
3752 >     * @return a non-null result from applying the given search
3753 >     * function on each (key, value), or null if none
3754 >     */
3755 >    public <U> U search(BiFun<? super K, ? super V, ? extends U> searchFunction) {
3756 >        return ForkJoinTasks.search
3757 >            (this, searchFunction).invoke();
3758 >    }
3759  
3760 <        /**
3761 <         * Performs the given action for each (key, value).
3762 <         *
3763 <         * @param action the action
3764 <         */
3765 <        public void forEach(BiAction<K,V> action) {
3766 <            fjp.invoke(ForkJoinTasks.forEach
3767 <                       (ConcurrentHashMapV8.this, action));
3768 <        }
3760 >    /**
3761 >     * Returns the result of accumulating the given transformation
3762 >     * of all (key, value) pairs using the given reducer to
3763 >     * combine values, or null if none.
3764 >     *
3765 >     * @param transformer a function returning the transformation
3766 >     * for an element, or null of there is no transformation (in
3767 >     * which case it is not combined).
3768 >     * @param reducer a commutative associative combining function
3769 >     * @return the result of accumulating the given transformation
3770 >     * of all (key, value) pairs
3771 >     */
3772 >    public <U> U reduce(BiFun<? super K, ? super V, ? extends U> transformer,
3773 >                        BiFun<? super U, ? super U, ? extends U> reducer) {
3774 >        return ForkJoinTasks.reduce
3775 >            (this, transformer, reducer).invoke();
3776 >    }
3777  
3778 <        /**
3779 <         * Performs the given action for each non-null transformation
3780 <         * of each (key, value).
3781 <         *
3782 <         * @param transformer a function returning the transformation
3783 <         * for an element, or null of there is no transformation (in
3784 <         * which case the action is not applied).
3785 <         * @param action the action
3786 <         */
3787 <        public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
3788 <                                Action<U> action) {
3789 <            fjp.invoke(ForkJoinTasks.forEach
3790 <                       (ConcurrentHashMapV8.this, transformer, action));
3791 <        }
3778 >    /**
3779 >     * Returns the result of accumulating the given transformation
3780 >     * of all (key, value) pairs using the given reducer to
3781 >     * combine values, and the given basis as an identity value.
3782 >     *
3783 >     * @param transformer a function returning the transformation
3784 >     * for an element
3785 >     * @param basis the identity (initial default value) for the reduction
3786 >     * @param reducer a commutative associative combining function
3787 >     * @return the result of accumulating the given transformation
3788 >     * of all (key, value) pairs
3789 >     */
3790 >    public double reduceToDouble(ObjectByObjectToDouble<? super K, ? super V> transformer,
3791 >                                 double basis,
3792 >                                 DoubleByDoubleToDouble reducer) {
3793 >        return ForkJoinTasks.reduceToDouble
3794 >            (this, transformer, basis, reducer).invoke();
3795 >    }
3796  
3797 <        /**
3798 <         * Returns a non-null result from applying the given search
3799 <         * function on each (key, value), or null if none.  Upon
3800 <         * success, further element processing is suppressed and the
3801 <         * results of any other parallel invocations of the search
3802 <         * function are ignored.
3803 <         *
3804 <         * @param searchFunction a function returning a non-null
3805 <         * result on success, else null
3806 <         * @return a non-null result from applying the given search
3807 <         * function on each (key, value), or null if none
3808 <         */
3809 <        public <U> U search(BiFun<? super K, ? super V, ? extends U> searchFunction) {
3810 <            return fjp.invoke(ForkJoinTasks.search
3811 <                              (ConcurrentHashMapV8.this, searchFunction));
3812 <        }
3797 >    /**
3798 >     * Returns the result of accumulating the given transformation
3799 >     * of all (key, value) pairs using the given reducer to
3800 >     * combine values, and the given basis as an identity value.
3801 >     *
3802 >     * @param transformer a function returning the transformation
3803 >     * for an element
3804 >     * @param basis the identity (initial default value) for the reduction
3805 >     * @param reducer a commutative associative combining function
3806 >     * @return the result of accumulating the given transformation
3807 >     * of all (key, value) pairs
3808 >     */
3809 >    public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer,
3810 >                             long basis,
3811 >                             LongByLongToLong reducer) {
3812 >        return ForkJoinTasks.reduceToLong
3813 >            (this, transformer, basis, reducer).invoke();
3814 >    }
3815  
3816 <        /**
3817 <         * Returns the result of accumulating the given transformation
3818 <         * of all (key, value) pairs using the given reducer to
3819 <         * combine values, or null if none.
3820 <         *
3821 <         * @param transformer a function returning the transformation
3822 <         * for an element, or null of there is no transformation (in
3823 <         * which case it is not combined).
3824 <         * @param reducer a commutative associative combining function
3825 <         * @return the result of accumulating the given transformation
3826 <         * of all (key, value) pairs
3827 <         */
3828 <        public <U> U reduce(BiFun<? super K, ? super V, ? extends U> transformer,
3816 >    /**
3817 >     * Returns the result of accumulating the given transformation
3818 >     * of all (key, value) pairs using the given reducer to
3819 >     * combine values, and the given basis as an identity value.
3820 >     *
3821 >     * @param transformer a function returning the transformation
3822 >     * for an element
3823 >     * @param basis the identity (initial default value) for the reduction
3824 >     * @param reducer a commutative associative combining function
3825 >     * @return the result of accumulating the given transformation
3826 >     * of all (key, value) pairs
3827 >     */
3828 >    public int reduceToInt(ObjectByObjectToInt<? super K, ? super V> transformer,
3829 >                           int basis,
3830 >                           IntByIntToInt reducer) {
3831 >        return ForkJoinTasks.reduceToInt
3832 >            (this, transformer, basis, reducer).invoke();
3833 >    }
3834 >
3835 >    /**
3836 >     * Performs the given action for each key.
3837 >     *
3838 >     * @param action the action
3839 >     */
3840 >    public void forEachKey(Action<K> action) {
3841 >        ForkJoinTasks.forEachKey
3842 >            (this, action).invoke();
3843 >    }
3844 >
3845 >    /**
3846 >     * Performs the given action for each non-null transformation
3847 >     * of each key.
3848 >     *
3849 >     * @param transformer a function returning the transformation
3850 >     * for an element, or null of there is no transformation (in
3851 >     * which case the action is not applied).
3852 >     * @param action the action
3853 >     */
3854 >    public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
3855 >                               Action<U> action) {
3856 >        ForkJoinTasks.forEachKey
3857 >            (this, transformer, action).invoke();
3858 >    }
3859 >
3860 >    /**
3861 >     * Returns a non-null result from applying the given search
3862 >     * function on each key, or null if none. Upon success,
3863 >     * further element processing is suppressed and the results of
3864 >     * any other parallel invocations of the search function are
3865 >     * ignored.
3866 >     *
3867 >     * @param searchFunction a function returning a non-null
3868 >     * result on success, else null
3869 >     * @return a non-null result from applying the given search
3870 >     * function on each key, or null if none
3871 >     */
3872 >    public <U> U searchKeys(Fun<? super K, ? extends U> searchFunction) {
3873 >        return ForkJoinTasks.searchKeys
3874 >            (this, searchFunction).invoke();
3875 >    }
3876 >
3877 >    /**
3878 >     * Returns the result of accumulating all keys using the given
3879 >     * reducer to combine values, or null if none.
3880 >     *
3881 >     * @param reducer a commutative associative combining function
3882 >     * @return the result of accumulating all keys using the given
3883 >     * reducer to combine values, or null if none
3884 >     */
3885 >    public K reduceKeys(BiFun<? super K, ? super K, ? extends K> reducer) {
3886 >        return ForkJoinTasks.reduceKeys
3887 >            (this, reducer).invoke();
3888 >    }
3889 >
3890 >    /**
3891 >     * Returns the result of accumulating the given transformation
3892 >     * of all keys using the given reducer to combine values, or
3893 >     * null if none.
3894 >     *
3895 >     * @param transformer a function returning the transformation
3896 >     * for an element, or null of there is no transformation (in
3897 >     * which case it is not combined).
3898 >     * @param reducer a commutative associative combining function
3899 >     * @return the result of accumulating the given transformation
3900 >     * of all keys
3901 >     */
3902 >    public <U> U reduceKeys(Fun<? super K, ? extends U> transformer,
3903                              BiFun<? super U, ? super U, ? extends U> reducer) {
3904 <            return fjp.invoke(ForkJoinTasks.reduce
3905 <                              (ConcurrentHashMapV8.this, transformer, reducer));
3906 <        }
3904 >        return ForkJoinTasks.reduceKeys
3905 >            (this, transformer, reducer).invoke();
3906 >    }
3907  
3908 <        /**
3909 <         * Returns the result of accumulating the given transformation
3910 <         * of all (key, value) pairs using the given reducer to
3911 <         * combine values, and the given basis as an identity value.
3912 <         *
3913 <         * @param transformer a function returning the transformation
3914 <         * for an element
3915 <         * @param basis the identity (initial default value) for the reduction
3916 <         * @param reducer a commutative associative combining function
3917 <         * @return the result of accumulating the given transformation
3918 <         * of all (key, value) pairs
3919 <         */
3920 <        public double reduceToDouble(ObjectByObjectToDouble<? super K, ? super V> transformer,
3908 >    /**
3909 >     * Returns the result of accumulating the given transformation
3910 >     * of all keys using the given reducer to combine values, and
3911 >     * the given basis as an identity value.
3912 >     *
3913 >     * @param transformer a function returning the transformation
3914 >     * for an element
3915 >     * @param basis the identity (initial default value) for the reduction
3916 >     * @param reducer a commutative associative combining function
3917 >     * @return  the result of accumulating the given transformation
3918 >     * of all keys
3919 >     */
3920 >    public double reduceKeysToDouble(ObjectToDouble<? super K> transformer,
3921                                       double basis,
3922                                       DoubleByDoubleToDouble reducer) {
3923 <            return fjp.invoke(ForkJoinTasks.reduceToDouble
3924 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3925 <        }
3923 >        return ForkJoinTasks.reduceKeysToDouble
3924 >            (this, transformer, basis, reducer).invoke();
3925 >    }
3926  
3927 <        /**
3928 <         * Returns the result of accumulating the given transformation
3929 <         * of all (key, value) pairs using the given reducer to
3930 <         * combine values, and the given basis as an identity value.
3931 <         *
3932 <         * @param transformer a function returning the transformation
3933 <         * for an element
3934 <         * @param basis the identity (initial default value) for the reduction
3935 <         * @param reducer a commutative associative combining function
3936 <         * @return the result of accumulating the given transformation
3937 <         * of all (key, value) pairs
3938 <         */
3939 <        public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer,
3927 >    /**
3928 >     * Returns the result of accumulating the given transformation
3929 >     * of all keys using the given reducer to combine values, and
3930 >     * the given basis as an identity value.
3931 >     *
3932 >     * @param transformer a function returning the transformation
3933 >     * for an element
3934 >     * @param basis the identity (initial default value) for the reduction
3935 >     * @param reducer a commutative associative combining function
3936 >     * @return the result of accumulating the given transformation
3937 >     * of all keys
3938 >     */
3939 >    public long reduceKeysToLong(ObjectToLong<? super K> transformer,
3940                                   long basis,
3941                                   LongByLongToLong reducer) {
3942 <            return fjp.invoke(ForkJoinTasks.reduceToLong
3943 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3944 <        }
3942 >        return ForkJoinTasks.reduceKeysToLong
3943 >            (this, transformer, basis, reducer).invoke();
3944 >    }
3945  
3946 <        /**
3947 <         * Returns the result of accumulating the given transformation
3948 <         * of all (key, value) pairs using the given reducer to
3949 <         * combine values, and the given basis as an identity value.
3950 <         *
3951 <         * @param transformer a function returning the transformation
3952 <         * for an element
3953 <         * @param basis the identity (initial default value) for the reduction
3954 <         * @param reducer a commutative associative combining function
3955 <         * @return the result of accumulating the given transformation
3956 <         * of all (key, value) pairs
3957 <         */
3958 <        public int reduceToInt(ObjectByObjectToInt<? super K, ? super V> transformer,
3946 >    /**
3947 >     * Returns the result of accumulating the given transformation
3948 >     * of all keys using the given reducer to combine values, and
3949 >     * the given basis as an identity value.
3950 >     *
3951 >     * @param transformer a function returning the transformation
3952 >     * for an element
3953 >     * @param basis the identity (initial default value) for the reduction
3954 >     * @param reducer a commutative associative combining function
3955 >     * @return the result of accumulating the given transformation
3956 >     * of all keys
3957 >     */
3958 >    public int reduceKeysToInt(ObjectToInt<? super K> transformer,
3959                                 int basis,
3960                                 IntByIntToInt reducer) {
3961 <            return fjp.invoke(ForkJoinTasks.reduceToInt
3962 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3963 <        }
3747 <
3748 <        /**
3749 <         * Performs the given action for each key.
3750 <         *
3751 <         * @param action the action
3752 <         */
3753 <        public void forEachKey(Action<K> action) {
3754 <            fjp.invoke(ForkJoinTasks.forEachKey
3755 <                       (ConcurrentHashMapV8.this, action));
3756 <        }
3757 <
3758 <        /**
3759 <         * Performs the given action for each non-null transformation
3760 <         * of each key.
3761 <         *
3762 <         * @param transformer a function returning the transformation
3763 <         * for an element, or null of there is no transformation (in
3764 <         * which case the action is not applied).
3765 <         * @param action the action
3766 <         */
3767 <        public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
3768 <                                   Action<U> action) {
3769 <            fjp.invoke(ForkJoinTasks.forEachKey
3770 <                       (ConcurrentHashMapV8.this, transformer, action));
3771 <        }
3772 <
3773 <        /**
3774 <         * Returns a non-null result from applying the given search
3775 <         * function on each key, or null if none. Upon success,
3776 <         * further element processing is suppressed and the results of
3777 <         * any other parallel invocations of the search function are
3778 <         * ignored.
3779 <         *
3780 <         * @param searchFunction a function returning a non-null
3781 <         * result on success, else null
3782 <         * @return a non-null result from applying the given search
3783 <         * function on each key, or null if none
3784 <         */
3785 <        public <U> U searchKeys(Fun<? super K, ? extends U> searchFunction) {
3786 <            return fjp.invoke(ForkJoinTasks.searchKeys
3787 <                              (ConcurrentHashMapV8.this, searchFunction));
3788 <        }
3789 <
3790 <        /**
3791 <         * Returns the result of accumulating all keys using the given
3792 <         * reducer to combine values, or null if none.
3793 <         *
3794 <         * @param reducer a commutative associative combining function
3795 <         * @return the result of accumulating all keys using the given
3796 <         * reducer to combine values, or null if none
3797 <         */
3798 <        public K reduceKeys(BiFun<? super K, ? super K, ? extends K> reducer) {
3799 <            return fjp.invoke(ForkJoinTasks.reduceKeys
3800 <                              (ConcurrentHashMapV8.this, reducer));
3801 <        }
3802 <
3803 <        /**
3804 <         * Returns the result of accumulating the given transformation
3805 <         * of all keys using the given reducer to combine values, or
3806 <         * null if none.
3807 <         *
3808 <         * @param transformer a function returning the transformation
3809 <         * for an element, or null of there is no transformation (in
3810 <         * which case it is not combined).
3811 <         * @param reducer a commutative associative combining function
3812 <         * @return the result of accumulating the given transformation
3813 <         * of all keys
3814 <         */
3815 <        public <U> U reduceKeys(Fun<? super K, ? extends U> transformer,
3816 <                                BiFun<? super U, ? super U, ? extends U> reducer) {
3817 <            return fjp.invoke(ForkJoinTasks.reduceKeys
3818 <                              (ConcurrentHashMapV8.this, transformer, reducer));
3819 <        }
3820 <
3821 <        /**
3822 <         * Returns the result of accumulating the given transformation
3823 <         * of all keys using the given reducer to combine values, and
3824 <         * the given basis as an identity value.
3825 <         *
3826 <         * @param transformer a function returning the transformation
3827 <         * for an element
3828 <         * @param basis the identity (initial default value) for the reduction
3829 <         * @param reducer a commutative associative combining function
3830 <         * @return  the result of accumulating the given transformation
3831 <         * of all keys
3832 <         */
3833 <        public double reduceKeysToDouble(ObjectToDouble<? super K> transformer,
3834 <                                         double basis,
3835 <                                         DoubleByDoubleToDouble reducer) {
3836 <            return fjp.invoke(ForkJoinTasks.reduceKeysToDouble
3837 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3838 <        }
3839 <
3840 <        /**
3841 <         * Returns the result of accumulating the given transformation
3842 <         * of all keys using the given reducer to combine values, and
3843 <         * the given basis as an identity value.
3844 <         *
3845 <         * @param transformer a function returning the transformation
3846 <         * for an element
3847 <         * @param basis the identity (initial default value) for the reduction
3848 <         * @param reducer a commutative associative combining function
3849 <         * @return the result of accumulating the given transformation
3850 <         * of all keys
3851 <         */
3852 <        public long reduceKeysToLong(ObjectToLong<? super K> transformer,
3853 <                                     long basis,
3854 <                                     LongByLongToLong reducer) {
3855 <            return fjp.invoke(ForkJoinTasks.reduceKeysToLong
3856 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3857 <        }
3858 <
3859 <        /**
3860 <         * Returns the result of accumulating the given transformation
3861 <         * of all keys using the given reducer to combine values, and
3862 <         * the given basis as an identity value.
3863 <         *
3864 <         * @param transformer a function returning the transformation
3865 <         * for an element
3866 <         * @param basis the identity (initial default value) for the reduction
3867 <         * @param reducer a commutative associative combining function
3868 <         * @return the result of accumulating the given transformation
3869 <         * of all keys
3870 <         */
3871 <        public int reduceKeysToInt(ObjectToInt<? super K> transformer,
3872 <                                   int basis,
3873 <                                   IntByIntToInt reducer) {
3874 <            return fjp.invoke(ForkJoinTasks.reduceKeysToInt
3875 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3876 <        }
3961 >        return ForkJoinTasks.reduceKeysToInt
3962 >            (this, transformer, basis, reducer).invoke();
3963 >    }
3964  
3965 <        /**
3966 <         * Performs the given action for each value.
3967 <         *
3968 <         * @param action the action
3969 <         */
3970 <        public void forEachValue(Action<V> action) {
3971 <            fjp.invoke(ForkJoinTasks.forEachValue
3972 <                       (ConcurrentHashMapV8.this, action));
3973 <        }
3965 >    /**
3966 >     * Performs the given action for each value.
3967 >     *
3968 >     * @param action the action
3969 >     */
3970 >    public void forEachValue(Action<V> action) {
3971 >        ForkJoinTasks.forEachValue
3972 >            (this, action).invoke();
3973 >    }
3974  
3975 <        /**
3976 <         * Performs the given action for each non-null transformation
3977 <         * of each value.
3978 <         *
3979 <         * @param transformer a function returning the transformation
3980 <         * for an element, or null of there is no transformation (in
3981 <         * which case the action is not applied).
3982 <         */
3983 <        public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3984 <                                     Action<U> action) {
3985 <            fjp.invoke(ForkJoinTasks.forEachValue
3986 <                       (ConcurrentHashMapV8.this, transformer, action));
3987 <        }
3975 >    /**
3976 >     * Performs the given action for each non-null transformation
3977 >     * of each value.
3978 >     *
3979 >     * @param transformer a function returning the transformation
3980 >     * for an element, or null of there is no transformation (in
3981 >     * which case the action is not applied).
3982 >     */
3983 >    public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3984 >                                 Action<U> action) {
3985 >        ForkJoinTasks.forEachValue
3986 >            (this, transformer, action).invoke();
3987 >    }
3988  
3989 <        /**
3990 <         * Returns a non-null result from applying the given search
3991 <         * function on each value, or null if none.  Upon success,
3992 <         * further element processing is suppressed and the results of
3993 <         * any other parallel invocations of the search function are
3994 <         * ignored.
3995 <         *
3996 <         * @param searchFunction a function returning a non-null
3997 <         * result on success, else null
3998 <         * @return a non-null result from applying the given search
3999 <         * function on each value, or null if none
4000 <         *
4001 <         */
4002 <        public <U> U searchValues(Fun<? super V, ? extends U> searchFunction) {
4003 <            return fjp.invoke(ForkJoinTasks.searchValues
4004 <                              (ConcurrentHashMapV8.this, searchFunction));
4005 <        }
3989 >    /**
3990 >     * Returns a non-null result from applying the given search
3991 >     * function on each value, or null if none.  Upon success,
3992 >     * further element processing is suppressed and the results of
3993 >     * any other parallel invocations of the search function are
3994 >     * ignored.
3995 >     *
3996 >     * @param searchFunction a function returning a non-null
3997 >     * result on success, else null
3998 >     * @return a non-null result from applying the given search
3999 >     * function on each value, or null if none
4000 >     *
4001 >     */
4002 >    public <U> U searchValues(Fun<? super V, ? extends U> searchFunction) {
4003 >        return ForkJoinTasks.searchValues
4004 >            (this, searchFunction).invoke();
4005 >    }
4006  
4007 <        /**
4008 <         * Returns the result of accumulating all values using the
4009 <         * given reducer to combine values, or null if none.
4010 <         *
4011 <         * @param reducer a commutative associative combining function
4012 <         * @return  the result of accumulating all values
4013 <         */
4014 <        public V reduceValues(BiFun<? super V, ? super V, ? extends V> reducer) {
4015 <            return fjp.invoke(ForkJoinTasks.reduceValues
4016 <                              (ConcurrentHashMapV8.this, reducer));
4017 <        }
4007 >    /**
4008 >     * Returns the result of accumulating all values using the
4009 >     * given reducer to combine values, or null if none.
4010 >     *
4011 >     * @param reducer a commutative associative combining function
4012 >     * @return  the result of accumulating all values
4013 >     */
4014 >    public V reduceValues(BiFun<? super V, ? super V, ? extends V> reducer) {
4015 >        return ForkJoinTasks.reduceValues
4016 >            (this, reducer).invoke();
4017 >    }
4018  
4019 <        /**
4020 <         * Returns the result of accumulating the given transformation
4021 <         * of all values using the given reducer to combine values, or
4022 <         * null if none.
4023 <         *
4024 <         * @param transformer a function returning the transformation
4025 <         * for an element, or null of there is no transformation (in
4026 <         * which case it is not combined).
4027 <         * @param reducer a commutative associative combining function
4028 <         * @return the result of accumulating the given transformation
4029 <         * of all values
4030 <         */
4031 <        public <U> U reduceValues(Fun<? super V, ? extends U> transformer,
4032 <                                  BiFun<? super U, ? super U, ? extends U> reducer) {
4033 <            return fjp.invoke(ForkJoinTasks.reduceValues
4034 <                              (ConcurrentHashMapV8.this, transformer, reducer));
4035 <        }
4019 >    /**
4020 >     * Returns the result of accumulating the given transformation
4021 >     * of all values using the given reducer to combine values, or
4022 >     * null if none.
4023 >     *
4024 >     * @param transformer a function returning the transformation
4025 >     * for an element, or null of there is no transformation (in
4026 >     * which case it is not combined).
4027 >     * @param reducer a commutative associative combining function
4028 >     * @return the result of accumulating the given transformation
4029 >     * of all values
4030 >     */
4031 >    public <U> U reduceValues(Fun<? super V, ? extends U> transformer,
4032 >                              BiFun<? super U, ? super U, ? extends U> reducer) {
4033 >        return ForkJoinTasks.reduceValues
4034 >            (this, transformer, reducer).invoke();
4035 >    }
4036  
4037 <        /**
4038 <         * Returns the result of accumulating the given transformation
4039 <         * of all values using the given reducer to combine values,
4040 <         * and the given basis as an identity value.
4041 <         *
4042 <         * @param transformer a function returning the transformation
4043 <         * for an element
4044 <         * @param basis the identity (initial default value) for the reduction
4045 <         * @param reducer a commutative associative combining function
4046 <         * @return the result of accumulating the given transformation
4047 <         * of all values
4048 <         */
4049 <        public double reduceValuesToDouble(ObjectToDouble<? super V> transformer,
4050 <                                           double basis,
4051 <                                           DoubleByDoubleToDouble reducer) {
4052 <            return fjp.invoke(ForkJoinTasks.reduceValuesToDouble
4053 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4054 <        }
4037 >    /**
4038 >     * Returns the result of accumulating the given transformation
4039 >     * of all values using the given reducer to combine values,
4040 >     * and the given basis as an identity value.
4041 >     *
4042 >     * @param transformer a function returning the transformation
4043 >     * for an element
4044 >     * @param basis the identity (initial default value) for the reduction
4045 >     * @param reducer a commutative associative combining function
4046 >     * @return the result of accumulating the given transformation
4047 >     * of all values
4048 >     */
4049 >    public double reduceValuesToDouble(ObjectToDouble<? super V> transformer,
4050 >                                       double basis,
4051 >                                       DoubleByDoubleToDouble reducer) {
4052 >        return ForkJoinTasks.reduceValuesToDouble
4053 >            (this, transformer, basis, reducer).invoke();
4054 >    }
4055  
4056 <        /**
4057 <         * Returns the result of accumulating the given transformation
4058 <         * of all values using the given reducer to combine values,
4059 <         * and the given basis as an identity value.
4060 <         *
4061 <         * @param transformer a function returning the transformation
4062 <         * for an element
4063 <         * @param basis the identity (initial default value) for the reduction
4064 <         * @param reducer a commutative associative combining function
4065 <         * @return the result of accumulating the given transformation
4066 <         * of all values
4067 <         */
4068 <        public long reduceValuesToLong(ObjectToLong<? super V> transformer,
4069 <                                       long basis,
4070 <                                       LongByLongToLong reducer) {
4071 <            return fjp.invoke(ForkJoinTasks.reduceValuesToLong
4072 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4073 <        }
4056 >    /**
4057 >     * Returns the result of accumulating the given transformation
4058 >     * of all values using the given reducer to combine values,
4059 >     * and the given basis as an identity value.
4060 >     *
4061 >     * @param transformer a function returning the transformation
4062 >     * for an element
4063 >     * @param basis the identity (initial default value) for the reduction
4064 >     * @param reducer a commutative associative combining function
4065 >     * @return the result of accumulating the given transformation
4066 >     * of all values
4067 >     */
4068 >    public long reduceValuesToLong(ObjectToLong<? super V> transformer,
4069 >                                   long basis,
4070 >                                   LongByLongToLong reducer) {
4071 >        return ForkJoinTasks.reduceValuesToLong
4072 >            (this, transformer, basis, reducer).invoke();
4073 >    }
4074  
4075 <        /**
4076 <         * Returns the result of accumulating the given transformation
4077 <         * of all values using the given reducer to combine values,
4078 <         * and the given basis as an identity value.
4079 <         *
4080 <         * @param transformer a function returning the transformation
4081 <         * for an element
4082 <         * @param basis the identity (initial default value) for the reduction
4083 <         * @param reducer a commutative associative combining function
4084 <         * @return the result of accumulating the given transformation
4085 <         * of all values
4086 <         */
4087 <        public int reduceValuesToInt(ObjectToInt<? super V> transformer,
4088 <                                     int basis,
4089 <                                     IntByIntToInt reducer) {
4090 <            return fjp.invoke(ForkJoinTasks.reduceValuesToInt
4091 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4092 <        }
4075 >    /**
4076 >     * Returns the result of accumulating the given transformation
4077 >     * of all values using the given reducer to combine values,
4078 >     * and the given basis as an identity value.
4079 >     *
4080 >     * @param transformer a function returning the transformation
4081 >     * for an element
4082 >     * @param basis the identity (initial default value) for the reduction
4083 >     * @param reducer a commutative associative combining function
4084 >     * @return the result of accumulating the given transformation
4085 >     * of all values
4086 >     */
4087 >    public int reduceValuesToInt(ObjectToInt<? super V> transformer,
4088 >                                 int basis,
4089 >                                 IntByIntToInt reducer) {
4090 >        return ForkJoinTasks.reduceValuesToInt
4091 >            (this, transformer, basis, reducer).invoke();
4092 >    }
4093  
4094 <        /**
4095 <         * Performs the given action for each entry.
4096 <         *
4097 <         * @param action the action
4098 <         */
4099 <        public void forEachEntry(Action<Map.Entry<K,V>> action) {
4100 <            fjp.invoke(ForkJoinTasks.forEachEntry
4101 <                       (ConcurrentHashMapV8.this, action));
4102 <        }
4094 >    /**
4095 >     * Performs the given action for each entry.
4096 >     *
4097 >     * @param action the action
4098 >     */
4099 >    public void forEachEntry(Action<Map.Entry<K,V>> action) {
4100 >        ForkJoinTasks.forEachEntry
4101 >            (this, action).invoke();
4102 >    }
4103  
4104 <        /**
4105 <         * Performs the given action for each non-null transformation
4106 <         * of each entry.
4107 <         *
4108 <         * @param transformer a function returning the transformation
4109 <         * for an element, or null of there is no transformation (in
4110 <         * which case the action is not applied).
4111 <         * @param action the action
4112 <         */
4113 <        public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
4114 <                                     Action<U> action) {
4115 <            fjp.invoke(ForkJoinTasks.forEachEntry
4116 <                       (ConcurrentHashMapV8.this, transformer, action));
4117 <        }
4104 >    /**
4105 >     * Performs the given action for each non-null transformation
4106 >     * of each entry.
4107 >     *
4108 >     * @param transformer a function returning the transformation
4109 >     * for an element, or null of there is no transformation (in
4110 >     * which case the action is not applied).
4111 >     * @param action the action
4112 >     */
4113 >    public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
4114 >                                 Action<U> action) {
4115 >        ForkJoinTasks.forEachEntry
4116 >            (this, transformer, action).invoke();
4117 >    }
4118  
4119 <        /**
4120 <         * Returns a non-null result from applying the given search
4121 <         * function on each entry, or null if none.  Upon success,
4122 <         * further element processing is suppressed and the results of
4123 <         * any other parallel invocations of the search function are
4124 <         * ignored.
4125 <         *
4126 <         * @param searchFunction a function returning a non-null
4127 <         * result on success, else null
4128 <         * @return a non-null result from applying the given search
4129 <         * function on each entry, or null if none
4130 <         */
4131 <        public <U> U searchEntries(Fun<Map.Entry<K,V>, ? extends U> searchFunction) {
4132 <            return fjp.invoke(ForkJoinTasks.searchEntries
4133 <                              (ConcurrentHashMapV8.this, searchFunction));
4134 <        }
4119 >    /**
4120 >     * Returns a non-null result from applying the given search
4121 >     * function on each entry, or null if none.  Upon success,
4122 >     * further element processing is suppressed and the results of
4123 >     * any other parallel invocations of the search function are
4124 >     * ignored.
4125 >     *
4126 >     * @param searchFunction a function returning a non-null
4127 >     * result on success, else null
4128 >     * @return a non-null result from applying the given search
4129 >     * function on each entry, or null if none
4130 >     */
4131 >    public <U> U searchEntries(Fun<Map.Entry<K,V>, ? extends U> searchFunction) {
4132 >        return ForkJoinTasks.searchEntries
4133 >            (this, searchFunction).invoke();
4134 >    }
4135  
4136 <        /**
4137 <         * Returns the result of accumulating all entries using the
4138 <         * given reducer to combine values, or null if none.
4139 <         *
4140 <         * @param reducer a commutative associative combining function
4141 <         * @return the result of accumulating all entries
4142 <         */
4143 <        public Map.Entry<K,V> reduceEntries(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
4144 <            return fjp.invoke(ForkJoinTasks.reduceEntries
4145 <                              (ConcurrentHashMapV8.this, reducer));
4146 <        }
4136 >    /**
4137 >     * Returns the result of accumulating all entries using the
4138 >     * given reducer to combine values, or null if none.
4139 >     *
4140 >     * @param reducer a commutative associative combining function
4141 >     * @return the result of accumulating all entries
4142 >     */
4143 >    public Map.Entry<K,V> reduceEntries(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
4144 >        return ForkJoinTasks.reduceEntries
4145 >            (this, reducer).invoke();
4146 >    }
4147  
4148 <        /**
4149 <         * Returns the result of accumulating the given transformation
4150 <         * of all entries using the given reducer to combine values,
4151 <         * or null if none.
4152 <         *
4153 <         * @param transformer a function returning the transformation
4154 <         * for an element, or null of there is no transformation (in
4155 <         * which case it is not combined).
4156 <         * @param reducer a commutative associative combining function
4157 <         * @return the result of accumulating the given transformation
4158 <         * of all entries
4159 <         */
4160 <        public <U> U reduceEntries(Fun<Map.Entry<K,V>, ? extends U> transformer,
4161 <                                   BiFun<? super U, ? super U, ? extends U> reducer) {
4162 <            return fjp.invoke(ForkJoinTasks.reduceEntries
4163 <                              (ConcurrentHashMapV8.this, transformer, reducer));
4164 <        }
4148 >    /**
4149 >     * Returns the result of accumulating the given transformation
4150 >     * of all entries using the given reducer to combine values,
4151 >     * or null if none.
4152 >     *
4153 >     * @param transformer a function returning the transformation
4154 >     * for an element, or null of there is no transformation (in
4155 >     * which case it is not combined).
4156 >     * @param reducer a commutative associative combining function
4157 >     * @return the result of accumulating the given transformation
4158 >     * of all entries
4159 >     */
4160 >    public <U> U reduceEntries(Fun<Map.Entry<K,V>, ? extends U> transformer,
4161 >                               BiFun<? super U, ? super U, ? extends U> reducer) {
4162 >        return ForkJoinTasks.reduceEntries
4163 >            (this, transformer, reducer).invoke();
4164 >    }
4165  
4166 <        /**
4167 <         * Returns the result of accumulating the given transformation
4168 <         * of all entries using the given reducer to combine values,
4169 <         * and the given basis as an identity value.
4170 <         *
4171 <         * @param transformer a function returning the transformation
4172 <         * for an element
4173 <         * @param basis the identity (initial default value) for the reduction
4174 <         * @param reducer a commutative associative combining function
4175 <         * @return the result of accumulating the given transformation
4176 <         * of all entries
4177 <         */
4178 <        public double reduceEntriesToDouble(ObjectToDouble<Map.Entry<K,V>> transformer,
4179 <                                            double basis,
4180 <                                            DoubleByDoubleToDouble reducer) {
4181 <            return fjp.invoke(ForkJoinTasks.reduceEntriesToDouble
4182 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4183 <        }
4166 >    /**
4167 >     * Returns the result of accumulating the given transformation
4168 >     * of all entries using the given reducer to combine values,
4169 >     * and the given basis as an identity value.
4170 >     *
4171 >     * @param transformer a function returning the transformation
4172 >     * for an element
4173 >     * @param basis the identity (initial default value) for the reduction
4174 >     * @param reducer a commutative associative combining function
4175 >     * @return the result of accumulating the given transformation
4176 >     * of all entries
4177 >     */
4178 >    public double reduceEntriesToDouble(ObjectToDouble<Map.Entry<K,V>> transformer,
4179 >                                        double basis,
4180 >                                        DoubleByDoubleToDouble reducer) {
4181 >        return ForkJoinTasks.reduceEntriesToDouble
4182 >            (this, transformer, basis, reducer).invoke();
4183 >    }
4184  
4185 <        /**
4186 <         * Returns the result of accumulating the given transformation
4187 <         * of all entries using the given reducer to combine values,
4188 <         * and the given basis as an identity value.
4189 <         *
4190 <         * @param transformer a function returning the transformation
4191 <         * for an element
4192 <         * @param basis the identity (initial default value) for the reduction
4193 <         * @param reducer a commutative associative combining function
4194 <         * @return  the result of accumulating the given transformation
4195 <         * of all entries
4196 <         */
4197 <        public long reduceEntriesToLong(ObjectToLong<Map.Entry<K,V>> transformer,
4198 <                                        long basis,
4199 <                                        LongByLongToLong reducer) {
4200 <            return fjp.invoke(ForkJoinTasks.reduceEntriesToLong
4201 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4202 <        }
4185 >    /**
4186 >     * Returns the result of accumulating the given transformation
4187 >     * of all entries using the given reducer to combine values,
4188 >     * and the given basis as an identity value.
4189 >     *
4190 >     * @param transformer a function returning the transformation
4191 >     * for an element
4192 >     * @param basis the identity (initial default value) for the reduction
4193 >     * @param reducer a commutative associative combining function
4194 >     * @return  the result of accumulating the given transformation
4195 >     * of all entries
4196 >     */
4197 >    public long reduceEntriesToLong(ObjectToLong<Map.Entry<K,V>> transformer,
4198 >                                    long basis,
4199 >                                    LongByLongToLong reducer) {
4200 >        return ForkJoinTasks.reduceEntriesToLong
4201 >            (this, transformer, basis, reducer).invoke();
4202 >    }
4203  
4204 <        /**
4205 <         * Returns the result of accumulating the given transformation
4206 <         * of all entries using the given reducer to combine values,
4207 <         * and the given basis as an identity value.
4208 <         *
4209 <         * @param transformer a function returning the transformation
4210 <         * for an element
4211 <         * @param basis the identity (initial default value) for the reduction
4212 <         * @param reducer a commutative associative combining function
4213 <         * @return the result of accumulating the given transformation
4214 <         * of all entries
4215 <         */
4216 <        public int reduceEntriesToInt(ObjectToInt<Map.Entry<K,V>> transformer,
4217 <                                      int basis,
4218 <                                      IntByIntToInt reducer) {
4219 <            return fjp.invoke(ForkJoinTasks.reduceEntriesToInt
4220 <                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4134 <        }
4204 >    /**
4205 >     * Returns the result of accumulating the given transformation
4206 >     * of all entries using the given reducer to combine values,
4207 >     * and the given basis as an identity value.
4208 >     *
4209 >     * @param transformer a function returning the transformation
4210 >     * for an element
4211 >     * @param basis the identity (initial default value) for the reduction
4212 >     * @param reducer a commutative associative combining function
4213 >     * @return the result of accumulating the given transformation
4214 >     * of all entries
4215 >     */
4216 >    public int reduceEntriesToInt(ObjectToInt<Map.Entry<K,V>> transformer,
4217 >                                  int basis,
4218 >                                  IntByIntToInt reducer) {
4219 >        return ForkJoinTasks.reduceEntriesToInt
4220 >            (this, transformer, basis, reducer).invoke();
4221      }
4222  
4223      // ---------------------------------------------------------------------
4224  
4225      /**
4226       * Predefined tasks for performing bulk parallel operations on
4227 <     * ConcurrentHashMaps. These tasks follow the forms and rules used
4228 <     * in class {@link Parallel}. Each method has the same name, but
4229 <     * returns a task rather than invoking it. These methods may be
4230 <     * useful in custom applications such as submitting a task without
4231 <     * waiting for completion, or combining with other tasks.
4227 >     * ConcurrentHashMapV8s. These tasks follow the forms and rules used
4228 >     * for bulk operations. Each method has the same name, but returns
4229 >     * a task rather than invoking it. These methods may be useful in
4230 >     * custom applications such as submitting a task without waiting
4231 >     * for completion, using a custom pool, or combining with other
4232 >     * tasks.
4233       */
4234      public static class ForkJoinTasks {
4235          private ForkJoinTasks() {}
# Line 4159 | Line 4246 | public class ConcurrentHashMapV8<K, V>
4246              (ConcurrentHashMapV8<K,V> map,
4247               BiAction<K,V> action) {
4248              if (action == null) throw new NullPointerException();
4249 <            return new ForEachMappingTask<K,V>(map, action);
4249 >            return new ForEachMappingTask<K,V>(map, null, -1, null, action);
4250          }
4251  
4252          /**
# Line 4168 | Line 4255 | public class ConcurrentHashMapV8<K, V>
4255           *
4256           * @param map the map
4257           * @param transformer a function returning the transformation
4258 <         * for an element, or null of there is no transformation (in
4259 <         * which case the action is not applied).
4258 >         * for an element, or null if there is no transformation (in
4259 >         * which case the action is not applied)
4260           * @param action the action
4261           * @return the task
4262           */
# Line 4180 | Line 4267 | public class ConcurrentHashMapV8<K, V>
4267              if (transformer == null || action == null)
4268                  throw new NullPointerException();
4269              return new ForEachTransformedMappingTask<K,V,U>
4270 <                (map, transformer, action);
4270 >                (map, null, -1, null, transformer, action);
4271          }
4272  
4273          /**
# Line 4200 | Line 4287 | public class ConcurrentHashMapV8<K, V>
4287               BiFun<? super K, ? super V, ? extends U> searchFunction) {
4288              if (searchFunction == null) throw new NullPointerException();
4289              return new SearchMappingsTask<K,V,U>
4290 <                (map, searchFunction,
4290 >                (map, null, -1, null, searchFunction,
4291                   new AtomicReference<U>());
4292          }
4293  
# Line 4211 | Line 4298 | public class ConcurrentHashMapV8<K, V>
4298           *
4299           * @param map the map
4300           * @param transformer a function returning the transformation
4301 <         * for an element, or null of there is no transformation (in
4301 >         * for an element, or null if there is no transformation (in
4302           * which case it is not combined).
4303           * @param reducer a commutative associative combining function
4304           * @return the task
# Line 4223 | Line 4310 | public class ConcurrentHashMapV8<K, V>
4310              if (transformer == null || reducer == null)
4311                  throw new NullPointerException();
4312              return new MapReduceMappingsTask<K,V,U>
4313 <                (map, transformer, reducer);
4313 >                (map, null, -1, null, transformer, reducer);
4314          }
4315  
4316          /**
# Line 4247 | Line 4334 | public class ConcurrentHashMapV8<K, V>
4334              if (transformer == null || reducer == null)
4335                  throw new NullPointerException();
4336              return new MapReduceMappingsToDoubleTask<K,V>
4337 <                (map, transformer, basis, reducer);
4337 >                (map, null, -1, null, transformer, basis, reducer);
4338          }
4339  
4340          /**
# Line 4271 | Line 4358 | public class ConcurrentHashMapV8<K, V>
4358              if (transformer == null || reducer == null)
4359                  throw new NullPointerException();
4360              return new MapReduceMappingsToLongTask<K,V>
4361 <                (map, transformer, basis, reducer);
4361 >                (map, null, -1, null, transformer, basis, reducer);
4362          }
4363  
4364          /**
# Line 4294 | Line 4381 | public class ConcurrentHashMapV8<K, V>
4381              if (transformer == null || reducer == null)
4382                  throw new NullPointerException();
4383              return new MapReduceMappingsToIntTask<K,V>
4384 <                (map, transformer, basis, reducer);
4384 >                (map, null, -1, null, transformer, basis, reducer);
4385          }
4386  
4387          /**
# Line 4309 | Line 4396 | public class ConcurrentHashMapV8<K, V>
4396              (ConcurrentHashMapV8<K,V> map,
4397               Action<K> action) {
4398              if (action == null) throw new NullPointerException();
4399 <            return new ForEachKeyTask<K,V>(map, action);
4399 >            return new ForEachKeyTask<K,V>(map, null, -1, null, action);
4400          }
4401  
4402          /**
# Line 4318 | Line 4405 | public class ConcurrentHashMapV8<K, V>
4405           *
4406           * @param map the map
4407           * @param transformer a function returning the transformation
4408 <         * for an element, or null of there is no transformation (in
4409 <         * which case the action is not applied).
4408 >         * for an element, or null if there is no transformation (in
4409 >         * which case the action is not applied)
4410           * @param action the action
4411           * @return the task
4412           */
# Line 4330 | Line 4417 | public class ConcurrentHashMapV8<K, V>
4417              if (transformer == null || action == null)
4418                  throw new NullPointerException();
4419              return new ForEachTransformedKeyTask<K,V,U>
4420 <                (map, transformer, action);
4420 >                (map, null, -1, null, transformer, action);
4421          }
4422  
4423          /**
# Line 4350 | Line 4437 | public class ConcurrentHashMapV8<K, V>
4437               Fun<? super K, ? extends U> searchFunction) {
4438              if (searchFunction == null) throw new NullPointerException();
4439              return new SearchKeysTask<K,V,U>
4440 <                (map, searchFunction,
4440 >                (map, null, -1, null, searchFunction,
4441                   new AtomicReference<U>());
4442          }
4443  
# Line 4368 | Line 4455 | public class ConcurrentHashMapV8<K, V>
4455               BiFun<? super K, ? super K, ? extends K> reducer) {
4456              if (reducer == null) throw new NullPointerException();
4457              return new ReduceKeysTask<K,V>
4458 <                (map, reducer);
4458 >                (map, null, -1, null, reducer);
4459          }
4460  
4461          /**
# Line 4378 | Line 4465 | public class ConcurrentHashMapV8<K, V>
4465           *
4466           * @param map the map
4467           * @param transformer a function returning the transformation
4468 <         * for an element, or null of there is no transformation (in
4468 >         * for an element, or null if there is no transformation (in
4469           * which case it is not combined).
4470           * @param reducer a commutative associative combining function
4471           * @return the task
# Line 4390 | Line 4477 | public class ConcurrentHashMapV8<K, V>
4477              if (transformer == null || reducer == null)
4478                  throw new NullPointerException();
4479              return new MapReduceKeysTask<K,V,U>
4480 <                (map, transformer, reducer);
4480 >                (map, null, -1, null, transformer, reducer);
4481          }
4482  
4483          /**
# Line 4414 | Line 4501 | public class ConcurrentHashMapV8<K, V>
4501              if (transformer == null || reducer == null)
4502                  throw new NullPointerException();
4503              return new MapReduceKeysToDoubleTask<K,V>
4504 <                (map, transformer, basis, reducer);
4504 >                (map, null, -1, null, transformer, basis, reducer);
4505          }
4506  
4507          /**
# Line 4438 | Line 4525 | public class ConcurrentHashMapV8<K, V>
4525              if (transformer == null || reducer == null)
4526                  throw new NullPointerException();
4527              return new MapReduceKeysToLongTask<K,V>
4528 <                (map, transformer, basis, reducer);
4528 >                (map, null, -1, null, transformer, basis, reducer);
4529          }
4530  
4531          /**
# Line 4462 | Line 4549 | public class ConcurrentHashMapV8<K, V>
4549              if (transformer == null || reducer == null)
4550                  throw new NullPointerException();
4551              return new MapReduceKeysToIntTask<K,V>
4552 <                (map, transformer, basis, reducer);
4552 >                (map, null, -1, null, transformer, basis, reducer);
4553          }
4554  
4555          /**
# Line 4476 | Line 4563 | public class ConcurrentHashMapV8<K, V>
4563              (ConcurrentHashMapV8<K,V> map,
4564               Action<V> action) {
4565              if (action == null) throw new NullPointerException();
4566 <            return new ForEachValueTask<K,V>(map, action);
4566 >            return new ForEachValueTask<K,V>(map, null, -1, null, action);
4567          }
4568  
4569          /**
# Line 4485 | Line 4572 | public class ConcurrentHashMapV8<K, V>
4572           *
4573           * @param map the map
4574           * @param transformer a function returning the transformation
4575 <         * for an element, or null of there is no transformation (in
4576 <         * which case the action is not applied).
4575 >         * for an element, or null if there is no transformation (in
4576 >         * which case the action is not applied)
4577           * @param action the action
4578           */
4579          public static <K,V,U> ForkJoinTask<Void> forEachValue
# Line 4496 | Line 4583 | public class ConcurrentHashMapV8<K, V>
4583              if (transformer == null || action == null)
4584                  throw new NullPointerException();
4585              return new ForEachTransformedValueTask<K,V,U>
4586 <                (map, transformer, action);
4586 >                (map, null, -1, null, transformer, action);
4587          }
4588  
4589          /**
# Line 4510 | Line 4597 | public class ConcurrentHashMapV8<K, V>
4597           * @param searchFunction a function returning a non-null
4598           * result on success, else null
4599           * @return the task
4513         *
4600           */
4601          public static <K,V,U> ForkJoinTask<U> searchValues
4602              (ConcurrentHashMapV8<K,V> map,
4603               Fun<? super V, ? extends U> searchFunction) {
4604              if (searchFunction == null) throw new NullPointerException();
4605              return new SearchValuesTask<K,V,U>
4606 <                (map, searchFunction,
4606 >                (map, null, -1, null, searchFunction,
4607                   new AtomicReference<U>());
4608          }
4609  
# Line 4535 | Line 4621 | public class ConcurrentHashMapV8<K, V>
4621               BiFun<? super V, ? super V, ? extends V> reducer) {
4622              if (reducer == null) throw new NullPointerException();
4623              return new ReduceValuesTask<K,V>
4624 <                (map, reducer);
4624 >                (map, null, -1, null, reducer);
4625          }
4626  
4627          /**
# Line 4545 | Line 4631 | public class ConcurrentHashMapV8<K, V>
4631           *
4632           * @param map the map
4633           * @param transformer a function returning the transformation
4634 <         * for an element, or null of there is no transformation (in
4634 >         * for an element, or null if there is no transformation (in
4635           * which case it is not combined).
4636           * @param reducer a commutative associative combining function
4637           * @return the task
# Line 4557 | Line 4643 | public class ConcurrentHashMapV8<K, V>
4643              if (transformer == null || reducer == null)
4644                  throw new NullPointerException();
4645              return new MapReduceValuesTask<K,V,U>
4646 <                (map, transformer, reducer);
4646 >                (map, null, -1, null, transformer, reducer);
4647          }
4648  
4649          /**
# Line 4581 | Line 4667 | public class ConcurrentHashMapV8<K, V>
4667              if (transformer == null || reducer == null)
4668                  throw new NullPointerException();
4669              return new MapReduceValuesToDoubleTask<K,V>
4670 <                (map, transformer, basis, reducer);
4670 >                (map, null, -1, null, transformer, basis, reducer);
4671          }
4672  
4673          /**
# Line 4605 | Line 4691 | public class ConcurrentHashMapV8<K, V>
4691              if (transformer == null || reducer == null)
4692                  throw new NullPointerException();
4693              return new MapReduceValuesToLongTask<K,V>
4694 <                (map, transformer, basis, reducer);
4694 >                (map, null, -1, null, transformer, basis, reducer);
4695          }
4696  
4697          /**
# Line 4629 | Line 4715 | public class ConcurrentHashMapV8<K, V>
4715              if (transformer == null || reducer == null)
4716                  throw new NullPointerException();
4717              return new MapReduceValuesToIntTask<K,V>
4718 <                (map, transformer, basis, reducer);
4718 >                (map, null, -1, null, transformer, basis, reducer);
4719          }
4720  
4721          /**
# Line 4643 | Line 4729 | public class ConcurrentHashMapV8<K, V>
4729              (ConcurrentHashMapV8<K,V> map,
4730               Action<Map.Entry<K,V>> action) {
4731              if (action == null) throw new NullPointerException();
4732 <            return new ForEachEntryTask<K,V>(map, action);
4732 >            return new ForEachEntryTask<K,V>(map, null, -1, null, action);
4733          }
4734  
4735          /**
# Line 4652 | Line 4738 | public class ConcurrentHashMapV8<K, V>
4738           *
4739           * @param map the map
4740           * @param transformer a function returning the transformation
4741 <         * for an element, or null of there is no transformation (in
4742 <         * which case the action is not applied).
4741 >         * for an element, or null if there is no transformation (in
4742 >         * which case the action is not applied)
4743           * @param action the action
4744           */
4745          public static <K,V,U> ForkJoinTask<Void> forEachEntry
# Line 4663 | Line 4749 | public class ConcurrentHashMapV8<K, V>
4749              if (transformer == null || action == null)
4750                  throw new NullPointerException();
4751              return new ForEachTransformedEntryTask<K,V,U>
4752 <                (map, transformer, action);
4752 >                (map, null, -1, null, transformer, action);
4753          }
4754  
4755          /**
# Line 4677 | Line 4763 | public class ConcurrentHashMapV8<K, V>
4763           * @param searchFunction a function returning a non-null
4764           * result on success, else null
4765           * @return the task
4680         *
4766           */
4767          public static <K,V,U> ForkJoinTask<U> searchEntries
4768              (ConcurrentHashMapV8<K,V> map,
4769               Fun<Map.Entry<K,V>, ? extends U> searchFunction) {
4770              if (searchFunction == null) throw new NullPointerException();
4771              return new SearchEntriesTask<K,V,U>
4772 <                (map, searchFunction,
4772 >                (map, null, -1, null, searchFunction,
4773                   new AtomicReference<U>());
4774          }
4775  
# Line 4702 | Line 4787 | public class ConcurrentHashMapV8<K, V>
4787               BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
4788              if (reducer == null) throw new NullPointerException();
4789              return new ReduceEntriesTask<K,V>
4790 <                (map, reducer);
4790 >                (map, null, -1, null, reducer);
4791          }
4792  
4793          /**
# Line 4712 | Line 4797 | public class ConcurrentHashMapV8<K, V>
4797           *
4798           * @param map the map
4799           * @param transformer a function returning the transformation
4800 <         * for an element, or null of there is no transformation (in
4800 >         * for an element, or null if there is no transformation (in
4801           * which case it is not combined).
4802           * @param reducer a commutative associative combining function
4803           * @return the task
# Line 4724 | Line 4809 | public class ConcurrentHashMapV8<K, V>
4809              if (transformer == null || reducer == null)
4810                  throw new NullPointerException();
4811              return new MapReduceEntriesTask<K,V,U>
4812 <                (map, transformer, reducer);
4812 >                (map, null, -1, null, transformer, reducer);
4813          }
4814  
4815          /**
# Line 4748 | Line 4833 | public class ConcurrentHashMapV8<K, V>
4833              if (transformer == null || reducer == null)
4834                  throw new NullPointerException();
4835              return new MapReduceEntriesToDoubleTask<K,V>
4836 <                (map, transformer, basis, reducer);
4836 >                (map, null, -1, null, transformer, basis, reducer);
4837          }
4838  
4839          /**
# Line 4772 | Line 4857 | public class ConcurrentHashMapV8<K, V>
4857              if (transformer == null || reducer == null)
4858                  throw new NullPointerException();
4859              return new MapReduceEntriesToLongTask<K,V>
4860 <                (map, transformer, basis, reducer);
4860 >                (map, null, -1, null, transformer, basis, reducer);
4861          }
4862  
4863          /**
# Line 4796 | Line 4881 | public class ConcurrentHashMapV8<K, V>
4881              if (transformer == null || reducer == null)
4882                  throw new NullPointerException();
4883              return new MapReduceEntriesToIntTask<K,V>
4884 <                (map, transformer, basis, reducer);
4884 >                (map, null, -1, null, transformer, basis, reducer);
4885          }
4886      }
4887  
# Line 4815 | Line 4900 | public class ConcurrentHashMapV8<K, V>
4900       */
4901      @SuppressWarnings("serial") static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> {
4902          final BulkTask<K,V,?> parent;  // completion target
4903 <        int batch;                     // split control
4903 >        int batch;                     // split control; -1 for unknown
4904          int pending;                   // completion control
4905  
4906 <        /** Constructor for root tasks */
4907 <        BulkTask(ConcurrentHashMapV8<K,V> map) {
4906 >        BulkTask(ConcurrentHashMapV8<K,V> map, BulkTask<K,V,?> parent,
4907 >                 int batch) {
4908              super(map);
4824            this.parent = null;
4825            this.batch = -1; // force call to batch() on execution
4826        }
4827
4828        /** Constructor for subtasks */
4829        BulkTask(BulkTask<K,V,?> parent, int batch) {
4830            super(parent);
4909              this.parent = parent;
4910              this.batch = batch;
4911 <        }
4912 <
4913 <        // FJ methods
4914 <
4915 <        /**
4916 <         * Propagates completion. Note that all reduce actions
4917 <         * bypass this method to combine while completing.
4918 <         */
4919 <        final void tryComplete() {
4920 <            BulkTask<K,V,?> a = this, s = a;
4843 <            for (int c;;) {
4844 <                if ((c = a.pending) == 0) {
4845 <                    if ((a = (s = a).parent) == null) {
4846 <                        s.quietlyComplete();
4847 <                        break;
4848 <                    }
4849 <                }
4850 <                else if (U.compareAndSwapInt(a, PENDING, c, c - 1))
4851 <                    break;
4911 >            if (parent != null && map != null) { // split parent
4912 >                Node[] t;
4913 >                if ((t = parent.tab) == null &&
4914 >                    (t = parent.tab = map.table) != null)
4915 >                    parent.baseLimit = parent.baseSize = t.length;
4916 >                this.tab = t;
4917 >                this.baseSize = parent.baseSize;
4918 >                int hi = this.baseLimit = parent.baseLimit;
4919 >                parent.baseLimit = this.index = this.baseIndex =
4920 >                    (hi + parent.baseIndex + 1) >>> 1;
4921              }
4922          }
4923  
# Line 4893 | Line 4962 | public class ConcurrentHashMapV8<K, V>
4962           * dividing by two anyway.
4963           */
4964          final int batch() {
4965 <            int b = batch;
4966 <            if (b < 0) {
4967 <                long n = map.counter.sum();
4968 <                int sp = getPool().getParallelism() << 3; // slack of 8
4969 <                b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp;
4965 >            ConcurrentHashMapV8<K, V> m; int b; Node[] t;  ForkJoinPool pool;
4966 >            if ((b = batch) < 0 && (m = map) != null) { // force initialization
4967 >                if ((t = tab) == null && (t = tab = m.table) != null)
4968 >                    baseLimit = baseSize = t.length;
4969 >                if (t != null) {
4970 >                    long n = m.counter.sum();
4971 >                    int par = ((pool = getPool()) == null) ?
4972 >                        ForkJoinPool.getCommonPoolParallelism() :
4973 >                        pool.getParallelism();
4974 >                    int sp = par << 3; // slack of 8
4975 >                    b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp;
4976 >                }
4977              }
4978              return b;
4979          }
# Line 4923 | Line 4999 | public class ConcurrentHashMapV8<K, V>
4999          }
5000      }
5001  
5002 +    /**
5003 +     * Base class for non-reductive actions
5004 +     */
5005 +    @SuppressWarnings("serial") static abstract class BulkAction<K,V,R> extends BulkTask<K,V,R> {
5006 +        BulkAction<K,V,?> nextTask;
5007 +        BulkAction(ConcurrentHashMapV8<K,V> map, BulkTask<K,V,?> parent,
5008 +                   int batch, BulkAction<K,V,?> nextTask) {
5009 +            super(map, parent, batch);
5010 +            this.nextTask = nextTask;
5011 +        }
5012 +
5013 +        /**
5014 +         * Try to complete task and upward parents. Upon hitting
5015 +         * non-completed parent, if a non-FJ task, try to help out the
5016 +         * computation.
5017 +         */
5018 +        final void tryComplete(BulkAction<K,V,?> subtasks) {
5019 +            BulkTask<K,V,?> a = this, s = a;
5020 +            for (int c;;) {
5021 +                if ((c = a.pending) == 0) {
5022 +                    if ((a = (s = a).parent) == null) {
5023 +                        s.quietlyComplete();
5024 +                        break;
5025 +                    }
5026 +                }
5027 +                else if (a.casPending(c, c - 1)) {
5028 +                    if (subtasks != null && !inForkJoinPool()) {
5029 +                        while ((s = a.parent) != null)
5030 +                            a = s;
5031 +                        while (!a.isDone()) {
5032 +                            BulkAction<K,V,?> next = subtasks.nextTask;
5033 +                            if (subtasks.tryUnfork())
5034 +                                subtasks.exec();
5035 +                            if ((subtasks = next) == null)
5036 +                                break;
5037 +                        }
5038 +                    }
5039 +                    break;
5040 +                }
5041 +            }
5042 +        }
5043 +
5044 +    }
5045 +
5046      /*
5047       * Task classes. Coded in a regular but ugly format/style to
5048       * simplify checks that each variant differs in the right way from
# Line 4930 | Line 5050 | public class ConcurrentHashMapV8<K, V>
5050       */
5051  
5052      @SuppressWarnings("serial") static final class ForEachKeyTask<K,V>
5053 <        extends BulkTask<K,V,Void> {
5053 >        extends BulkAction<K,V,Void> {
5054          final Action<K> action;
5055          ForEachKeyTask
5056 <            (ConcurrentHashMapV8<K,V> m,
5057 <             Action<K> action) {
4938 <            super(m);
4939 <            this.action = action;
4940 <        }
4941 <        ForEachKeyTask
4942 <            (BulkTask<K,V,?> p, int b,
5056 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5057 >             ForEachKeyTask<K,V> nextTask,
5058               Action<K> action) {
5059 <            super(p, b);
5059 >            super(m, p, b, nextTask);
5060              this.action = action;
5061          }
5062          @SuppressWarnings("unchecked") public final boolean exec() {
5063              final Action<K> action = this.action;
5064              if (action == null)
5065                  return abortOnNullFunction();
5066 +            ForEachKeyTask<K,V> subtasks = null;
5067              try {
5068                  int b = batch(), c;
5069                  while (b > 1 && baseIndex != baseLimit) {
5070                      do {} while (!casPending(c = pending, c+1));
5071 <                    new ForEachKeyTask<K,V>(this, b >>>= 1, action).fork();
5071 >                    (subtasks = new ForEachKeyTask<K,V>
5072 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5073                  }
5074                  while (advance() != null)
5075                      action.apply((K)nextKey);
4959                tryComplete();
5076              } catch (Throwable ex) {
5077                  return tryCompleteComputation(ex);
5078              }
5079 +            tryComplete(subtasks);
5080              return false;
5081          }
5082      }
5083  
5084      @SuppressWarnings("serial") static final class ForEachValueTask<K,V>
5085 <        extends BulkTask<K,V,Void> {
5085 >        extends BulkAction<K,V,Void> {
5086          final Action<V> action;
5087          ForEachValueTask
5088 <            (ConcurrentHashMapV8<K,V> m,
5088 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5089 >             ForEachValueTask<K,V> nextTask,
5090               Action<V> action) {
5091 <            super(m);
4974 <            this.action = action;
4975 <        }
4976 <        ForEachValueTask
4977 <            (BulkTask<K,V,?> p, int b,
4978 <             Action<V> action) {
4979 <            super(p, b);
5091 >            super(m, p, b, nextTask);
5092              this.action = action;
5093          }
5094          @SuppressWarnings("unchecked") public final boolean exec() {
5095              final Action<V> action = this.action;
5096              if (action == null)
5097                  return abortOnNullFunction();
5098 +            ForEachValueTask<K,V> subtasks = null;
5099              try {
5100                  int b = batch(), c;
5101                  while (b > 1 && baseIndex != baseLimit) {
5102                      do {} while (!casPending(c = pending, c+1));
5103 <                    new ForEachValueTask<K,V>(this, b >>>= 1, action).fork();
5103 >                    (subtasks = new ForEachValueTask<K,V>
5104 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5105                  }
5106                  Object v;
5107                  while ((v = advance()) != null)
5108                      action.apply((V)v);
4995                tryComplete();
5109              } catch (Throwable ex) {
5110                  return tryCompleteComputation(ex);
5111              }
5112 +            tryComplete(subtasks);
5113              return false;
5114          }
5115      }
5116  
5117      @SuppressWarnings("serial") static final class ForEachEntryTask<K,V>
5118 <        extends BulkTask<K,V,Void> {
5118 >        extends BulkAction<K,V,Void> {
5119          final Action<Entry<K,V>> action;
5120          ForEachEntryTask
5121 <            (ConcurrentHashMapV8<K,V> m,
5122 <             Action<Entry<K,V>> action) {
5009 <            super(m);
5010 <            this.action = action;
5011 <        }
5012 <        ForEachEntryTask
5013 <            (BulkTask<K,V,?> p, int b,
5121 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5122 >             ForEachEntryTask<K,V> nextTask,
5123               Action<Entry<K,V>> action) {
5124 <            super(p, b);
5124 >            super(m, p, b, nextTask);
5125              this.action = action;
5126          }
5127          @SuppressWarnings("unchecked") public final boolean exec() {
5128              final Action<Entry<K,V>> action = this.action;
5129              if (action == null)
5130                  return abortOnNullFunction();
5131 +            ForEachEntryTask<K,V> subtasks = null;
5132              try {
5133                  int b = batch(), c;
5134                  while (b > 1 && baseIndex != baseLimit) {
5135                      do {} while (!casPending(c = pending, c+1));
5136 <                    new ForEachEntryTask<K,V>(this, b >>>= 1, action).fork();
5136 >                    (subtasks = new ForEachEntryTask<K,V>
5137 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5138                  }
5139                  Object v;
5140                  while ((v = advance()) != null)
5141                      action.apply(entryFor((K)nextKey, (V)v));
5031                tryComplete();
5142              } catch (Throwable ex) {
5143                  return tryCompleteComputation(ex);
5144              }
5145 +            tryComplete(subtasks);
5146              return false;
5147          }
5148      }
5149  
5150      @SuppressWarnings("serial") static final class ForEachMappingTask<K,V>
5151 <        extends BulkTask<K,V,Void> {
5151 >        extends BulkAction<K,V,Void> {
5152          final BiAction<K,V> action;
5153          ForEachMappingTask
5154 <            (ConcurrentHashMapV8<K,V> m,
5155 <             BiAction<K,V> action) {
5045 <            super(m);
5046 <            this.action = action;
5047 <        }
5048 <        ForEachMappingTask
5049 <            (BulkTask<K,V,?> p, int b,
5154 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5155 >             ForEachMappingTask<K,V> nextTask,
5156               BiAction<K,V> action) {
5157 <            super(p, b);
5157 >            super(m, p, b, nextTask);
5158              this.action = action;
5159          }
5054
5160          @SuppressWarnings("unchecked") public final boolean exec() {
5161              final BiAction<K,V> action = this.action;
5162              if (action == null)
5163                  return abortOnNullFunction();
5164 +            ForEachMappingTask<K,V> subtasks = null;
5165              try {
5166                  int b = batch(), c;
5167                  while (b > 1 && baseIndex != baseLimit) {
5168                      do {} while (!casPending(c = pending, c+1));
5169 <                    new ForEachMappingTask<K,V>(this, b >>>= 1,
5170 <                                                action).fork();
5169 >                    (subtasks = new ForEachMappingTask<K,V>
5170 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5171                  }
5172                  Object v;
5173                  while ((v = advance()) != null)
5174                      action.apply((K)nextKey, (V)v);
5069                tryComplete();
5175              } catch (Throwable ex) {
5176                  return tryCompleteComputation(ex);
5177              }
5178 +            tryComplete(subtasks);
5179              return false;
5180          }
5181      }
5182  
5183      @SuppressWarnings("serial") static final class ForEachTransformedKeyTask<K,V,U>
5184 <        extends BulkTask<K,V,Void> {
5184 >        extends BulkAction<K,V,Void> {
5185          final Fun<? super K, ? extends U> transformer;
5186          final Action<U> action;
5187          ForEachTransformedKeyTask
5188 <            (ConcurrentHashMapV8<K,V> m,
5188 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5189 >             ForEachTransformedKeyTask<K,V,U> nextTask,
5190               Fun<? super K, ? extends U> transformer,
5191               Action<U> action) {
5192 <            super(m);
5192 >            super(m, p, b, nextTask);
5193              this.transformer = transformer;
5194              this.action = action;
5195  
5196          }
5090        ForEachTransformedKeyTask
5091            (BulkTask<K,V,?> p, int b,
5092             Fun<? super K, ? extends U> transformer,
5093             Action<U> action) {
5094            super(p, b);
5095            this.transformer = transformer;
5096            this.action = action;
5097        }
5197          @SuppressWarnings("unchecked") public final boolean exec() {
5198              final Fun<? super K, ? extends U> transformer =
5199                  this.transformer;
5200              final Action<U> action = this.action;
5201              if (transformer == null || action == null)
5202                  return abortOnNullFunction();
5203 +            ForEachTransformedKeyTask<K,V,U> subtasks = null;
5204              try {
5205                  int b = batch(), c;
5206                  while (b > 1 && baseIndex != baseLimit) {
5207                      do {} while (!casPending(c = pending, c+1));
5208 <                    new ForEachTransformedKeyTask<K,V,U>
5209 <                        (this, b >>>= 1, transformer, action).fork();
5208 >                    (subtasks = new ForEachTransformedKeyTask<K,V,U>
5209 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5210                  }
5211                  U u;
5212                  while (advance() != null) {
5213                      if ((u = transformer.apply((K)nextKey)) != null)
5214                          action.apply(u);
5215                  }
5116                tryComplete();
5216              } catch (Throwable ex) {
5217                  return tryCompleteComputation(ex);
5218              }
5219 +            tryComplete(subtasks);
5220              return false;
5221          }
5222      }
5223  
5224      @SuppressWarnings("serial") static final class ForEachTransformedValueTask<K,V,U>
5225 <        extends BulkTask<K,V,Void> {
5225 >        extends BulkAction<K,V,Void> {
5226          final Fun<? super V, ? extends U> transformer;
5227          final Action<U> action;
5228          ForEachTransformedValueTask
5229 <            (ConcurrentHashMapV8<K,V> m,
5229 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5230 >             ForEachTransformedValueTask<K,V,U> nextTask,
5231               Fun<? super V, ? extends U> transformer,
5232               Action<U> action) {
5233 <            super(m);
5233 >            super(m, p, b, nextTask);
5234              this.transformer = transformer;
5235              this.action = action;
5236  
5237          }
5137        ForEachTransformedValueTask
5138            (BulkTask<K,V,?> p, int b,
5139             Fun<? super V, ? extends U> transformer,
5140             Action<U> action) {
5141            super(p, b);
5142            this.transformer = transformer;
5143            this.action = action;
5144        }
5238          @SuppressWarnings("unchecked") public final boolean exec() {
5239              final Fun<? super V, ? extends U> transformer =
5240                  this.transformer;
5241              final Action<U> action = this.action;
5242              if (transformer == null || action == null)
5243                  return abortOnNullFunction();
5244 +            ForEachTransformedValueTask<K,V,U> subtasks = null;
5245              try {
5246                  int b = batch(), c;
5247                  while (b > 1 && baseIndex != baseLimit) {
5248                      do {} while (!casPending(c = pending, c+1));
5249 <                    new ForEachTransformedValueTask<K,V,U>
5250 <                        (this, b >>>= 1, transformer, action).fork();
5249 >                    (subtasks = new ForEachTransformedValueTask<K,V,U>
5250 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5251                  }
5252                  Object v; U u;
5253                  while ((v = advance()) != null) {
5254                      if ((u = transformer.apply((V)v)) != null)
5255                          action.apply(u);
5256                  }
5163                tryComplete();
5257              } catch (Throwable ex) {
5258                  return tryCompleteComputation(ex);
5259              }
5260 +            tryComplete(subtasks);
5261              return false;
5262          }
5263      }
5264  
5265      @SuppressWarnings("serial") static final class ForEachTransformedEntryTask<K,V,U>
5266 <        extends BulkTask<K,V,Void> {
5266 >        extends BulkAction<K,V,Void> {
5267          final Fun<Map.Entry<K,V>, ? extends U> transformer;
5268          final Action<U> action;
5269          ForEachTransformedEntryTask
5270 <            (ConcurrentHashMapV8<K,V> m,
5270 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5271 >             ForEachTransformedEntryTask<K,V,U> nextTask,
5272               Fun<Map.Entry<K,V>, ? extends U> transformer,
5273               Action<U> action) {
5274 <            super(m);
5274 >            super(m, p, b, nextTask);
5275              this.transformer = transformer;
5276              this.action = action;
5277  
5278          }
5184        ForEachTransformedEntryTask
5185            (BulkTask<K,V,?> p, int b,
5186             Fun<Map.Entry<K,V>, ? extends U> transformer,
5187             Action<U> action) {
5188            super(p, b);
5189            this.transformer = transformer;
5190            this.action = action;
5191        }
5279          @SuppressWarnings("unchecked") public final boolean exec() {
5280              final Fun<Map.Entry<K,V>, ? extends U> transformer =
5281                  this.transformer;
5282              final Action<U> action = this.action;
5283              if (transformer == null || action == null)
5284                  return abortOnNullFunction();
5285 +            ForEachTransformedEntryTask<K,V,U> subtasks = null;
5286              try {
5287                  int b = batch(), c;
5288                  while (b > 1 && baseIndex != baseLimit) {
5289                      do {} while (!casPending(c = pending, c+1));
5290 <                    new ForEachTransformedEntryTask<K,V,U>
5291 <                        (this, b >>>= 1, transformer, action).fork();
5290 >                    (subtasks = new ForEachTransformedEntryTask<K,V,U>
5291 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5292                  }
5293                  Object v; U u;
5294                  while ((v = advance()) != null) {
5295                      if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5296                          action.apply(u);
5297                  }
5210                tryComplete();
5298              } catch (Throwable ex) {
5299                  return tryCompleteComputation(ex);
5300              }
5301 +            tryComplete(subtasks);
5302              return false;
5303          }
5304      }
5305  
5306      @SuppressWarnings("serial") static final class ForEachTransformedMappingTask<K,V,U>
5307 <        extends BulkTask<K,V,Void> {
5307 >        extends BulkAction<K,V,Void> {
5308          final BiFun<? super K, ? super V, ? extends U> transformer;
5309          final Action<U> action;
5310          ForEachTransformedMappingTask
5311 <            (ConcurrentHashMapV8<K,V> m,
5311 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5312 >             ForEachTransformedMappingTask<K,V,U> nextTask,
5313               BiFun<? super K, ? super V, ? extends U> transformer,
5314               Action<U> action) {
5315 <            super(m);
5315 >            super(m, p, b, nextTask);
5316              this.transformer = transformer;
5317              this.action = action;
5318  
5319          }
5231        ForEachTransformedMappingTask
5232            (BulkTask<K,V,?> p, int b,
5233             BiFun<? super K, ? super V, ? extends U> transformer,
5234             Action<U> action) {
5235            super(p, b);
5236            this.transformer = transformer;
5237            this.action = action;
5238        }
5320          @SuppressWarnings("unchecked") public final boolean exec() {
5321              final BiFun<? super K, ? super V, ? extends U> transformer =
5322                  this.transformer;
5323              final Action<U> action = this.action;
5324              if (transformer == null || action == null)
5325                  return abortOnNullFunction();
5326 +            ForEachTransformedMappingTask<K,V,U> subtasks = null;
5327              try {
5328                  int b = batch(), c;
5329                  while (b > 1 && baseIndex != baseLimit) {
5330                      do {} while (!casPending(c = pending, c+1));
5331 <                    new ForEachTransformedMappingTask<K,V,U>
5332 <                        (this, b >>>= 1, transformer, action).fork();
5331 >                    (subtasks = new ForEachTransformedMappingTask<K,V,U>
5332 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5333                  }
5334                  Object v; U u;
5335                  while ((v = advance()) != null) {
5336                      if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5337                          action.apply(u);
5338                  }
5257                tryComplete();
5339              } catch (Throwable ex) {
5340                  return tryCompleteComputation(ex);
5341              }
5342 +            tryComplete(subtasks);
5343              return false;
5344          }
5345      }
5346  
5347      @SuppressWarnings("serial") static final class SearchKeysTask<K,V,U>
5348 <        extends BulkTask<K,V,U> {
5348 >        extends BulkAction<K,V,U> {
5349          final Fun<? super K, ? extends U> searchFunction;
5350          final AtomicReference<U> result;
5351          SearchKeysTask
5352 <            (ConcurrentHashMapV8<K,V> m,
5352 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5353 >             SearchKeysTask<K,V,U> nextTask,
5354               Fun<? super K, ? extends U> searchFunction,
5355               AtomicReference<U> result) {
5356 <            super(m);
5274 <            this.searchFunction = searchFunction; this.result = result;
5275 <        }
5276 <        SearchKeysTask
5277 <            (BulkTask<K,V,?> p, int b,
5278 <             Fun<? super K, ? extends U> searchFunction,
5279 <             AtomicReference<U> result) {
5280 <            super(p, b);
5356 >            super(m, p, b, nextTask);
5357              this.searchFunction = searchFunction; this.result = result;
5358          }
5359          @SuppressWarnings("unchecked") public final boolean exec() {
# Line 5286 | Line 5362 | public class ConcurrentHashMapV8<K, V>
5362                  this.searchFunction;
5363              if (searchFunction == null || result == null)
5364                  return abortOnNullFunction();
5365 +            SearchKeysTask<K,V,U> subtasks = null;
5366              try {
5367                  int b = batch(), c;
5368                  while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5369                      do {} while (!casPending(c = pending, c+1));
5370 <                    new SearchKeysTask<K,V,U>(this, b >>>= 1,
5371 <                                              searchFunction, result).fork();
5370 >                    (subtasks = new SearchKeysTask<K,V,U>
5371 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5372                  }
5373                  U u;
5374                  while (result.get() == null && advance() != null) {
# Line 5301 | Line 5378 | public class ConcurrentHashMapV8<K, V>
5378                          break;
5379                      }
5380                  }
5304                tryComplete();
5381              } catch (Throwable ex) {
5382                  return tryCompleteComputation(ex);
5383              }
5384 +            tryComplete(subtasks);
5385              return false;
5386          }
5387          public final U getRawResult() { return result.get(); }
5388      }
5389  
5390      @SuppressWarnings("serial") static final class SearchValuesTask<K,V,U>
5391 <        extends BulkTask<K,V,U> {
5391 >        extends BulkAction<K,V,U> {
5392          final Fun<? super V, ? extends U> searchFunction;
5393          final AtomicReference<U> result;
5394          SearchValuesTask
5395 <            (ConcurrentHashMapV8<K,V> m,
5395 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5396 >             SearchValuesTask<K,V,U> nextTask,
5397               Fun<? super V, ? extends U> searchFunction,
5398               AtomicReference<U> result) {
5399 <            super(m);
5322 <            this.searchFunction = searchFunction; this.result = result;
5323 <        }
5324 <        SearchValuesTask
5325 <            (BulkTask<K,V,?> p, int b,
5326 <             Fun<? super V, ? extends U> searchFunction,
5327 <             AtomicReference<U> result) {
5328 <            super(p, b);
5399 >            super(m, p, b, nextTask);
5400              this.searchFunction = searchFunction; this.result = result;
5401          }
5402          @SuppressWarnings("unchecked") public final boolean exec() {
# Line 5334 | Line 5405 | public class ConcurrentHashMapV8<K, V>
5405                  this.searchFunction;
5406              if (searchFunction == null || result == null)
5407                  return abortOnNullFunction();
5408 +            SearchValuesTask<K,V,U> subtasks = null;
5409              try {
5410                  int b = batch(), c;
5411                  while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5412                      do {} while (!casPending(c = pending, c+1));
5413 <                    new SearchValuesTask<K,V,U>(this, b >>>= 1,
5414 <                                                searchFunction, result).fork();
5413 >                    (subtasks = new SearchValuesTask<K,V,U>
5414 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5415                  }
5416                  Object v; U u;
5417                  while (result.get() == null && (v = advance()) != null) {
# Line 5349 | Line 5421 | public class ConcurrentHashMapV8<K, V>
5421                          break;
5422                      }
5423                  }
5352                tryComplete();
5424              } catch (Throwable ex) {
5425                  return tryCompleteComputation(ex);
5426              }
5427 +            tryComplete(subtasks);
5428              return false;
5429          }
5430          public final U getRawResult() { return result.get(); }
5431      }
5432  
5433      @SuppressWarnings("serial") static final class SearchEntriesTask<K,V,U>
5434 <        extends BulkTask<K,V,U> {
5434 >        extends BulkAction<K,V,U> {
5435          final Fun<Entry<K,V>, ? extends U> searchFunction;
5436          final AtomicReference<U> result;
5437          SearchEntriesTask
5438 <            (ConcurrentHashMapV8<K,V> m,
5438 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5439 >             SearchEntriesTask<K,V,U> nextTask,
5440               Fun<Entry<K,V>, ? extends U> searchFunction,
5441               AtomicReference<U> result) {
5442 <            super(m);
5370 <            this.searchFunction = searchFunction; this.result = result;
5371 <        }
5372 <        SearchEntriesTask
5373 <            (BulkTask<K,V,?> p, int b,
5374 <             Fun<Entry<K,V>, ? extends U> searchFunction,
5375 <             AtomicReference<U> result) {
5376 <            super(p, b);
5442 >            super(m, p, b, nextTask);
5443              this.searchFunction = searchFunction; this.result = result;
5444          }
5445          @SuppressWarnings("unchecked") public final boolean exec() {
# Line 5382 | Line 5448 | public class ConcurrentHashMapV8<K, V>
5448                  this.searchFunction;
5449              if (searchFunction == null || result == null)
5450                  return abortOnNullFunction();
5451 +            SearchEntriesTask<K,V,U> subtasks = null;
5452              try {
5453                  int b = batch(), c;
5454                  while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5455                      do {} while (!casPending(c = pending, c+1));
5456 <                    new SearchEntriesTask<K,V,U>(this, b >>>= 1,
5457 <                                                 searchFunction, result).fork();
5456 >                    (subtasks = new SearchEntriesTask<K,V,U>
5457 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5458                  }
5459                  Object v; U u;
5460                  while (result.get() == null && (v = advance()) != null) {
# Line 5397 | Line 5464 | public class ConcurrentHashMapV8<K, V>
5464                          break;
5465                      }
5466                  }
5400                tryComplete();
5467              } catch (Throwable ex) {
5468                  return tryCompleteComputation(ex);
5469              }
5470 +            tryComplete(subtasks);
5471              return false;
5472          }
5473          public final U getRawResult() { return result.get(); }
5474      }
5475  
5476      @SuppressWarnings("serial") static final class SearchMappingsTask<K,V,U>
5477 <        extends BulkTask<K,V,U> {
5477 >        extends BulkAction<K,V,U> {
5478          final BiFun<? super K, ? super V, ? extends U> searchFunction;
5479          final AtomicReference<U> result;
5480          SearchMappingsTask
5481 <            (ConcurrentHashMapV8<K,V> m,
5481 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5482 >             SearchMappingsTask<K,V,U> nextTask,
5483               BiFun<? super K, ? super V, ? extends U> searchFunction,
5484               AtomicReference<U> result) {
5485 <            super(m);
5418 <            this.searchFunction = searchFunction; this.result = result;
5419 <        }
5420 <        SearchMappingsTask
5421 <            (BulkTask<K,V,?> p, int b,
5422 <             BiFun<? super K, ? super V, ? extends U> searchFunction,
5423 <             AtomicReference<U> result) {
5424 <            super(p, b);
5485 >            super(m, p, b, nextTask);
5486              this.searchFunction = searchFunction; this.result = result;
5487          }
5488          @SuppressWarnings("unchecked") public final boolean exec() {
# Line 5430 | Line 5491 | public class ConcurrentHashMapV8<K, V>
5491                  this.searchFunction;
5492              if (searchFunction == null || result == null)
5493                  return abortOnNullFunction();
5494 +            SearchMappingsTask<K,V,U> subtasks = null;
5495              try {
5496                  int b = batch(), c;
5497                  while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5498                      do {} while (!casPending(c = pending, c+1));
5499 <                    new SearchMappingsTask<K,V,U>(this, b >>>= 1,
5500 <                                                  searchFunction, result).fork();
5499 >                    (subtasks = new SearchMappingsTask<K,V,U>
5500 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5501                  }
5502                  Object v; U u;
5503                  while (result.get() == null && (v = advance()) != null) {
# Line 5445 | Line 5507 | public class ConcurrentHashMapV8<K, V>
5507                          break;
5508                      }
5509                  }
5448                tryComplete();
5510              } catch (Throwable ex) {
5511                  return tryCompleteComputation(ex);
5512              }
5513 +            tryComplete(subtasks);
5514              return false;
5515          }
5516          public final U getRawResult() { return result.get(); }
# Line 5460 | Line 5522 | public class ConcurrentHashMapV8<K, V>
5522          K result;
5523          ReduceKeysTask<K,V> rights, nextRight;
5524          ReduceKeysTask
5525 <            (ConcurrentHashMapV8<K,V> m,
5464 <             BiFun<? super K, ? super K, ? extends K> reducer) {
5465 <            super(m);
5466 <            this.reducer = reducer;
5467 <        }
5468 <        ReduceKeysTask
5469 <            (BulkTask<K,V,?> p, int b,
5525 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5526               ReduceKeysTask<K,V> nextRight,
5527               BiFun<? super K, ? super K, ? extends K> reducer) {
5528 <            super(p, b); this.nextRight = nextRight;
5528 >            super(m, p, b); this.nextRight = nextRight;
5529              this.reducer = reducer;
5530          }
5475
5531          @SuppressWarnings("unchecked") public final boolean exec() {
5532              final BiFun<? super K, ? super K, ? extends K> reducer =
5533                  this.reducer;
# Line 5482 | Line 5537 | public class ConcurrentHashMapV8<K, V>
5537                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5538                      do {} while (!casPending(c = pending, c+1));
5539                      (rights = new ReduceKeysTask<K,V>
5540 <                     (this, b >>>= 1, rights, reducer)).fork();
5540 >                     (map, this, b >>>= 1, rights, reducer)).fork();
5541                  }
5542                  K r = null;
5543                  while (advance() != null) {
# Line 5495 | Line 5550 | public class ConcurrentHashMapV8<K, V>
5550                      if ((c = t.pending) == 0) {
5551                          for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5552                              if ((sr = s.result) != null)
5553 <                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5553 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5554                          }
5555                          if ((par = t.parent) == null ||
5556                              !(par instanceof ReduceKeysTask)) {
# Line 5510 | Line 5565 | public class ConcurrentHashMapV8<K, V>
5565              } catch (Throwable ex) {
5566                  return tryCompleteComputation(ex);
5567              }
5568 +            ReduceKeysTask<K,V> s = rights;
5569 +            if (s != null && !inForkJoinPool()) {
5570 +                do  {
5571 +                    if (s.tryUnfork())
5572 +                        s.exec();
5573 +                } while ((s = s.nextRight) != null);
5574 +            }
5575              return false;
5576          }
5577          public final K getRawResult() { return result; }
# Line 5521 | Line 5583 | public class ConcurrentHashMapV8<K, V>
5583          V result;
5584          ReduceValuesTask<K,V> rights, nextRight;
5585          ReduceValuesTask
5586 <            (ConcurrentHashMapV8<K,V> m,
5525 <             BiFun<? super V, ? super V, ? extends V> reducer) {
5526 <            super(m);
5527 <            this.reducer = reducer;
5528 <        }
5529 <        ReduceValuesTask
5530 <            (BulkTask<K,V,?> p, int b,
5586 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5587               ReduceValuesTask<K,V> nextRight,
5588               BiFun<? super V, ? super V, ? extends V> reducer) {
5589 <            super(p, b); this.nextRight = nextRight;
5589 >            super(m, p, b); this.nextRight = nextRight;
5590              this.reducer = reducer;
5591          }
5536
5592          @SuppressWarnings("unchecked") public final boolean exec() {
5593              final BiFun<? super V, ? super V, ? extends V> reducer =
5594                  this.reducer;
# Line 5543 | Line 5598 | public class ConcurrentHashMapV8<K, V>
5598                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5599                      do {} while (!casPending(c = pending, c+1));
5600                      (rights = new ReduceValuesTask<K,V>
5601 <                     (this, b >>>= 1, rights, reducer)).fork();
5601 >                     (map, this, b >>>= 1, rights, reducer)).fork();
5602                  }
5603                  V r = null;
5604                  Object v;
# Line 5557 | Line 5612 | public class ConcurrentHashMapV8<K, V>
5612                      if ((c = t.pending) == 0) {
5613                          for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5614                              if ((sr = s.result) != null)
5615 <                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5615 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5616                          }
5617                          if ((par = t.parent) == null ||
5618                              !(par instanceof ReduceValuesTask)) {
# Line 5572 | Line 5627 | public class ConcurrentHashMapV8<K, V>
5627              } catch (Throwable ex) {
5628                  return tryCompleteComputation(ex);
5629              }
5630 +            ReduceValuesTask<K,V> s = rights;
5631 +            if (s != null && !inForkJoinPool()) {
5632 +                do  {
5633 +                    if (s.tryUnfork())
5634 +                        s.exec();
5635 +                } while ((s = s.nextRight) != null);
5636 +            }
5637              return false;
5638          }
5639          public final V getRawResult() { return result; }
# Line 5583 | Line 5645 | public class ConcurrentHashMapV8<K, V>
5645          Map.Entry<K,V> result;
5646          ReduceEntriesTask<K,V> rights, nextRight;
5647          ReduceEntriesTask
5648 <            (ConcurrentHashMapV8<K,V> m,
5587 <             BiFun<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5588 <            super(m);
5589 <            this.reducer = reducer;
5590 <        }
5591 <        ReduceEntriesTask
5592 <            (BulkTask<K,V,?> p, int b,
5648 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5649               ReduceEntriesTask<K,V> nextRight,
5650 <             BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5651 <            super(p, b); this.nextRight = nextRight;
5650 >             BiFun<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5651 >            super(m, p, b); this.nextRight = nextRight;
5652              this.reducer = reducer;
5653          }
5598
5654          @SuppressWarnings("unchecked") public final boolean exec() {
5655              final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer =
5656                  this.reducer;
# Line 5605 | Line 5660 | public class ConcurrentHashMapV8<K, V>
5660                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5661                      do {} while (!casPending(c = pending, c+1));
5662                      (rights = new ReduceEntriesTask<K,V>
5663 <                     (this, b >>>= 1, rights, reducer)).fork();
5663 >                     (map, this, b >>>= 1, rights, reducer)).fork();
5664                  }
5665                  Map.Entry<K,V> r = null;
5666                  Object v;
# Line 5619 | Line 5674 | public class ConcurrentHashMapV8<K, V>
5674                      if ((c = t.pending) == 0) {
5675                          for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5676                              if ((sr = s.result) != null)
5677 <                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5677 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5678                          }
5679                          if ((par = t.parent) == null ||
5680                              !(par instanceof ReduceEntriesTask)) {
# Line 5634 | Line 5689 | public class ConcurrentHashMapV8<K, V>
5689              } catch (Throwable ex) {
5690                  return tryCompleteComputation(ex);
5691              }
5692 +            ReduceEntriesTask<K,V> s = rights;
5693 +            if (s != null && !inForkJoinPool()) {
5694 +                do  {
5695 +                    if (s.tryUnfork())
5696 +                        s.exec();
5697 +                } while ((s = s.nextRight) != null);
5698 +            }
5699              return false;
5700          }
5701          public final Map.Entry<K,V> getRawResult() { return result; }
# Line 5646 | Line 5708 | public class ConcurrentHashMapV8<K, V>
5708          U result;
5709          MapReduceKeysTask<K,V,U> rights, nextRight;
5710          MapReduceKeysTask
5711 <            (ConcurrentHashMapV8<K,V> m,
5650 <             Fun<? super K, ? extends U> transformer,
5651 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5652 <            super(m);
5653 <            this.transformer = transformer;
5654 <            this.reducer = reducer;
5655 <        }
5656 <        MapReduceKeysTask
5657 <            (BulkTask<K,V,?> p, int b,
5711 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5712               MapReduceKeysTask<K,V,U> nextRight,
5713               Fun<? super K, ? extends U> transformer,
5714               BiFun<? super U, ? super U, ? extends U> reducer) {
5715 <            super(p, b); this.nextRight = nextRight;
5715 >            super(m, p, b); this.nextRight = nextRight;
5716              this.transformer = transformer;
5717              this.reducer = reducer;
5718          }
# Line 5673 | Line 5727 | public class ConcurrentHashMapV8<K, V>
5727                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5728                      do {} while (!casPending(c = pending, c+1));
5729                      (rights = new MapReduceKeysTask<K,V,U>
5730 <                     (this, b >>>= 1, rights, transformer, reducer)).fork();
5730 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5731                  }
5732                  U r = null, u;
5733                  while (advance() != null) {
# Line 5686 | Line 5740 | public class ConcurrentHashMapV8<K, V>
5740                      if ((c = t.pending) == 0) {
5741                          for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5742                              if ((sr = s.result) != null)
5743 <                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5743 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5744                          }
5745                          if ((par = t.parent) == null ||
5746                              !(par instanceof MapReduceKeysTask)) {
# Line 5701 | Line 5755 | public class ConcurrentHashMapV8<K, V>
5755              } catch (Throwable ex) {
5756                  return tryCompleteComputation(ex);
5757              }
5758 +            MapReduceKeysTask<K,V,U> s = rights;
5759 +            if (s != null && !inForkJoinPool()) {
5760 +                do  {
5761 +                    if (s.tryUnfork())
5762 +                        s.exec();
5763 +                } while ((s = s.nextRight) != null);
5764 +            }
5765              return false;
5766          }
5767          public final U getRawResult() { return result; }
# Line 5713 | Line 5774 | public class ConcurrentHashMapV8<K, V>
5774          U result;
5775          MapReduceValuesTask<K,V,U> rights, nextRight;
5776          MapReduceValuesTask
5777 <            (ConcurrentHashMapV8<K,V> m,
5717 <             Fun<? super V, ? extends U> transformer,
5718 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5719 <            super(m);
5720 <            this.transformer = transformer;
5721 <            this.reducer = reducer;
5722 <        }
5723 <        MapReduceValuesTask
5724 <            (BulkTask<K,V,?> p, int b,
5777 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5778               MapReduceValuesTask<K,V,U> nextRight,
5779               Fun<? super V, ? extends U> transformer,
5780               BiFun<? super U, ? super U, ? extends U> reducer) {
5781 <            super(p, b); this.nextRight = nextRight;
5781 >            super(m, p, b); this.nextRight = nextRight;
5782              this.transformer = transformer;
5783              this.reducer = reducer;
5784          }
# Line 5740 | Line 5793 | public class ConcurrentHashMapV8<K, V>
5793                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5794                      do {} while (!casPending(c = pending, c+1));
5795                      (rights = new MapReduceValuesTask<K,V,U>
5796 <                     (this, b >>>= 1, rights, transformer, reducer)).fork();
5796 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5797                  }
5798                  U r = null, u;
5799                  Object v;
# Line 5754 | Line 5807 | public class ConcurrentHashMapV8<K, V>
5807                      if ((c = t.pending) == 0) {
5808                          for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5809                              if ((sr = s.result) != null)
5810 <                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5810 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5811                          }
5812                          if ((par = t.parent) == null ||
5813                              !(par instanceof MapReduceValuesTask)) {
# Line 5769 | Line 5822 | public class ConcurrentHashMapV8<K, V>
5822              } catch (Throwable ex) {
5823                  return tryCompleteComputation(ex);
5824              }
5825 +            MapReduceValuesTask<K,V,U> s = rights;
5826 +            if (s != null && !inForkJoinPool()) {
5827 +                do  {
5828 +                    if (s.tryUnfork())
5829 +                        s.exec();
5830 +                } while ((s = s.nextRight) != null);
5831 +            }
5832              return false;
5833          }
5834          public final U getRawResult() { return result; }
# Line 5781 | Line 5841 | public class ConcurrentHashMapV8<K, V>
5841          U result;
5842          MapReduceEntriesTask<K,V,U> rights, nextRight;
5843          MapReduceEntriesTask
5844 <            (ConcurrentHashMapV8<K,V> m,
5785 <             Fun<Map.Entry<K,V>, ? extends U> transformer,
5786 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5787 <            super(m);
5788 <            this.transformer = transformer;
5789 <            this.reducer = reducer;
5790 <        }
5791 <        MapReduceEntriesTask
5792 <            (BulkTask<K,V,?> p, int b,
5844 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5845               MapReduceEntriesTask<K,V,U> nextRight,
5846               Fun<Map.Entry<K,V>, ? extends U> transformer,
5847               BiFun<? super U, ? super U, ? extends U> reducer) {
5848 <            super(p, b); this.nextRight = nextRight;
5848 >            super(m, p, b); this.nextRight = nextRight;
5849              this.transformer = transformer;
5850              this.reducer = reducer;
5851          }
# Line 5808 | Line 5860 | public class ConcurrentHashMapV8<K, V>
5860                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5861                      do {} while (!casPending(c = pending, c+1));
5862                      (rights = new MapReduceEntriesTask<K,V,U>
5863 <                     (this, b >>>= 1, rights, transformer, reducer)).fork();
5863 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5864                  }
5865                  U r = null, u;
5866                  Object v;
# Line 5822 | Line 5874 | public class ConcurrentHashMapV8<K, V>
5874                      if ((c = t.pending) == 0) {
5875                          for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5876                              if ((sr = s.result) != null)
5877 <                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5877 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5878                          }
5879                          if ((par = t.parent) == null ||
5880                              !(par instanceof MapReduceEntriesTask)) {
# Line 5837 | Line 5889 | public class ConcurrentHashMapV8<K, V>
5889              } catch (Throwable ex) {
5890                  return tryCompleteComputation(ex);
5891              }
5892 +            MapReduceEntriesTask<K,V,U> s = rights;
5893 +            if (s != null && !inForkJoinPool()) {
5894 +                do  {
5895 +                    if (s.tryUnfork())
5896 +                        s.exec();
5897 +                } while ((s = s.nextRight) != null);
5898 +            }
5899              return false;
5900          }
5901          public final U getRawResult() { return result; }
# Line 5849 | Line 5908 | public class ConcurrentHashMapV8<K, V>
5908          U result;
5909          MapReduceMappingsTask<K,V,U> rights, nextRight;
5910          MapReduceMappingsTask
5911 <            (ConcurrentHashMapV8<K,V> m,
5853 <             BiFun<? super K, ? super V, ? extends U> transformer,
5854 <             BiFun<? super U, ? super U, ? extends U> reducer) {
5855 <            super(m);
5856 <            this.transformer = transformer;
5857 <            this.reducer = reducer;
5858 <        }
5859 <        MapReduceMappingsTask
5860 <            (BulkTask<K,V,?> p, int b,
5911 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5912               MapReduceMappingsTask<K,V,U> nextRight,
5913               BiFun<? super K, ? super V, ? extends U> transformer,
5914               BiFun<? super U, ? super U, ? extends U> reducer) {
5915 <            super(p, b); this.nextRight = nextRight;
5915 >            super(m, p, b); this.nextRight = nextRight;
5916              this.transformer = transformer;
5917              this.reducer = reducer;
5918          }
# Line 5876 | Line 5927 | public class ConcurrentHashMapV8<K, V>
5927                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5928                      do {} while (!casPending(c = pending, c+1));
5929                      (rights = new MapReduceMappingsTask<K,V,U>
5930 <                     (this, b >>>= 1, rights, transformer, reducer)).fork();
5930 >                     (map, this, b >>>= 1, rights, transformer, reducer)).fork();
5931                  }
5932                  U r = null, u;
5933                  Object v;
# Line 5890 | Line 5941 | public class ConcurrentHashMapV8<K, V>
5941                      if ((c = t.pending) == 0) {
5942                          for (s = t.rights; s != null; s = t.rights = s.nextRight) {
5943                              if ((sr = s.result) != null)
5944 <                                t.result = (tr = t.result) == null? sr : reducer.apply(tr, sr);
5944 >                                t.result = ((tr = t.result) == null) ? sr : reducer.apply(tr, sr);
5945                          }
5946                          if ((par = t.parent) == null ||
5947                              !(par instanceof MapReduceMappingsTask)) {
# Line 5905 | Line 5956 | public class ConcurrentHashMapV8<K, V>
5956              } catch (Throwable ex) {
5957                  return tryCompleteComputation(ex);
5958              }
5959 +            MapReduceMappingsTask<K,V,U> s = rights;
5960 +            if (s != null && !inForkJoinPool()) {
5961 +                do  {
5962 +                    if (s.tryUnfork())
5963 +                        s.exec();
5964 +                } while ((s = s.nextRight) != null);
5965 +            }
5966              return false;
5967          }
5968          public final U getRawResult() { return result; }
# Line 5918 | Line 5976 | public class ConcurrentHashMapV8<K, V>
5976          double result;
5977          MapReduceKeysToDoubleTask<K,V> rights, nextRight;
5978          MapReduceKeysToDoubleTask
5979 <            (ConcurrentHashMapV8<K,V> m,
5922 <             ObjectToDouble<? super K> transformer,
5923 <             double basis,
5924 <             DoubleByDoubleToDouble reducer) {
5925 <            super(m);
5926 <            this.transformer = transformer;
5927 <            this.basis = basis; this.reducer = reducer;
5928 <        }
5929 <        MapReduceKeysToDoubleTask
5930 <            (BulkTask<K,V,?> p, int b,
5979 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
5980               MapReduceKeysToDoubleTask<K,V> nextRight,
5981               ObjectToDouble<? super K> transformer,
5982               double basis,
5983               DoubleByDoubleToDouble reducer) {
5984 <            super(p, b); this.nextRight = nextRight;
5984 >            super(m, p, b); this.nextRight = nextRight;
5985              this.transformer = transformer;
5986              this.basis = basis; this.reducer = reducer;
5987          }
# Line 5947 | Line 5996 | public class ConcurrentHashMapV8<K, V>
5996                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
5997                      do {} while (!casPending(c = pending, c+1));
5998                      (rights = new MapReduceKeysToDoubleTask<K,V>
5999 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
5999 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6000                  }
6001                  double r = id;
6002                  while (advance() != null)
# Line 5972 | Line 6021 | public class ConcurrentHashMapV8<K, V>
6021              } catch (Throwable ex) {
6022                  return tryCompleteComputation(ex);
6023              }
6024 +            MapReduceKeysToDoubleTask<K,V> s = rights;
6025 +            if (s != null && !inForkJoinPool()) {
6026 +                do  {
6027 +                    if (s.tryUnfork())
6028 +                        s.exec();
6029 +                } while ((s = s.nextRight) != null);
6030 +            }
6031              return false;
6032          }
6033          public final Double getRawResult() { return result; }
# Line 5985 | Line 6041 | public class ConcurrentHashMapV8<K, V>
6041          double result;
6042          MapReduceValuesToDoubleTask<K,V> rights, nextRight;
6043          MapReduceValuesToDoubleTask
6044 <            (ConcurrentHashMapV8<K,V> m,
5989 <             ObjectToDouble<? super V> transformer,
5990 <             double basis,
5991 <             DoubleByDoubleToDouble reducer) {
5992 <            super(m);
5993 <            this.transformer = transformer;
5994 <            this.basis = basis; this.reducer = reducer;
5995 <        }
5996 <        MapReduceValuesToDoubleTask
5997 <            (BulkTask<K,V,?> p, int b,
6044 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6045               MapReduceValuesToDoubleTask<K,V> nextRight,
6046               ObjectToDouble<? super V> transformer,
6047               double basis,
6048               DoubleByDoubleToDouble reducer) {
6049 <            super(p, b); this.nextRight = nextRight;
6049 >            super(m, p, b); this.nextRight = nextRight;
6050              this.transformer = transformer;
6051              this.basis = basis; this.reducer = reducer;
6052          }
# Line 6014 | Line 6061 | public class ConcurrentHashMapV8<K, V>
6061                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6062                      do {} while (!casPending(c = pending, c+1));
6063                      (rights = new MapReduceValuesToDoubleTask<K,V>
6064 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6064 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6065                  }
6066                  double r = id;
6067                  Object v;
# Line 6040 | Line 6087 | public class ConcurrentHashMapV8<K, V>
6087              } catch (Throwable ex) {
6088                  return tryCompleteComputation(ex);
6089              }
6090 +            MapReduceValuesToDoubleTask<K,V> s = rights;
6091 +            if (s != null && !inForkJoinPool()) {
6092 +                do  {
6093 +                    if (s.tryUnfork())
6094 +                        s.exec();
6095 +                } while ((s = s.nextRight) != null);
6096 +            }
6097              return false;
6098          }
6099          public final Double getRawResult() { return result; }
# Line 6053 | Line 6107 | public class ConcurrentHashMapV8<K, V>
6107          double result;
6108          MapReduceEntriesToDoubleTask<K,V> rights, nextRight;
6109          MapReduceEntriesToDoubleTask
6110 <            (ConcurrentHashMapV8<K,V> m,
6057 <             ObjectToDouble<Map.Entry<K,V>> transformer,
6058 <             double basis,
6059 <             DoubleByDoubleToDouble reducer) {
6060 <            super(m);
6061 <            this.transformer = transformer;
6062 <            this.basis = basis; this.reducer = reducer;
6063 <        }
6064 <        MapReduceEntriesToDoubleTask
6065 <            (BulkTask<K,V,?> p, int b,
6110 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6111               MapReduceEntriesToDoubleTask<K,V> nextRight,
6112               ObjectToDouble<Map.Entry<K,V>> transformer,
6113               double basis,
6114               DoubleByDoubleToDouble reducer) {
6115 <            super(p, b); this.nextRight = nextRight;
6115 >            super(m, p, b); this.nextRight = nextRight;
6116              this.transformer = transformer;
6117              this.basis = basis; this.reducer = reducer;
6118          }
# Line 6082 | Line 6127 | public class ConcurrentHashMapV8<K, V>
6127                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6128                      do {} while (!casPending(c = pending, c+1));
6129                      (rights = new MapReduceEntriesToDoubleTask<K,V>
6130 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6130 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6131                  }
6132                  double r = id;
6133                  Object v;
# Line 6108 | Line 6153 | public class ConcurrentHashMapV8<K, V>
6153              } catch (Throwable ex) {
6154                  return tryCompleteComputation(ex);
6155              }
6156 +            MapReduceEntriesToDoubleTask<K,V> s = rights;
6157 +            if (s != null && !inForkJoinPool()) {
6158 +                do  {
6159 +                    if (s.tryUnfork())
6160 +                        s.exec();
6161 +                } while ((s = s.nextRight) != null);
6162 +            }
6163              return false;
6164          }
6165          public final Double getRawResult() { return result; }
# Line 6121 | Line 6173 | public class ConcurrentHashMapV8<K, V>
6173          double result;
6174          MapReduceMappingsToDoubleTask<K,V> rights, nextRight;
6175          MapReduceMappingsToDoubleTask
6176 <            (ConcurrentHashMapV8<K,V> m,
6125 <             ObjectByObjectToDouble<? super K, ? super V> transformer,
6126 <             double basis,
6127 <             DoubleByDoubleToDouble reducer) {
6128 <            super(m);
6129 <            this.transformer = transformer;
6130 <            this.basis = basis; this.reducer = reducer;
6131 <        }
6132 <        MapReduceMappingsToDoubleTask
6133 <            (BulkTask<K,V,?> p, int b,
6176 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6177               MapReduceMappingsToDoubleTask<K,V> nextRight,
6178               ObjectByObjectToDouble<? super K, ? super V> transformer,
6179               double basis,
6180               DoubleByDoubleToDouble reducer) {
6181 <            super(p, b); this.nextRight = nextRight;
6181 >            super(m, p, b); this.nextRight = nextRight;
6182              this.transformer = transformer;
6183              this.basis = basis; this.reducer = reducer;
6184          }
# Line 6150 | Line 6193 | public class ConcurrentHashMapV8<K, V>
6193                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6194                      do {} while (!casPending(c = pending, c+1));
6195                      (rights = new MapReduceMappingsToDoubleTask<K,V>
6196 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6196 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6197                  }
6198                  double r = id;
6199                  Object v;
# Line 6176 | Line 6219 | public class ConcurrentHashMapV8<K, V>
6219              } catch (Throwable ex) {
6220                  return tryCompleteComputation(ex);
6221              }
6222 +            MapReduceMappingsToDoubleTask<K,V> s = rights;
6223 +            if (s != null && !inForkJoinPool()) {
6224 +                do  {
6225 +                    if (s.tryUnfork())
6226 +                        s.exec();
6227 +                } while ((s = s.nextRight) != null);
6228 +            }
6229              return false;
6230          }
6231          public final Double getRawResult() { return result; }
# Line 6189 | Line 6239 | public class ConcurrentHashMapV8<K, V>
6239          long result;
6240          MapReduceKeysToLongTask<K,V> rights, nextRight;
6241          MapReduceKeysToLongTask
6242 <            (ConcurrentHashMapV8<K,V> m,
6193 <             ObjectToLong<? super K> transformer,
6194 <             long basis,
6195 <             LongByLongToLong reducer) {
6196 <            super(m);
6197 <            this.transformer = transformer;
6198 <            this.basis = basis; this.reducer = reducer;
6199 <        }
6200 <        MapReduceKeysToLongTask
6201 <            (BulkTask<K,V,?> p, int b,
6242 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6243               MapReduceKeysToLongTask<K,V> nextRight,
6244               ObjectToLong<? super K> transformer,
6245               long basis,
6246               LongByLongToLong reducer) {
6247 <            super(p, b); this.nextRight = nextRight;
6247 >            super(m, p, b); this.nextRight = nextRight;
6248              this.transformer = transformer;
6249              this.basis = basis; this.reducer = reducer;
6250          }
# Line 6218 | Line 6259 | public class ConcurrentHashMapV8<K, V>
6259                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6260                      do {} while (!casPending(c = pending, c+1));
6261                      (rights = new MapReduceKeysToLongTask<K,V>
6262 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6262 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6263                  }
6264                  long r = id;
6265                  while (advance() != null)
# Line 6243 | Line 6284 | public class ConcurrentHashMapV8<K, V>
6284              } catch (Throwable ex) {
6285                  return tryCompleteComputation(ex);
6286              }
6287 +            MapReduceKeysToLongTask<K,V> s = rights;
6288 +            if (s != null && !inForkJoinPool()) {
6289 +                do  {
6290 +                    if (s.tryUnfork())
6291 +                        s.exec();
6292 +                } while ((s = s.nextRight) != null);
6293 +            }
6294              return false;
6295          }
6296          public final Long getRawResult() { return result; }
# Line 6256 | Line 6304 | public class ConcurrentHashMapV8<K, V>
6304          long result;
6305          MapReduceValuesToLongTask<K,V> rights, nextRight;
6306          MapReduceValuesToLongTask
6307 <            (ConcurrentHashMapV8<K,V> m,
6260 <             ObjectToLong<? super V> transformer,
6261 <             long basis,
6262 <             LongByLongToLong reducer) {
6263 <            super(m);
6264 <            this.transformer = transformer;
6265 <            this.basis = basis; this.reducer = reducer;
6266 <        }
6267 <        MapReduceValuesToLongTask
6268 <            (BulkTask<K,V,?> p, int b,
6307 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6308               MapReduceValuesToLongTask<K,V> nextRight,
6309               ObjectToLong<? super V> transformer,
6310               long basis,
6311               LongByLongToLong reducer) {
6312 <            super(p, b); this.nextRight = nextRight;
6312 >            super(m, p, b); this.nextRight = nextRight;
6313              this.transformer = transformer;
6314              this.basis = basis; this.reducer = reducer;
6315          }
# Line 6285 | Line 6324 | public class ConcurrentHashMapV8<K, V>
6324                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6325                      do {} while (!casPending(c = pending, c+1));
6326                      (rights = new MapReduceValuesToLongTask<K,V>
6327 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6327 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6328                  }
6329                  long r = id;
6330                  Object v;
# Line 6311 | Line 6350 | public class ConcurrentHashMapV8<K, V>
6350              } catch (Throwable ex) {
6351                  return tryCompleteComputation(ex);
6352              }
6353 +            MapReduceValuesToLongTask<K,V> s = rights;
6354 +            if (s != null && !inForkJoinPool()) {
6355 +                do  {
6356 +                    if (s.tryUnfork())
6357 +                        s.exec();
6358 +                } while ((s = s.nextRight) != null);
6359 +            }
6360              return false;
6361          }
6362          public final Long getRawResult() { return result; }
# Line 6324 | Line 6370 | public class ConcurrentHashMapV8<K, V>
6370          long result;
6371          MapReduceEntriesToLongTask<K,V> rights, nextRight;
6372          MapReduceEntriesToLongTask
6373 <            (ConcurrentHashMapV8<K,V> m,
6328 <             ObjectToLong<Map.Entry<K,V>> transformer,
6329 <             long basis,
6330 <             LongByLongToLong reducer) {
6331 <            super(m);
6332 <            this.transformer = transformer;
6333 <            this.basis = basis; this.reducer = reducer;
6334 <        }
6335 <        MapReduceEntriesToLongTask
6336 <            (BulkTask<K,V,?> p, int b,
6373 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6374               MapReduceEntriesToLongTask<K,V> nextRight,
6375               ObjectToLong<Map.Entry<K,V>> transformer,
6376               long basis,
6377               LongByLongToLong reducer) {
6378 <            super(p, b); this.nextRight = nextRight;
6378 >            super(m, p, b); this.nextRight = nextRight;
6379              this.transformer = transformer;
6380              this.basis = basis; this.reducer = reducer;
6381          }
# Line 6353 | Line 6390 | public class ConcurrentHashMapV8<K, V>
6390                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6391                      do {} while (!casPending(c = pending, c+1));
6392                      (rights = new MapReduceEntriesToLongTask<K,V>
6393 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6393 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6394                  }
6395                  long r = id;
6396                  Object v;
# Line 6379 | Line 6416 | public class ConcurrentHashMapV8<K, V>
6416              } catch (Throwable ex) {
6417                  return tryCompleteComputation(ex);
6418              }
6419 +            MapReduceEntriesToLongTask<K,V> s = rights;
6420 +            if (s != null && !inForkJoinPool()) {
6421 +                do  {
6422 +                    if (s.tryUnfork())
6423 +                        s.exec();
6424 +                } while ((s = s.nextRight) != null);
6425 +            }
6426              return false;
6427          }
6428          public final Long getRawResult() { return result; }
# Line 6392 | Line 6436 | public class ConcurrentHashMapV8<K, V>
6436          long result;
6437          MapReduceMappingsToLongTask<K,V> rights, nextRight;
6438          MapReduceMappingsToLongTask
6439 <            (ConcurrentHashMapV8<K,V> m,
6396 <             ObjectByObjectToLong<? super K, ? super V> transformer,
6397 <             long basis,
6398 <             LongByLongToLong reducer) {
6399 <            super(m);
6400 <            this.transformer = transformer;
6401 <            this.basis = basis; this.reducer = reducer;
6402 <        }
6403 <        MapReduceMappingsToLongTask
6404 <            (BulkTask<K,V,?> p, int b,
6439 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6440               MapReduceMappingsToLongTask<K,V> nextRight,
6441               ObjectByObjectToLong<? super K, ? super V> transformer,
6442               long basis,
6443               LongByLongToLong reducer) {
6444 <            super(p, b); this.nextRight = nextRight;
6444 >            super(m, p, b); this.nextRight = nextRight;
6445              this.transformer = transformer;
6446              this.basis = basis; this.reducer = reducer;
6447          }
# Line 6421 | Line 6456 | public class ConcurrentHashMapV8<K, V>
6456                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6457                      do {} while (!casPending(c = pending, c+1));
6458                      (rights = new MapReduceMappingsToLongTask<K,V>
6459 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6459 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6460                  }
6461                  long r = id;
6462                  Object v;
# Line 6447 | Line 6482 | public class ConcurrentHashMapV8<K, V>
6482              } catch (Throwable ex) {
6483                  return tryCompleteComputation(ex);
6484              }
6485 +            MapReduceMappingsToLongTask<K,V> s = rights;
6486 +            if (s != null && !inForkJoinPool()) {
6487 +                do  {
6488 +                    if (s.tryUnfork())
6489 +                        s.exec();
6490 +                } while ((s = s.nextRight) != null);
6491 +            }
6492              return false;
6493          }
6494          public final Long getRawResult() { return result; }
# Line 6460 | Line 6502 | public class ConcurrentHashMapV8<K, V>
6502          int result;
6503          MapReduceKeysToIntTask<K,V> rights, nextRight;
6504          MapReduceKeysToIntTask
6505 <            (ConcurrentHashMapV8<K,V> m,
6464 <             ObjectToInt<? super K> transformer,
6465 <             int basis,
6466 <             IntByIntToInt reducer) {
6467 <            super(m);
6468 <            this.transformer = transformer;
6469 <            this.basis = basis; this.reducer = reducer;
6470 <        }
6471 <        MapReduceKeysToIntTask
6472 <            (BulkTask<K,V,?> p, int b,
6505 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6506               MapReduceKeysToIntTask<K,V> nextRight,
6507               ObjectToInt<? super K> transformer,
6508               int basis,
6509               IntByIntToInt reducer) {
6510 <            super(p, b); this.nextRight = nextRight;
6510 >            super(m, p, b); this.nextRight = nextRight;
6511              this.transformer = transformer;
6512              this.basis = basis; this.reducer = reducer;
6513          }
# Line 6489 | Line 6522 | public class ConcurrentHashMapV8<K, V>
6522                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6523                      do {} while (!casPending(c = pending, c+1));
6524                      (rights = new MapReduceKeysToIntTask<K,V>
6525 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6525 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6526                  }
6527                  int r = id;
6528                  while (advance() != null)
# Line 6514 | Line 6547 | public class ConcurrentHashMapV8<K, V>
6547              } catch (Throwable ex) {
6548                  return tryCompleteComputation(ex);
6549              }
6550 +            MapReduceKeysToIntTask<K,V> s = rights;
6551 +            if (s != null && !inForkJoinPool()) {
6552 +                do  {
6553 +                    if (s.tryUnfork())
6554 +                        s.exec();
6555 +                } while ((s = s.nextRight) != null);
6556 +            }
6557              return false;
6558          }
6559          public final Integer getRawResult() { return result; }
# Line 6527 | Line 6567 | public class ConcurrentHashMapV8<K, V>
6567          int result;
6568          MapReduceValuesToIntTask<K,V> rights, nextRight;
6569          MapReduceValuesToIntTask
6570 <            (ConcurrentHashMapV8<K,V> m,
6531 <             ObjectToInt<? super V> transformer,
6532 <             int basis,
6533 <             IntByIntToInt reducer) {
6534 <            super(m);
6535 <            this.transformer = transformer;
6536 <            this.basis = basis; this.reducer = reducer;
6537 <        }
6538 <        MapReduceValuesToIntTask
6539 <            (BulkTask<K,V,?> p, int b,
6570 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6571               MapReduceValuesToIntTask<K,V> nextRight,
6572               ObjectToInt<? super V> transformer,
6573               int basis,
6574               IntByIntToInt reducer) {
6575 <            super(p, b); this.nextRight = nextRight;
6575 >            super(m, p, b); this.nextRight = nextRight;
6576              this.transformer = transformer;
6577              this.basis = basis; this.reducer = reducer;
6578          }
# Line 6556 | Line 6587 | public class ConcurrentHashMapV8<K, V>
6587                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6588                      do {} while (!casPending(c = pending, c+1));
6589                      (rights = new MapReduceValuesToIntTask<K,V>
6590 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6590 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6591                  }
6592                  int r = id;
6593                  Object v;
# Line 6582 | Line 6613 | public class ConcurrentHashMapV8<K, V>
6613              } catch (Throwable ex) {
6614                  return tryCompleteComputation(ex);
6615              }
6616 +            MapReduceValuesToIntTask<K,V> s = rights;
6617 +            if (s != null && !inForkJoinPool()) {
6618 +                do  {
6619 +                    if (s.tryUnfork())
6620 +                        s.exec();
6621 +                } while ((s = s.nextRight) != null);
6622 +            }
6623              return false;
6624          }
6625          public final Integer getRawResult() { return result; }
# Line 6595 | Line 6633 | public class ConcurrentHashMapV8<K, V>
6633          int result;
6634          MapReduceEntriesToIntTask<K,V> rights, nextRight;
6635          MapReduceEntriesToIntTask
6636 <            (ConcurrentHashMapV8<K,V> m,
6599 <             ObjectToInt<Map.Entry<K,V>> transformer,
6600 <             int basis,
6601 <             IntByIntToInt reducer) {
6602 <            super(m);
6603 <            this.transformer = transformer;
6604 <            this.basis = basis; this.reducer = reducer;
6605 <        }
6606 <        MapReduceEntriesToIntTask
6607 <            (BulkTask<K,V,?> p, int b,
6636 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6637               MapReduceEntriesToIntTask<K,V> nextRight,
6638               ObjectToInt<Map.Entry<K,V>> transformer,
6639               int basis,
6640               IntByIntToInt reducer) {
6641 <            super(p, b); this.nextRight = nextRight;
6641 >            super(m, p, b); this.nextRight = nextRight;
6642              this.transformer = transformer;
6643              this.basis = basis; this.reducer = reducer;
6644          }
# Line 6624 | Line 6653 | public class ConcurrentHashMapV8<K, V>
6653                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6654                      do {} while (!casPending(c = pending, c+1));
6655                      (rights = new MapReduceEntriesToIntTask<K,V>
6656 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6656 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6657                  }
6658                  int r = id;
6659                  Object v;
# Line 6650 | Line 6679 | public class ConcurrentHashMapV8<K, V>
6679              } catch (Throwable ex) {
6680                  return tryCompleteComputation(ex);
6681              }
6682 +            MapReduceEntriesToIntTask<K,V> s = rights;
6683 +            if (s != null && !inForkJoinPool()) {
6684 +                do  {
6685 +                    if (s.tryUnfork())
6686 +                        s.exec();
6687 +                } while ((s = s.nextRight) != null);
6688 +            }
6689              return false;
6690          }
6691          public final Integer getRawResult() { return result; }
# Line 6663 | Line 6699 | public class ConcurrentHashMapV8<K, V>
6699          int result;
6700          MapReduceMappingsToIntTask<K,V> rights, nextRight;
6701          MapReduceMappingsToIntTask
6702 <            (ConcurrentHashMapV8<K,V> m,
6702 >            (ConcurrentHashMapV8<K,V> m, BulkTask<K,V,?> p, int b,
6703 >             MapReduceMappingsToIntTask<K,V> rights,
6704               ObjectByObjectToInt<? super K, ? super V> transformer,
6705               int basis,
6706               IntByIntToInt reducer) {
6707 <            super(m);
6671 <            this.transformer = transformer;
6672 <            this.basis = basis; this.reducer = reducer;
6673 <        }
6674 <        MapReduceMappingsToIntTask
6675 <            (BulkTask<K,V,?> p, int b,
6676 <             MapReduceMappingsToIntTask<K,V> nextRight,
6677 <             ObjectByObjectToInt<? super K, ? super V> transformer,
6678 <             int basis,
6679 <             IntByIntToInt reducer) {
6680 <            super(p, b); this.nextRight = nextRight;
6707 >            super(m, p, b); this.nextRight = nextRight;
6708              this.transformer = transformer;
6709              this.basis = basis; this.reducer = reducer;
6710          }
# Line 6692 | Line 6719 | public class ConcurrentHashMapV8<K, V>
6719                  for (int c, b = batch(); b > 1 && baseIndex != baseLimit;) {
6720                      do {} while (!casPending(c = pending, c+1));
6721                      (rights = new MapReduceMappingsToIntTask<K,V>
6722 <                     (this, b >>>= 1, rights, transformer, id, reducer)).fork();
6722 >                     (map, this, b >>>= 1, rights, transformer, id, reducer)).fork();
6723                  }
6724                  int r = id;
6725                  Object v;
# Line 6718 | Line 6745 | public class ConcurrentHashMapV8<K, V>
6745              } catch (Throwable ex) {
6746                  return tryCompleteComputation(ex);
6747              }
6748 +            MapReduceMappingsToIntTask<K,V> s = rights;
6749 +            if (s != null && !inForkJoinPool()) {
6750 +                do  {
6751 +                    if (s.tryUnfork())
6752 +                        s.exec();
6753 +                } while ((s = s.nextRight) != null);
6754 +            }
6755              return false;
6756          }
6757          public final Integer getRawResult() { return result; }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines