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.51 by jsr166, Wed Jul 18 01:30:54 2012 UTC vs.
Revision 1.52 by dl, Mon Aug 13 15:52:33 2012 UTC

# Line 6 | Line 6
6  
7   package jsr166e;
8   import jsr166e.LongAdder;
9 + import jsr166e.ForkJoinPool;
10 + import jsr166e.ForkJoinTask;
11 +
12 + import java.util.Comparator;
13   import java.util.Arrays;
14   import java.util.Map;
15   import java.util.Set;
# Line 23 | Line 27 | import java.util.concurrent.ConcurrentMa
27   import java.util.concurrent.ThreadLocalRandom;
28   import java.util.concurrent.locks.LockSupport;
29   import java.util.concurrent.locks.AbstractQueuedSynchronizer;
30 + import java.util.concurrent.atomic.AtomicReference;
31 +
32   import java.io.Serializable;
33  
34   /**
# Line 88 | Line 94 | import java.io.Serializable;
94   * Java Collections Framework</a>.
95   *
96   * <p><em>jsr166e note: This class is a candidate replacement for
97 < * java.util.concurrent.ConcurrentHashMap.<em>
97 > * java.util.concurrent.ConcurrentHashMap.  During transition, this
98 > * class declares and uses nested functional interfaces with different
99 > * names but the same forms as those expected for JDK8.<em>
100   *
101   * @since 1.5
102   * @author Doug Lea
# Line 96 | Line 104 | import java.io.Serializable;
104   * @param <V> the type of mapped values
105   */
106   public class ConcurrentHashMapV8<K, V>
107 <        implements ConcurrentMap<K, V>, Serializable {
107 >    implements ConcurrentMap<K, V>, Serializable {
108      private static final long serialVersionUID = 7249069246763182397L;
109  
110      /**
103     * A function computing a mapping from the given key to a value.
104     * This is a place-holder for an upcoming JDK8 interface.
105     */
106    public static interface MappingFunction<K, V> {
107        /**
108         * Returns a value for the given key, or null if there is no mapping.
109         *
110         * @param key the (non-null) key
111         * @return a value for the key, or null if none
112         */
113        V map(K key);
114    }
115
116    /**
117     * A function computing a new mapping given a key and its current
118     * mapped value (or {@code null} if there is no current
119     * mapping). This is a place-holder for an upcoming JDK8
120     * interface.
121     */
122    public static interface RemappingFunction<K, V> {
123        /**
124         * Returns a new value given a key and its current value.
125         *
126         * @param key the (non-null) key
127         * @param value the current value, or null if there is no mapping
128         * @return a value for the key, or null if none
129         */
130        V remap(K key, V value);
131    }
132
133    /**
111       * A partitionable iterator. A Spliterator can be traversed
112       * directly, but can also be partitioned (before traversal) by
113       * creating another Spliterator that covers a non-overlapping
# Line 150 | Line 127 | public class ConcurrentHashMapV8<K, V>
127       *
128       * <pre>
129       * {@code ConcurrentHashMapV8<String, Long> m = ...
130 <     * // Uses parallel depth of log2 of size / (parallelism * slack of 8).
131 <     * int depth = 32 - Integer.numberOfLeadingZeros(m.size() / (aForkJoinPool.getParallelism() * 8));
132 <     * long sum = aForkJoinPool.invoke(new SumValues(m.valueSpliterator(), depth, null));
130 >     * // split as if have 8 * parallelism, for load balance
131 >     * int n = m.size();
132 >     * int p = aForkJoinPool.getParallelism() * 8;
133 >     * int split = (n < p)? n : p;
134 >     * long sum = aForkJoinPool.invoke(new SumValues(m.valueSpliterator(), split, null));
135       * // ...
136       * static class SumValues extends RecursiveTask<Long> {
137       *   final Spliterator<Long> s;
138 <     *   final int depth;             // number of splits before processing
138 >     *   final int split;             // split while > 1
139       *   final SumValues nextJoin;    // records forked subtasks to join
140       *   SumValues(Spliterator<Long> s, int depth, SumValues nextJoin) {
141       *     this.s = s; this.depth = depth; this.nextJoin = nextJoin;
# Line 164 | Line 143 | public class ConcurrentHashMapV8<K, V>
143       *   public Long compute() {
144       *     long sum = 0;
145       *     SumValues subtasks = null; // fork subtasks
146 <     *     for (int d = depth - 1; d >= 0; --d)
147 <     *       (subtasks = new SumValues(s.split(), d, subtasks)).fork();
146 >     *     for (int s = split >>> 1; s > 0; s >>>= 1)
147 >     *       (subtasks = new SumValues(s.split(), s, subtasks)).fork();
148       *     while (s.hasNext())        // directly process remaining elements
149       *       sum += s.next();
150       *     for (SumValues t = subtasks; t != null; t = t.nextJoin)
# Line 348 | Line 327 | public class ConcurrentHashMapV8<K, V>
327       * When there are no lock acquisition failures, this is arranged
328       * simply by proceeding from the last bin (table.length - 1) up
329       * towards the first.  Upon seeing a forwarding node, traversals
330 <     * (see class InternalIterator) arrange to move to the new table
330 >     * (see class Iter) arrange to move to the new table
331       * without revisiting nodes.  However, when any node is skipped
332       * during a transfer, all earlier table bins may have become
333       * visible, so are initialized with a reverse-forwarding node back
# Line 358 | Line 337 | public class ConcurrentHashMapV8<K, V>
337       * mechanics trigger only when necessary.
338       *
339       * The traversal scheme also applies to partial traversals of
340 <     * ranges of bins (via an alternate InternalIterator constructor)
340 >     * ranges of bins (via an alternate Traverser constructor)
341       * to support partitioned aggregate operations.  Also, read-only
342       * operations give up if ever forwarded to a null table, which
343       * provides support for shutdown-style clearing, which is also not
# Line 500 | Line 479 | public class ConcurrentHashMapV8<K, V>
479       * inline assignments below.
480       */
481  
482 <    static final Node tabAt(Node[] tab, int i) { // used by InternalIterator
482 >    static final Node tabAt(Node[] tab, int i) { // used by Iter
483          return (Node)UNSAFE.getObjectVolatile(tab, ((long)i<<ASHIFT)+ABASE);
484      }
485  
# Line 737 | Line 716 | public class ConcurrentHashMapV8<K, V>
716           * starting at given root.
717           */
718          @SuppressWarnings("unchecked") // suppress Comparable cast warning
719 <        final TreeNode getTreeNode(int h, Object k, TreeNode p) {
719 >            final TreeNode getTreeNode(int h, Object k, TreeNode p) {
720              Class<?> c = k.getClass();
721              while (p != null) {
722                  int dir, ph;  Object pk; Class<?> pc;
# Line 798 | Line 777 | public class ConcurrentHashMapV8<K, V>
777           * @return null if added
778           */
779          @SuppressWarnings("unchecked") // suppress Comparable cast warning
780 <        final TreeNode putTreeNode(int h, Object k, Object v) {
780 >            final TreeNode putTreeNode(int h, Object k, Object v) {
781              Class<?> c = k.getClass();
782              TreeNode pp = root, p = null;
783              int dir = 0;
# Line 1439 | Line 1418 | public class ConcurrentHashMapV8<K, V>
1418  
1419      /** Implementation for computeIfAbsent */
1420      private final Object internalComputeIfAbsent(K k,
1421 <                                                 MappingFunction<? super K, ?> mf) {
1421 >                                                 Fun<? super K, ?> mf) {
1422          int h = spread(k.hashCode());
1423          Object val = null;
1424          int count = 0;
# Line 1452 | Line 1431 | public class ConcurrentHashMapV8<K, V>
1431                  if (casTabAt(tab, i, null, node)) {
1432                      count = 1;
1433                      try {
1434 <                        if ((val = mf.map(k)) != null)
1434 >                        if ((val = mf.apply(k)) != null)
1435                              node.val = val;
1436                      } finally {
1437                          if (val == null)
# Line 1477 | Line 1456 | public class ConcurrentHashMapV8<K, V>
1456                              TreeNode p = t.getTreeNode(h, k, t.root);
1457                              if (p != null)
1458                                  val = p.val;
1459 <                            else if ((val = mf.map(k)) != null) {
1459 >                            else if ((val = mf.apply(k)) != null) {
1460                                  added = true;
1461                                  count = 2;
1462                                  t.putTreeNode(h, k, val);
# Line 1531 | Line 1510 | public class ConcurrentHashMapV8<K, V>
1510                                  }
1511                                  Node last = e;
1512                                  if ((e = e.next) == null) {
1513 <                                    if ((val = mf.map(k)) != null) {
1513 >                                    if ((val = mf.apply(k)) != null) {
1514                                          added = true;
1515                                          last.next = new Node(h, k, val, null);
1516                                          if (count >= TREE_THRESHOLD)
# Line 1567 | Line 1546 | public class ConcurrentHashMapV8<K, V>
1546  
1547      /** Implementation for compute */
1548      @SuppressWarnings("unchecked")
1549 <    private final Object internalCompute(K k,
1550 <                                         RemappingFunction<? super K, V> mf) {
1549 >        private final Object internalCompute(K k, boolean onlyIfPresent,
1550 >                                             BiFun<? super K, ? super V, ? extends V> mf) {
1551          int h = spread(k.hashCode());
1552          Object val = null;
1553          int delta = 0;
# Line 1578 | Line 1557 | public class ConcurrentHashMapV8<K, V>
1557              if (tab == null)
1558                  tab = initTable();
1559              else if ((f = tabAt(tab, i = (tab.length - 1) & h)) == null) {
1560 +                if (onlyIfPresent)
1561 +                    break;
1562                  Node node = new Node(fh = h | LOCKED, k, null, null);
1563                  if (casTabAt(tab, i, null, node)) {
1564                      try {
1565                          count = 1;
1566 <                        if ((val = mf.remap(k, null)) != null) {
1566 >                        if ((val = mf.apply(k, null)) != null) {
1567                              node.val = val;
1568                              delta = 1;
1569                          }
# Line 1607 | Line 1588 | public class ConcurrentHashMapV8<K, V>
1588                              count = 1;
1589                              TreeNode p = t.getTreeNode(h, k, t.root);
1590                              Object pv = (p == null) ? null : p.val;
1591 <                            if ((val = mf.remap(k, (V)pv)) != null) {
1591 >                            if ((val = mf.apply(k, (V)pv)) != null) {
1592                                  if (p != null)
1593                                      p.val = val;
1594                                  else {
# Line 1643 | Line 1624 | public class ConcurrentHashMapV8<K, V>
1624                              if ((e.hash & HASH_BITS) == h &&
1625                                  (ev = e.val) != null &&
1626                                  ((ek = e.key) == k || k.equals(ek))) {
1627 <                                val = mf.remap(k, (V)ev);
1627 >                                val = mf.apply(k, (V)ev);
1628                                  if (val != null)
1629                                      e.val = val;
1630                                  else {
# Line 1658 | Line 1639 | public class ConcurrentHashMapV8<K, V>
1639                              }
1640                              pred = e;
1641                              if ((e = e.next) == null) {
1642 <                                if ((val = mf.remap(k, null)) != null) {
1642 >                                if (!onlyIfPresent && (val = mf.apply(k, null)) != null) {
1643                                      pred.next = new Node(h, k, val, null);
1644                                      delta = 1;
1645                                      if (count >= TREE_THRESHOLD)
# Line 1689 | Line 1670 | public class ConcurrentHashMapV8<K, V>
1670          return val;
1671      }
1672  
1673 +    private final Object internalMerge(K k, V v,
1674 +                                       BiFun<? super V, ? super V, ? extends V> mf) {
1675 +        int h = spread(k.hashCode());
1676 +        Object val = null;
1677 +        int delta = 0;
1678 +        int count = 0;
1679 +        for (Node[] tab = table;;) {
1680 +            int i; Node f; int fh; Object fk, fv;
1681 +            if (tab == null)
1682 +                tab = initTable();
1683 +            else if ((f = tabAt(tab, i = (tab.length - 1) & h)) == null) {
1684 +                if (casTabAt(tab, i, null, new Node(h, k, v, null))) {
1685 +                    delta = 1;
1686 +                    val = v;
1687 +                    break;
1688 +                }
1689 +            }
1690 +            else if ((fh = f.hash) == MOVED) {
1691 +                if ((fk = f.key) instanceof TreeBin) {
1692 +                    TreeBin t = (TreeBin)fk;
1693 +                    t.acquire(0);
1694 +                    try {
1695 +                        if (tabAt(tab, i) == f) {
1696 +                            count = 1;
1697 +                            TreeNode p = t.getTreeNode(h, k, t.root);
1698 +                            val = (p == null) ? v : mf.apply((V)p.val, v);
1699 +                            if (val != null) {
1700 +                                if (p != null)
1701 +                                    p.val = val;
1702 +                                else {
1703 +                                    count = 2;
1704 +                                    delta = 1;
1705 +                                    t.putTreeNode(h, k, val);
1706 +                                }
1707 +                            }
1708 +                            else if (p != null) {
1709 +                                delta = -1;
1710 +                                t.deleteTreeNode(p);
1711 +                            }
1712 +                        }
1713 +                    } finally {
1714 +                        t.release(0);
1715 +                    }
1716 +                    if (count != 0)
1717 +                        break;
1718 +                }
1719 +                else
1720 +                    tab = (Node[])fk;
1721 +            }
1722 +            else if ((fh & LOCKED) != 0) {
1723 +                checkForResize();
1724 +                f.tryAwaitLock(tab, i);
1725 +            }
1726 +            else if (f.casHash(fh, fh | LOCKED)) {
1727 +                try {
1728 +                    if (tabAt(tab, i) == f) {
1729 +                        count = 1;
1730 +                        for (Node e = f, pred = null;; ++count) {
1731 +                            Object ek, ev;
1732 +                            if ((e.hash & HASH_BITS) == h &&
1733 +                                (ev = e.val) != null &&
1734 +                                ((ek = e.key) == k || k.equals(ek))) {
1735 +                                val = mf.apply(v, (V)ev);
1736 +                                if (val != null)
1737 +                                    e.val = val;
1738 +                                else {
1739 +                                    delta = -1;
1740 +                                    Node en = e.next;
1741 +                                    if (pred != null)
1742 +                                        pred.next = en;
1743 +                                    else
1744 +                                        setTabAt(tab, i, en);
1745 +                                }
1746 +                                break;
1747 +                            }
1748 +                            pred = e;
1749 +                            if ((e = e.next) == null) {
1750 +                                val = v;
1751 +                                pred.next = new Node(h, k, val, null);
1752 +                                delta = 1;
1753 +                                if (count >= TREE_THRESHOLD)
1754 +                                    replaceWithTreeBin(tab, i, k);
1755 +                                break;
1756 +                            }
1757 +                        }
1758 +                    }
1759 +                } finally {
1760 +                    if (!f.casHash(fh | LOCKED, fh)) {
1761 +                        f.hash = fh;
1762 +                        synchronized (f) { f.notifyAll(); };
1763 +                    }
1764 +                }
1765 +                if (count != 0) {
1766 +                    if (tab.length <= 64)
1767 +                        count = 2;
1768 +                    break;
1769 +                }
1770 +            }
1771 +        }
1772 +        if (delta != 0) {
1773 +            counter.add((long)delta);
1774 +            if (count > 1)
1775 +                checkForResize();
1776 +        }
1777 +        return val;
1778 +    }
1779 +
1780      /** Implementation for putAll */
1781      private final void internalPutAll(Map<?, ?> m) {
1782          tryPresize(m.size());
# Line 2168 | Line 2256 | public class ConcurrentHashMapV8<K, V>
2256       * paranoically cope with potential sharing by users of iterators
2257       * across threads, iteration terminates if a bounds checks fails
2258       * for a table read.
2259 +     *
2260 +     * This class extends ForkJoinTask to streamline parallel
2261 +     * iteration in bulk operations (see BulkTask). This adds only an
2262 +     * int of space overhead, which is close enough to negligible in
2263 +     * cases where it is not needed to not worry about it.
2264       */
2265 <    static class InternalIterator<K,V> {
2265 >    static class Traverser<K,V,R> extends ForkJoinTask<R> {
2266          final ConcurrentHashMapV8<K, V> map;
2267          Node next;           // the next entry to use
2268          Node last;           // the last entry used
# Line 2182 | Line 2275 | public class ConcurrentHashMapV8<K, V>
2275          final int baseSize;  // initial table size
2276  
2277          /** Creates iterator for all entries in the table. */
2278 <        InternalIterator(ConcurrentHashMapV8<K, V> map) {
2278 >        Traverser(ConcurrentHashMapV8<K, V> map) {
2279              this.tab = (this.map = map).table;
2280              baseLimit = baseSize = (tab == null) ? 0 : tab.length;
2281          }
2282  
2283 <        /** Creates iterator for clone() and split() methods. */
2284 <        InternalIterator(InternalIterator<K,V> it, boolean split) {
2283 >        /** Creates iterator for split() methods */
2284 >        Traverser(Traverser<K,V,?> it, boolean split) {
2285              this.map = it.map;
2286              this.tab = it.tab;
2287              this.baseSize = it.baseSize;
2288              int lo = it.baseIndex;
2289              int hi = this.baseLimit = it.baseLimit;
2290 <            this.index = this.baseIndex =
2291 <                (split) ? (it.baseLimit = (lo + hi + 1) >>> 1) : lo;
2290 >            int i;
2291 >            if (split) // adjust parent
2292 >                i = it.baseLimit = (lo + hi + 1) >>> 1;
2293 >            else       // clone parent
2294 >                i = lo;
2295 >            this.index = this.baseIndex = i;
2296          }
2297  
2298          /**
# Line 2244 | Line 2341 | public class ConcurrentHashMapV8<K, V>
2341          }
2342  
2343          public final boolean hasMoreElements() { return hasNext(); }
2344 +        public final void setRawResult(Object x) { }
2345 +        public R getRawResult() { return null; }
2346 +        public boolean exec() { return true; }
2347      }
2348  
2349      /* ---------------- Public operations -------------- */
# Line 2353 | Line 2453 | public class ConcurrentHashMapV8<K, V>
2453                  (int)n);
2454      }
2455  
2456 <    final long longSize() { // accurate version of size needed for views
2456 >    /**
2457 >     * Returns the number of mappings. This method should be used
2458 >     * instead of {@link #size} because a ConcurrentHashMap may
2459 >     * contain more mappings than can be represented as an int. The
2460 >     * value returned is a snapshot; the actual count may differ if
2461 >     * there are ongoing concurrent insertions of removals.
2462 >     *
2463 >     * @return the number of mappings
2464 >     */
2465 >    public long mappingCount() {
2466          long n = counter.sum();
2467          return (n < 0L) ? 0L : n;
2468      }
# Line 2370 | Line 2479 | public class ConcurrentHashMapV8<K, V>
2479       * @throws NullPointerException if the specified key is null
2480       */
2481      @SuppressWarnings("unchecked")
2482 <    public V get(Object key) {
2482 >        public V get(Object key) {
2483          if (key == null)
2484              throw new NullPointerException();
2485          return (V)internalGet(key);
# Line 2405 | Line 2514 | public class ConcurrentHashMapV8<K, V>
2514          if (value == null)
2515              throw new NullPointerException();
2516          Object v;
2517 <        InternalIterator<K,V> it = new InternalIterator<K,V>(this);
2517 >        Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
2518          while ((v = it.advance()) != null) {
2519              if (v == value || value.equals(v))
2520                  return true;
# Line 2446 | Line 2555 | public class ConcurrentHashMapV8<K, V>
2555       * @throws NullPointerException if the specified key or value is null
2556       */
2557      @SuppressWarnings("unchecked")
2558 <    public V put(K key, V value) {
2558 >        public V put(K key, V value) {
2559          if (key == null || value == null)
2560              throw new NullPointerException();
2561          return (V)internalPut(key, value);
# Line 2460 | Line 2569 | public class ConcurrentHashMapV8<K, V>
2569       * @throws NullPointerException if the specified key or value is null
2570       */
2571      @SuppressWarnings("unchecked")
2572 <    public V putIfAbsent(K key, V value) {
2572 >        public V putIfAbsent(K key, V value) {
2573          if (key == null || value == null)
2574              throw new NullPointerException();
2575          return (V)internalPutIfAbsent(key, value);
# Line 2484 | Line 2593 | public class ConcurrentHashMapV8<K, V>
2593       * <pre> {@code
2594       * if (map.containsKey(key))
2595       *   return map.get(key);
2596 <     * value = mappingFunction.map(key);
2596 >     * value = mappingFunction.apply(key);
2597       * if (value != null)
2598       *   map.put(key, value);
2599       * return value;}</pre>
# Line 2501 | Line 2610 | public class ConcurrentHashMapV8<K, V>
2610       * memoized result, as in:
2611       *
2612       *  <pre> {@code
2613 <     * map.computeIfAbsent(key, new MappingFunction<K, V>() {
2613 >     * map.computeIfAbsent(key, new Fun<K, V>() {
2614       *   public V map(K k) { return new Value(f(k)); }});}</pre>
2615       *
2616       * @param key key with which the specified value is to be associated
# Line 2517 | Line 2626 | public class ConcurrentHashMapV8<K, V>
2626       *         in which case the mapping is left unestablished
2627       */
2628      @SuppressWarnings("unchecked")
2629 <    public V computeIfAbsent(K key, MappingFunction<? super K, ? extends V> mappingFunction) {
2629 >        public V computeIfAbsent(K key, Fun<? super K, ? extends V> mappingFunction) {
2630          if (key == null || mappingFunction == null)
2631              throw new NullPointerException();
2632          return (V)internalComputeIfAbsent(key, mappingFunction);
2633      }
2634  
2635      /**
2636 +     * If the given key is present, computes a new mapping value given a key and
2637 +     * its current mapped value. This is equivalent to
2638 +     *  <pre> {@code
2639 +     *   if (map.containsKey(key)) {
2640 +     *     value = remappingFunction.apply(key, map.get(key));
2641 +     *     if (value != null)
2642 +     *       map.put(key, value);
2643 +     *     else
2644 +     *       map.remove(key);
2645 +     *   }
2646 +     * }</pre>
2647 +     *
2648 +     * except that the action is performed atomically.  If the
2649 +     * function returns {@code null}, the mapping is removed.  If the
2650 +     * function itself throws an (unchecked) exception, the exception
2651 +     * is rethrown to its caller, and the current mapping is left
2652 +     * unchanged.  Some attempted update operations on this map by
2653 +     * other threads may be blocked while computation is in progress,
2654 +     * so the computation should be short and simple, and must not
2655 +     * attempt to update any other mappings of this Map. For example,
2656 +     * to either create or append new messages to a value mapping:
2657 +     *
2658 +     * @param key key with which the specified value is to be associated
2659 +     * @param remappingFunction the function to compute a value
2660 +     * @return the new value associated with
2661 +     *         the specified key, or null if none.
2662 +     * @throws NullPointerException if the specified key or remappingFunction
2663 +     *         is null
2664 +     * @throws IllegalStateException if the computation detectably
2665 +     *         attempts a recursive update to this map that would
2666 +     *         otherwise never complete
2667 +     * @throws RuntimeException or Error if the remappingFunction does so,
2668 +     *         in which case the mapping is unchanged
2669 +     */
2670 +    public V computeIfPresent(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2671 +        if (key == null || remappingFunction == null)
2672 +            throw new NullPointerException();
2673 +        return (V)internalCompute(key, true, remappingFunction);
2674 +    }
2675 +
2676 +    /**
2677       * Computes a new mapping value given a key and
2678       * its current mapped value (or {@code null} if there is no current
2679       * mapping). This is equivalent to
2680       *  <pre> {@code
2681 <     *   value = remappingFunction.remap(key, map.get(key));
2681 >     *   value = remappingFunction.apply(key, map.get(key));
2682       *   if (value != null)
2683       *     map.put(key, value);
2684       *   else
# Line 2548 | Line 2698 | public class ConcurrentHashMapV8<K, V>
2698       * <pre> {@code
2699       * Map<Key, String> map = ...;
2700       * final String msg = ...;
2701 <     * map.compute(key, new RemappingFunction<Key, String>() {
2702 <     *   public String remap(Key k, String v) {
2701 >     * map.compute(key, new BiFun<Key, String, String>() {
2702 >     *   public String apply(Key k, String v) {
2703       *    return (v == null) ? msg : v + msg;});}}</pre>
2704       *
2705       * @param key key with which the specified value is to be associated
# Line 2564 | Line 2714 | public class ConcurrentHashMapV8<K, V>
2714       * @throws RuntimeException or Error if the remappingFunction does so,
2715       *         in which case the mapping is unchanged
2716       */
2717 <    @SuppressWarnings("unchecked")
2718 <    public V compute(K key, RemappingFunction<? super K, V> remappingFunction) {
2717 >    //    @SuppressWarnings("unchecked")
2718 >    public V compute(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) {
2719          if (key == null || remappingFunction == null)
2720              throw new NullPointerException();
2721 <        return (V)internalCompute(key, remappingFunction);
2721 >        return (V)internalCompute(key, false, remappingFunction);
2722 >    }
2723 >
2724 >    /**
2725 >     * If the specified key is not already associated
2726 >     * with a value, associate it with the given value.
2727 >     * Otherwise, replace the value with the results of
2728 >     * the given remapping function. This is equivalent to:
2729 >     *  <pre> {@code
2730 >     *   if (!map.containsKey(key))
2731 >     *     map.put(value);
2732 >     *   else {
2733 >     *     newValue = remappingFunction.apply(map.get(key), value);
2734 >     *     if (value != null)
2735 >     *       map.put(key, value);
2736 >     *     else
2737 >     *       map.remove(key);
2738 >     *   }
2739 >     * }</pre>
2740 >     * except that the action is performed atomically.  If the
2741 >     * function returns {@code null}, the mapping is removed.  If the
2742 >     * function itself throws an (unchecked) exception, the exception
2743 >     * is rethrown to its caller, and the current mapping is left
2744 >     * unchanged.  Some attempted update operations on this map by
2745 >     * other threads may be blocked while computation is in progress,
2746 >     * so the computation should be short and simple, and must not
2747 >     * attempt to update any other mappings of this Map.
2748 >     */
2749 >    //    @SuppressWarnings("unchecked")
2750 >    public V merge(K key, V value, BiFun<? super V, ? super V, ? extends V> remappingFunction) {
2751 >        if (key == null || value == null || remappingFunction == null)
2752 >            throw new NullPointerException();
2753 >        return (V)internalMerge(key, value, remappingFunction);
2754      }
2755  
2756      /**
# Line 2581 | Line 2763 | public class ConcurrentHashMapV8<K, V>
2763       * @throws NullPointerException if the specified key is null
2764       */
2765      @SuppressWarnings("unchecked")
2766 <    public V remove(Object key) {
2766 >        public V remove(Object key) {
2767          if (key == null)
2768              throw new NullPointerException();
2769          return (V)internalReplace(key, null, null);
# Line 2619 | Line 2801 | public class ConcurrentHashMapV8<K, V>
2801       * @throws NullPointerException if the specified key or value is null
2802       */
2803      @SuppressWarnings("unchecked")
2804 <    public V replace(K key, V value) {
2804 >        public V replace(K key, V value) {
2805          if (key == null || value == null)
2806              throw new NullPointerException();
2807          return (V)internalReplace(key, value, null);
# Line 2751 | Line 2933 | public class ConcurrentHashMapV8<K, V>
2933       */
2934      public int hashCode() {
2935          int h = 0;
2936 <        InternalIterator<K,V> it = new InternalIterator<K,V>(this);
2936 >        Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
2937          Object v;
2938          while ((v = it.advance()) != null) {
2939              h += it.nextKey.hashCode() ^ v.hashCode();
# Line 2771 | Line 2953 | public class ConcurrentHashMapV8<K, V>
2953       * @return a string representation of this map
2954       */
2955      public String toString() {
2956 <        InternalIterator<K,V> it = new InternalIterator<K,V>(this);
2956 >        Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
2957          StringBuilder sb = new StringBuilder();
2958          sb.append('{');
2959          Object v;
# Line 2804 | Line 2986 | public class ConcurrentHashMapV8<K, V>
2986              if (!(o instanceof Map))
2987                  return false;
2988              Map<?,?> m = (Map<?,?>) o;
2989 <            InternalIterator<K,V> it = new InternalIterator<K,V>(this);
2989 >            Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
2990              Object val;
2991              while ((val = it.advance()) != null) {
2992                  Object v = m.get(it.nextKey);
# Line 2825 | Line 3007 | public class ConcurrentHashMapV8<K, V>
3007  
3008      /* ----------------Iterators -------------- */
3009  
3010 <    static final class KeyIterator<K,V> extends InternalIterator<K,V>
3010 >    static final class KeyIterator<K,V> extends Traverser<K,V,Object>
3011          implements Spliterator<K>, Enumeration<K> {
3012          KeyIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3013 <        KeyIterator(InternalIterator<K,V> it, boolean split) {
3013 >        KeyIterator(Traverser<K,V,Object> it, boolean split) {
3014              super(it, split);
3015          }
3016          public KeyIterator<K,V> split() {
# Line 2836 | Line 3018 | public class ConcurrentHashMapV8<K, V>
3018                  throw new IllegalStateException();
3019              return new KeyIterator<K,V>(this, true);
3020          }
2839        public KeyIterator<K,V> clone() {
2840            if (last != null || (next != null && nextVal == null))
2841                throw new IllegalStateException();
2842            return new KeyIterator<K,V>(this, false);
2843        }
2844
3021          @SuppressWarnings("unchecked")
3022 <        public final K next() {
3022 >            public final K next() {
3023              if (nextVal == null && advance() == null)
3024                  throw new NoSuchElementException();
3025              Object k = nextKey;
# Line 2854 | Line 3030 | public class ConcurrentHashMapV8<K, V>
3030          public final K nextElement() { return next(); }
3031      }
3032  
3033 <    static final class ValueIterator<K,V> extends InternalIterator<K,V>
3033 >    static final class ValueIterator<K,V> extends Traverser<K,V,Object>
3034          implements Spliterator<V>, Enumeration<V> {
3035          ValueIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3036 <        ValueIterator(InternalIterator<K,V> it, boolean split) {
3036 >        ValueIterator(Traverser<K,V,Object> it, boolean split) {
3037              super(it, split);
3038          }
3039          public ValueIterator<K,V> split() {
# Line 2866 | Line 3042 | public class ConcurrentHashMapV8<K, V>
3042              return new ValueIterator<K,V>(this, true);
3043          }
3044  
2869        public ValueIterator<K,V> clone() {
2870            if (last != null || (next != null && nextVal == null))
2871                throw new IllegalStateException();
2872            return new ValueIterator<K,V>(this, false);
2873        }
2874
3045          @SuppressWarnings("unchecked")
3046 <        public final V next() {
3046 >            public final V next() {
3047              Object v;
3048              if ((v = nextVal) == null && (v = advance()) == null)
3049                  throw new NoSuchElementException();
# Line 2884 | Line 3054 | public class ConcurrentHashMapV8<K, V>
3054          public final V nextElement() { return next(); }
3055      }
3056  
3057 <    static final class EntryIterator<K,V> extends InternalIterator<K,V>
3057 >    static final class EntryIterator<K,V> extends Traverser<K,V,Object>
3058          implements Spliterator<Map.Entry<K,V>> {
3059          EntryIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3060 <        EntryIterator(InternalIterator<K,V> it, boolean split) {
3060 >        EntryIterator(Traverser<K,V,Object> it, boolean split) {
3061              super(it, split);
3062          }
3063          public EntryIterator<K,V> split() {
# Line 2895 | Line 3065 | public class ConcurrentHashMapV8<K, V>
3065                  throw new IllegalStateException();
3066              return new EntryIterator<K,V>(this, true);
3067          }
2898        public EntryIterator<K,V> clone() {
2899            if (last != null || (next != null && nextVal == null))
2900                throw new IllegalStateException();
2901            return new EntryIterator<K,V>(this, false);
2902        }
3068  
3069          @SuppressWarnings("unchecked")
3070 <        public final Map.Entry<K,V> next() {
3070 >            public final Map.Entry<K,V> next() {
3071              Object v;
3072              if ((v = nextVal) == null && (v = advance()) == null)
3073                  throw new NoSuchElementException();
# Line 2960 | Line 3125 | public class ConcurrentHashMapV8<K, V>
3125      /**
3126       * Base class for views.
3127       */
3128 <    static abstract class MapView<K, V> {
3128 >    static abstract class CHMView<K, V> {
3129          final ConcurrentHashMapV8<K, V> map;
3130 <        MapView(ConcurrentHashMapV8<K, V> map)  { this.map = map; }
3130 >        CHMView(ConcurrentHashMapV8<K, V> map)  { this.map = map; }
3131          public final int size()                 { return map.size(); }
3132          public final boolean isEmpty()          { return map.isEmpty(); }
3133          public final void clear()               { map.clear(); }
# Line 2975 | Line 3140 | public class ConcurrentHashMapV8<K, V>
3140          private static final String oomeMsg = "Required array size too large";
3141  
3142          public final Object[] toArray() {
3143 <            long sz = map.longSize();
3143 >            long sz = map.mappingCount();
3144              if (sz > (long)(MAX_ARRAY_SIZE))
3145                  throw new OutOfMemoryError(oomeMsg);
3146              int n = (int)sz;
# Line 2998 | Line 3163 | public class ConcurrentHashMapV8<K, V>
3163          }
3164  
3165          @SuppressWarnings("unchecked")
3166 <        public final <T> T[] toArray(T[] a) {
3167 <            long sz = map.longSize();
3166 >            public final <T> T[] toArray(T[] a) {
3167 >            long sz = map.mappingCount();
3168              if (sz > (long)(MAX_ARRAY_SIZE))
3169                  throw new OutOfMemoryError(oomeMsg);
3170              int m = (int)sz;
# Line 3086 | Line 3251 | public class ConcurrentHashMapV8<K, V>
3251  
3252      }
3253  
3254 <    static final class KeySet<K,V> extends MapView<K,V> implements Set<K> {
3255 <        KeySet(ConcurrentHashMapV8<K, V> map)   { super(map); }
3254 >    static final class KeySet<K,V> extends CHMView<K,V> implements Set<K> {
3255 >        KeySet(ConcurrentHashMapV8<K, V> map)  {
3256 >            super(map);
3257 >        }
3258          public final boolean contains(Object o) { return map.containsKey(o); }
3259          public final boolean remove(Object o)   { return map.remove(o) != null; }
3260          public final Iterator<K> iterator() {
# Line 3107 | Line 3274 | public class ConcurrentHashMapV8<K, V>
3274          }
3275      }
3276  
3277 <    static final class Values<K,V> extends MapView<K,V>
3277 >
3278 >    static final class Values<K,V> extends CHMView<K,V>
3279          implements Collection<V> {
3280          Values(ConcurrentHashMapV8<K, V> map)   { super(map); }
3281          public final boolean contains(Object o) { return map.containsValue(o); }
# Line 3132 | Line 3300 | public class ConcurrentHashMapV8<K, V>
3300          public final boolean addAll(Collection<? extends V> c) {
3301              throw new UnsupportedOperationException();
3302          }
3303 +
3304      }
3305  
3306 <    static final class EntrySet<K,V> extends MapView<K,V>
3306 >    static final class EntrySet<K,V> extends CHMView<K,V>
3307          implements Set<Map.Entry<K,V>> {
3308          EntrySet(ConcurrentHashMapV8<K, V> map) { super(map); }
3309          public final boolean contains(Object o) {
# Line 3191 | Line 3360 | public class ConcurrentHashMapV8<K, V>
3360       * The key-value mappings are emitted in no particular order.
3361       */
3362      @SuppressWarnings("unchecked")
3363 <    private void writeObject(java.io.ObjectOutputStream s)
3364 <            throws java.io.IOException {
3363 >        private void writeObject(java.io.ObjectOutputStream s)
3364 >        throws java.io.IOException {
3365          if (segments == null) { // for serialization compatibility
3366              segments = (Segment<K,V>[])
3367                  new Segment<?,?>[DEFAULT_CONCURRENCY_LEVEL];
# Line 3200 | Line 3369 | public class ConcurrentHashMapV8<K, V>
3369                  segments[i] = new Segment<K,V>(LOAD_FACTOR);
3370          }
3371          s.defaultWriteObject();
3372 <        InternalIterator<K,V> it = new InternalIterator<K,V>(this);
3372 >        Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
3373          Object v;
3374          while ((v = it.advance()) != null) {
3375              s.writeObject(it.nextKey);
# Line 3216 | Line 3385 | public class ConcurrentHashMapV8<K, V>
3385       * @param s the stream
3386       */
3387      @SuppressWarnings("unchecked")
3388 <    private void readObject(java.io.ObjectInputStream s)
3389 <            throws java.io.IOException, ClassNotFoundException {
3388 >        private void readObject(java.io.ObjectInputStream s)
3389 >        throws java.io.IOException, ClassNotFoundException {
3390          s.defaultReadObject();
3391          this.segments = null; // unneeded
3392          // initialize transient final field
# Line 3294 | Line 3463 | public class ConcurrentHashMapV8<K, V>
3463          }
3464      }
3465  
3466 +
3467 +    // -------------------------------------------------------
3468 +
3469 +    // Sams
3470 +    /** Interface describing a void action of one argument */
3471 +    public interface Action<A> { void apply(A a); }
3472 +    /** Interface describing a void action of two arguments */
3473 +    public interface BiAction<A,B> { void apply(A a, B b); }
3474 +    /** Interface describing a function of one argument */
3475 +    public interface Fun<A,T> { T apply(A a); }
3476 +    /** Interface describing a function of two arguments */
3477 +    public interface BiFun<A,B,T> { T apply(A a, B b); }
3478 +    /** Interface describing a function of no arguments */
3479 +    public interface Generator<T> { T apply(); }
3480 +    /** Interface describing a function mapping its argument to a double */
3481 +    public interface ObjectToDouble<A> { double apply(A a); }
3482 +    /** Interface describing a function mapping its argument to a long */
3483 +    public interface ObjectToLong<A> { long apply(A a); }
3484 +    /** Interface describing a function mapping its argument to an int */
3485 +    public interface ObjectToInt<A> {int apply(A a); }
3486 +    /** Interface describing a function mapping two arguments to a double */
3487 +    public interface ObjectByObjectToDouble<A,B> { double apply(A a, B b); }
3488 +    /** Interface describing a function mapping two arguments to a long */
3489 +    public interface ObjectByObjectToLong<A,B> { long apply(A a, B b); }
3490 +    /** Interface describing a function mapping two arguments to an int */
3491 +    public interface ObjectByObjectToInt<A,B> {int apply(A a, B b); }
3492 +    /** Interface describing a function mapping a double to a double */
3493 +    public interface DoubleToDouble { double apply(double a); }
3494 +    /** Interface describing a function mapping a long to a long */
3495 +    public interface LongToLong { long apply(long a); }
3496 +    /** Interface describing a function mapping an int to an int */
3497 +    public interface IntToInt { int apply(int a); }
3498 +    /** Interface describing a function mapping two doubles to a double */
3499 +    public interface DoubleByDoubleToDouble { double apply(double a, double b); }
3500 +    /** Interface describing a function mapping two longs to a long */
3501 +    public interface LongByLongToLong { long apply(long a, long b); }
3502 +    /** Interface describing a function mapping two ints to an int */
3503 +    public interface IntByIntToInt { int apply(int a, int b); }
3504 +
3505 +
3506 +    // -------------------------------------------------------
3507 +
3508 +    /**
3509 +     * Returns an extended {@link Parallel} view of this map using the
3510 +     * given executor for bulk parallel operations.
3511 +     *
3512 +     * @param executor the executor
3513 +     * @return a parallel view
3514 +     */
3515 +    public Parallel parallel(ForkJoinPool executor)  {
3516 +        return new Parallel(executor);
3517 +    }
3518 +
3519 +    /**
3520 +     * An extended view of a ConcurrentHashMap supporting bulk
3521 +     * parallel operations. These operations are designed to be be
3522 +     * safely, and often sensibly, applied even with maps that are
3523 +     * being concurrently updated by other threads; for example, when
3524 +     * computing a snapshot summary of the values in a shared
3525 +     * registry.  There are three kinds of operation, each with four
3526 +     * forms, accepting functions with Keys, Values, Entries, and
3527 +     * (Key, Value) arguments and/or return values. Because the
3528 +     * elements of a ConcurrentHashMap are not ordered in any
3529 +     * particular way, and may be processed in different orders in
3530 +     * different parallel executions, the correctness of supplied
3531 +     * functions should not depend on any ordering, or on any other
3532 +     * objects or values that may transiently change while computation
3533 +     * is in progress; and except for forEach actions, should ideally
3534 +     * be side-effect-free.
3535 +     *
3536 +     * <ul>
3537 +     * <li> forEach: Perform a given action on each element.
3538 +     * A variant form applies a given transformation on each element
3539 +     * before performing the action.</li>
3540 +     *
3541 +     * <li> search: Return the first available non-null result of
3542 +     * applying a given function on each element; skipping further
3543 +     * search when a result is found.</li>
3544 +     *
3545 +     * <li> reduce: Accumulate each element.  The supplied reduction
3546 +     * function cannot rely on ordering (more formally, it should be
3547 +     * both associative and commutative).  There are five variants:
3548 +     *
3549 +     * <ul>
3550 +     *
3551 +     * <li> Plain reductions. (There is not a form of this method for
3552 +     * (key, value) function arguments since there is no corresponding
3553 +     * return type.)</li>
3554 +     *
3555 +     * <li> Mapped reductions that accumulate the results of a given
3556 +     * function applied to each element.</li>
3557 +     *
3558 +     * <li> Reductions to scalar doubles, longs, and ints, using a
3559 +     * given basis value.</li>
3560 +     *
3561 +     * </li>
3562 +     * </ul>
3563 +     * </ul>
3564 +     *
3565 +     * <p>The concurrency properties of the bulk operations follow
3566 +     * from those of ConcurrentHashMap: Any non-null result returned
3567 +     * from {@code get(key)} and related access methods bears a
3568 +     * happens-before relation with the associated insertion or
3569 +     * update.  The result of any bulk operation reflects the
3570 +     * composition of these per-element relations (but is not
3571 +     * necessarily atomic with respect to the map as a whole unless it
3572 +     * is somehow known to be quiescent).  Conversely, because keys
3573 +     * and values in the map are never null, null serves as a reliable
3574 +     * atomic indicator of the current lack of any result.  To
3575 +     * maintain this property, null serves as an implicit basis for
3576 +     * all non-scalar reduction operations. For the double, long, and
3577 +     * int versions, the basis should be one that, when combined with
3578 +     * any other value, returns that other value (more formally, it
3579 +     * should be the identity element for the reduction). Most common
3580 +     * reductions have these properties; for example, computing a sum
3581 +     * with basis 0 or a minimum with basis MAX_VALUE.
3582 +     *
3583 +     * <p>Search and transformation functions provided as arguments
3584 +     * should similarly return null to indicate the lack of any result
3585 +     * (in which case it is not used). In the case of mapped
3586 +     * reductions, this also enables transformations to serve as
3587 +     * filters, returning null (or, in the case of primitive
3588 +     * specializations, the identity basis) if the element should not
3589 +     * be combined. You can create compound transformations and
3590 +     * filterings by composing them yourself under this "null means
3591 +     * there is nothing there now" rule before using them in search or
3592 +     * reduce operations.
3593 +     *
3594 +     * <p>Methods accepting and/or returning Entry arguments maintain
3595 +     * key-value associations. They may be useful for example when
3596 +     * finding the key for the greatest value. Note that "plain" Entry
3597 +     * arguments can be supplied using {@code new
3598 +     * AbstractMap.SimpleEntry(k,v)}.
3599 +     *
3600 +     * <p> Bulk operations may complete abruptly, throwing an
3601 +     * exception encountered in the application of a supplied
3602 +     * function. Bear in mind when handling such exceptions that other
3603 +     * concurrently executing functions could also have thrown
3604 +     * exceptions, or would have done so if the first exception had
3605 +     * not occurred.
3606 +     *
3607 +     * <p>Parallel speedups compared to sequential processing are
3608 +     * common but not guaranteed.  Operations involving brief
3609 +     * functions on small maps may execute more slowly than sequential
3610 +     * loops if the underlying work to parallelize the computation is
3611 +     * more expensive than the computation itself. Similarly,
3612 +     * parallelization may not lead to much actual parallelism if all
3613 +     * processors are busy performing unrelated tasks.
3614 +     *
3615 +     * <p> All arguments to all task methods must be non-null.
3616 +     *
3617 +     * <p><em>jsr166e note: During transition, this class
3618 +     * uses nested functional interfaces with different names but the
3619 +     * same forms as those expected for JDK8.<em>
3620 +     */
3621 +    public class Parallel {
3622 +        final ForkJoinPool fjp;
3623 +
3624 +        /**
3625 +         * Returns an extended view of this map using the given
3626 +         * executor for bulk parallel operations.
3627 +         *
3628 +         * @param executor the executor
3629 +         */
3630 +        public Parallel(ForkJoinPool executor)  {
3631 +            this.fjp = executor;
3632 +        }
3633 +
3634 +        /**
3635 +         * Performs the given action for each (key, value).
3636 +         *
3637 +         * @param action the action
3638 +         */
3639 +        public void forEach(BiAction<K,V> action) {
3640 +            fjp.invoke(ForkJoinTasks.forEach
3641 +                       (ConcurrentHashMapV8.this, action));
3642 +        }
3643 +
3644 +        /**
3645 +         * Performs the given action for each non-null transformation
3646 +         * of each (key, value).
3647 +         *
3648 +         * @param transformer a function returning the transformation
3649 +         * for an element, or null of there is no transformation (in
3650 +         * which case the action is not applied).
3651 +         * @param action the action
3652 +         */
3653 +        public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
3654 +                                Action<U> action) {
3655 +            fjp.invoke(ForkJoinTasks.forEach
3656 +                       (ConcurrentHashMapV8.this, transformer, action));
3657 +        }
3658 +
3659 +        /**
3660 +         * Returns a non-null result from applying the given search
3661 +         * function on each (key, value), or null if none.  Further
3662 +         * element processing is suppressed upon success. However,
3663 +         * this method does not return until other in-progress
3664 +         * parallel invocations of the search function also complete.
3665 +         *
3666 +         * @param searchFunction a function returning a non-null
3667 +         * result on success, else null
3668 +         * @return a non-null result from applying the given search
3669 +         * function on each (key, value), or null if none
3670 +         */
3671 +        public <U> U search(BiFun<? super K, ? super V, ? extends U> searchFunction) {
3672 +            return fjp.invoke(ForkJoinTasks.search
3673 +                              (ConcurrentHashMapV8.this, searchFunction));
3674 +        }
3675 +
3676 +        /**
3677 +         * Returns the result of accumulating the given transformation
3678 +         * of all (key, value) pairs using the given reducer to
3679 +         * combine values, or null if none.
3680 +         *
3681 +         * @param transformer a function returning the transformation
3682 +         * for an element, or null of there is no transformation (in
3683 +         * which case it is not combined).
3684 +         * @param reducer a commutative associative combining function
3685 +         * @return the result of accumulating the given transformation
3686 +         * of all (key, value) pairs
3687 +         */
3688 +        public <U> U reduce(BiFun<? super K, ? super V, ? extends U> transformer,
3689 +                            BiFun<? super U, ? super U, ? extends U> reducer) {
3690 +            return fjp.invoke(ForkJoinTasks.reduce
3691 +                              (ConcurrentHashMapV8.this, transformer, reducer));
3692 +        }
3693 +
3694 +        /**
3695 +         * Returns the result of accumulating the given transformation
3696 +         * of all (key, value) pairs using the given reducer to
3697 +         * combine values, and the given basis as an identity value.
3698 +         *
3699 +         * @param transformer a function returning the transformation
3700 +         * for an element
3701 +         * @param basis the identity (initial default value) for the reduction
3702 +         * @param reducer a commutative associative combining function
3703 +         * @return the result of accumulating the given transformation
3704 +         * of all (key, value) pairs
3705 +         */
3706 +        public double reduceToDouble(ObjectByObjectToDouble<? super K, ? super V> transformer,
3707 +                                     double basis,
3708 +                                     DoubleByDoubleToDouble reducer) {
3709 +            return fjp.invoke(ForkJoinTasks.reduceToDouble
3710 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3711 +        }
3712 +
3713 +        /**
3714 +         * Returns the result of accumulating the given transformation
3715 +         * of all (key, value) pairs using the given reducer to
3716 +         * combine values, and the given basis as an identity value.
3717 +         *
3718 +         * @param transformer a function returning the transformation
3719 +         * for an element
3720 +         * @param basis the identity (initial default value) for the reduction
3721 +         * @param reducer a commutative associative combining function
3722 +         * @return the result of accumulating the given transformation
3723 +         * of all (key, value) pairs using the given reducer to
3724 +         * combine values, and the given basis as an identity value.
3725 +         */
3726 +        public long reduceToLong(ObjectByObjectToLong<? super K, ? super V> transformer,
3727 +                                 long basis,
3728 +                                 LongByLongToLong reducer) {
3729 +            return fjp.invoke(ForkJoinTasks.reduceToLong
3730 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3731 +        }
3732 +
3733 +        /**
3734 +         * Returns the result of accumulating the given transformation
3735 +         * of all (key, value) pairs using the given reducer to
3736 +         * combine values, and the given basis as an identity value.
3737 +         *
3738 +         * @param transformer a function returning the transformation
3739 +         * for an element
3740 +         * @param basis the identity (initial default value) for the reduction
3741 +         * @param reducer a commutative associative combining function
3742 +         * @return the result of accumulating the given transformation
3743 +         * of all (key, value) pairs
3744 +         */
3745 +        public int reduceToInt(ObjectByObjectToInt<? super K, ? super V> transformer,
3746 +                               int basis,
3747 +                               IntByIntToInt reducer) {
3748 +            return fjp.invoke(ForkJoinTasks.reduceToInt
3749 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3750 +        }
3751 +
3752 +        /**
3753 +         * Performs the given action for each key
3754 +         *
3755 +         * @param action the action
3756 +         */
3757 +        public void forEachKey(Action<K> action) {
3758 +            fjp.invoke(ForkJoinTasks.forEachKey
3759 +                       (ConcurrentHashMapV8.this, action));
3760 +        }
3761 +
3762 +        /**
3763 +         * Performs the given action for each non-null transformation
3764 +         * of each key
3765 +         *
3766 +         * @param transformer a function returning the transformation
3767 +         * for an element, or null of there is no transformation (in
3768 +         * which case the action is not applied).
3769 +         * @param action the action
3770 +         */
3771 +        public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
3772 +                                   Action<U> action) {
3773 +            fjp.invoke(ForkJoinTasks.forEachKey
3774 +                       (ConcurrentHashMapV8.this, transformer, action));
3775 +        }
3776 +
3777 +        /**
3778 +         * Returns a non-null result from applying the given search
3779 +         * function on each key, or null if none.  Further element
3780 +         * processing is suppressed upon success. However, this method
3781 +         * does not return until other in-progress parallel
3782 +         * invocations of the search function also complete.
3783 +         *
3784 +         * @param searchFunction a function returning a non-null
3785 +         * result on success, else null
3786 +         * @return a non-null result from applying the given search
3787 +         * function on each key, or null if none
3788 +         */
3789 +        public <U> U searchKeys(Fun<? super K, ? extends U> searchFunction) {
3790 +            return fjp.invoke(ForkJoinTasks.searchKeys
3791 +                              (ConcurrentHashMapV8.this, searchFunction));
3792 +        }
3793 +
3794 +        /**
3795 +         * Returns the result of accumulating all keys using the given
3796 +         * reducer to combine values, or null if none.
3797 +         *
3798 +         * @param reducer a commutative associative combining function
3799 +         * @return the result of accumulating all keys using the given
3800 +         * reducer to combine values, or null if none
3801 +         */
3802 +        public K reduceKeys(BiFun<? super K, ? super K, ? extends K> reducer) {
3803 +            return fjp.invoke(ForkJoinTasks.reduceKeys
3804 +                              (ConcurrentHashMapV8.this, reducer));
3805 +        }
3806 +
3807 +        /**
3808 +         * Returns the result of accumulating the given transformation
3809 +         * of all keys using the given reducer to combine values, or
3810 +         * null if none.
3811 +         *
3812 +         * @param transformer a function returning the transformation
3813 +         * for an element, or null of there is no transformation (in
3814 +         * which case it is not combined).
3815 +         * @param reducer a commutative associative combining function
3816 +         * @return the result of accumulating the given transformation
3817 +         * of all keys
3818 +         */
3819 +        public <U> U reduceKeys(Fun<? super K, ? extends U> transformer,
3820 +                                BiFun<? super U, ? super U, ? extends U> reducer) {
3821 +            return fjp.invoke(ForkJoinTasks.reduceKeys
3822 +                              (ConcurrentHashMapV8.this, transformer, reducer));
3823 +        }
3824 +
3825 +        /**
3826 +         * Returns the result of accumulating the given transformation
3827 +         * of all keys using the given reducer to combine values, and
3828 +         * the given basis as an identity value.
3829 +         *
3830 +         * @param transformer a function returning the transformation
3831 +         * for an element
3832 +         * @param basis the identity (initial default value) for the reduction
3833 +         * @param reducer a commutative associative combining function
3834 +         * @return  the result of accumulating the given transformation
3835 +         * of all keys
3836 +         */
3837 +        public double reduceKeysToDouble(ObjectToDouble<? super K> transformer,
3838 +                                         double basis,
3839 +                                         DoubleByDoubleToDouble reducer) {
3840 +            return fjp.invoke(ForkJoinTasks.reduceKeysToDouble
3841 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3842 +        }
3843 +
3844 +        /**
3845 +         * Returns the result of accumulating the given transformation
3846 +         * of all keys using the given reducer to combine values, and
3847 +         * the given basis as an identity value.
3848 +         *
3849 +         * @param transformer a function returning the transformation
3850 +         * for an element
3851 +         * @param basis the identity (initial default value) for the reduction
3852 +         * @param reducer a commutative associative combining function
3853 +         * @return the result of accumulating the given transformation
3854 +         * of all keys
3855 +         */
3856 +        public long reduceKeysToLong(ObjectToLong<? super K> transformer,
3857 +                                     long basis,
3858 +                                     LongByLongToLong reducer) {
3859 +            return fjp.invoke(ForkJoinTasks.reduceKeysToLong
3860 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3861 +        }
3862 +
3863 +        /**
3864 +         * Returns the result of accumulating the given transformation
3865 +         * of all keys using the given reducer to combine values, and
3866 +         * the given basis as an identity value.
3867 +         *
3868 +         * @param transformer a function returning the transformation
3869 +         * for an element
3870 +         * @param basis the identity (initial default value) for the reduction
3871 +         * @param reducer a commutative associative combining function
3872 +         * @return the result of accumulating the given transformation
3873 +         * of all keys
3874 +         */
3875 +        public int reduceKeysToInt(ObjectToInt<? super K> transformer,
3876 +                                   int basis,
3877 +                                   IntByIntToInt reducer) {
3878 +            return fjp.invoke(ForkJoinTasks.reduceKeysToInt
3879 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3880 +        }
3881 +
3882 +        /**
3883 +         * Performs the given action for each value
3884 +         *
3885 +         * @param action the action
3886 +         */
3887 +        public void forEachValue(Action<V> action) {
3888 +            fjp.invoke(ForkJoinTasks.forEachValue
3889 +                       (ConcurrentHashMapV8.this, action));
3890 +        }
3891 +
3892 +        /**
3893 +         * Performs the given action for each non-null transformation
3894 +         * of each value
3895 +         *
3896 +         * @param transformer a function returning the transformation
3897 +         * for an element, or null of there is no transformation (in
3898 +         * which case the action is not applied).
3899 +         */
3900 +        public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3901 +                                     Action<U> action) {
3902 +            fjp.invoke(ForkJoinTasks.forEachValue
3903 +                       (ConcurrentHashMapV8.this, transformer, action));
3904 +        }
3905 +
3906 +        /**
3907 +         * Returns a non-null result from applying the given search
3908 +         * function on each value, or null if none.  Further element
3909 +         * processing is suppressed upon success. However, this method
3910 +         * does not return until other in-progress parallel
3911 +         * invocations of the search function also complete.
3912 +         *
3913 +         * @param searchFunction a function returning a non-null
3914 +         * result on success, else null
3915 +         * @return a non-null result from applying the given search
3916 +         * function on each value, or null if none
3917 +         *
3918 +         */
3919 +        public <U> U searchValues(Fun<? super V, ? extends U> searchFunction) {
3920 +            return fjp.invoke(ForkJoinTasks.searchValues
3921 +                              (ConcurrentHashMapV8.this, searchFunction));
3922 +        }
3923 +
3924 +        /**
3925 +         * Returns the result of accumulating all values using the
3926 +         * given reducer to combine values, or null if none.
3927 +         *
3928 +         * @param reducer a commutative associative combining function
3929 +         * @return  the result of accumulating all values
3930 +         */
3931 +        public V reduceValues(BiFun<? super V, ? super V, ? extends V> reducer) {
3932 +            return fjp.invoke(ForkJoinTasks.reduceValues
3933 +                              (ConcurrentHashMapV8.this, reducer));
3934 +        }
3935 +
3936 +        /**
3937 +         * Returns the result of accumulating the given transformation
3938 +         * of all values using the given reducer to combine values, or
3939 +         * null if none.
3940 +         *
3941 +         * @param transformer a function returning the transformation
3942 +         * for an element, or null of there is no transformation (in
3943 +         * which case it is not combined).
3944 +         * @param reducer a commutative associative combining function
3945 +         * @return the result of accumulating the given transformation
3946 +         * of all values
3947 +         */
3948 +        public <U> U reduceValues(Fun<? super V, ? extends U> transformer,
3949 +                                  BiFun<? super U, ? super U, ? extends U> reducer) {
3950 +            return fjp.invoke(ForkJoinTasks.reduceValues
3951 +                              (ConcurrentHashMapV8.this, transformer, reducer));
3952 +        }
3953 +
3954 +        /**
3955 +         * Returns the result of accumulating the given transformation
3956 +         * of all values using the given reducer to combine values,
3957 +         * and the given basis as an identity value.
3958 +         *
3959 +         * @param transformer a function returning the transformation
3960 +         * for an element
3961 +         * @param basis the identity (initial default value) for the reduction
3962 +         * @param reducer a commutative associative combining function
3963 +         * @return the result of accumulating the given transformation
3964 +         * of all values
3965 +         */
3966 +        public double reduceValuesToDouble(ObjectToDouble<? super V> transformer,
3967 +                                           double basis,
3968 +                                           DoubleByDoubleToDouble reducer) {
3969 +            return fjp.invoke(ForkJoinTasks.reduceValuesToDouble
3970 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3971 +        }
3972 +
3973 +        /**
3974 +         * Returns the result of accumulating the given transformation
3975 +         * of all values using the given reducer to combine values,
3976 +         * and the given basis as an identity value.
3977 +         *
3978 +         * @param transformer a function returning the transformation
3979 +         * for an element
3980 +         * @param basis the identity (initial default value) for the reduction
3981 +         * @param reducer a commutative associative combining function
3982 +         * @return the result of accumulating the given transformation
3983 +         * of all values
3984 +         */
3985 +        public long reduceValuesToLong(ObjectToLong<? super V> transformer,
3986 +                                       long basis,
3987 +                                       LongByLongToLong reducer) {
3988 +            return fjp.invoke(ForkJoinTasks.reduceValuesToLong
3989 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
3990 +        }
3991 +
3992 +        /**
3993 +         * Returns the result of accumulating the given transformation
3994 +         * of all values using the given reducer to combine values,
3995 +         * and the given basis as an identity value.
3996 +         *
3997 +         * @param transformer a function returning the transformation
3998 +         * for an element
3999 +         * @param basis the identity (initial default value) for the reduction
4000 +         * @param reducer a commutative associative combining function
4001 +         * @return the result of accumulating the given transformation
4002 +         * of all values
4003 +         */
4004 +        public int reduceValuesToInt(ObjectToInt<? super V> transformer,
4005 +                                     int basis,
4006 +                                     IntByIntToInt reducer) {
4007 +            return fjp.invoke(ForkJoinTasks.reduceValuesToInt
4008 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4009 +        }
4010 +
4011 +        /**
4012 +         * Perform the given action for each entry
4013 +         *
4014 +         * @param action the action
4015 +         */
4016 +        public void forEachEntry(Action<Map.Entry<K,V>> action) {
4017 +            fjp.invoke(ForkJoinTasks.forEachEntry
4018 +                       (ConcurrentHashMapV8.this, action));
4019 +        }
4020 +
4021 +        /**
4022 +         * Perform the given action for each non-null transformation
4023 +         * of each entry
4024 +         *
4025 +         * @param transformer a function returning the transformation
4026 +         * for an element, or null of there is no transformation (in
4027 +         * which case the action is not applied).
4028 +         * @param action the action
4029 +         */
4030 +        public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
4031 +                                     Action<U> action) {
4032 +            fjp.invoke(ForkJoinTasks.forEachEntry
4033 +                       (ConcurrentHashMapV8.this, transformer, action));
4034 +        }
4035 +
4036 +        /**
4037 +         * Returns a non-null result from applying the given search
4038 +         * function on each entry, or null if none.  Further element
4039 +         * processing is suppressed upon success. However, this method
4040 +         * does not return until other in-progress parallel
4041 +         * invocations of the search function also complete.
4042 +         *
4043 +         * @param searchFunction a function returning a non-null
4044 +         * result on success, else null
4045 +         * @return a non-null result from applying the given search
4046 +         * function on each entry, or null if none
4047 +         */
4048 +        public <U> U searchEntries(Fun<Map.Entry<K,V>, ? extends U> searchFunction) {
4049 +            return fjp.invoke(ForkJoinTasks.searchEntries
4050 +                              (ConcurrentHashMapV8.this, searchFunction));
4051 +        }
4052 +
4053 +        /**
4054 +         * Returns the result of accumulating all entries using the
4055 +         * given reducer to combine values, or null if none.
4056 +         *
4057 +         * @param reducer a commutative associative combining function
4058 +         * @return the result of accumulating all entries
4059 +         */
4060 +        public Map.Entry<K,V> reduceEntries(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
4061 +            return fjp.invoke(ForkJoinTasks.reduceEntries
4062 +                              (ConcurrentHashMapV8.this, reducer));
4063 +        }
4064 +
4065 +        /**
4066 +         * Returns the result of accumulating the given transformation
4067 +         * of all entries using the given reducer to combine values,
4068 +         * or null if none.
4069 +         *
4070 +         * @param transformer a function returning the transformation
4071 +         * for an element, or null of there is no transformation (in
4072 +         * which case it is not combined).
4073 +         * @param reducer a commutative associative combining function
4074 +         * @return the result of accumulating the given transformation
4075 +         * of all entries
4076 +         */
4077 +        public <U> U reduceEntries(Fun<Map.Entry<K,V>, ? extends U> transformer,
4078 +                                   BiFun<? super U, ? super U, ? extends U> reducer) {
4079 +            return fjp.invoke(ForkJoinTasks.reduceEntries
4080 +                              (ConcurrentHashMapV8.this, transformer, reducer));
4081 +        }
4082 +
4083 +        /**
4084 +         * Returns the result of accumulating the given transformation
4085 +         * of all entries using the given reducer to combine values,
4086 +         * and the given basis as an identity value.
4087 +         *
4088 +         * @param transformer a function returning the transformation
4089 +         * for an element
4090 +         * @param basis the identity (initial default value) for the reduction
4091 +         * @param reducer a commutative associative combining function
4092 +         * @return the result of accumulating the given transformation
4093 +         * of all entries
4094 +         */
4095 +        public double reduceEntriesToDouble(ObjectToDouble<Map.Entry<K,V>> transformer,
4096 +                                            double basis,
4097 +                                            DoubleByDoubleToDouble reducer) {
4098 +            return fjp.invoke(ForkJoinTasks.reduceEntriesToDouble
4099 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4100 +        }
4101 +
4102 +        /**
4103 +         * Returns the result of accumulating the given transformation
4104 +         * of all entries using the given reducer to combine values,
4105 +         * and the given basis as an identity value.
4106 +         *
4107 +         * @param transformer a function returning the transformation
4108 +         * for an element
4109 +         * @param basis the identity (initial default value) for the reduction
4110 +         * @param reducer a commutative associative combining function
4111 +         * @return  the result of accumulating the given transformation
4112 +         * of all entries
4113 +         */
4114 +        public long reduceEntriesToLong(ObjectToLong<Map.Entry<K,V>> transformer,
4115 +                                        long basis,
4116 +                                        LongByLongToLong reducer) {
4117 +            return fjp.invoke(ForkJoinTasks.reduceEntriesToLong
4118 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4119 +        }
4120 +
4121 +        /**
4122 +         * Returns the result of accumulating the given transformation
4123 +         * of all entries using the given reducer to combine values,
4124 +         * and the given basis as an identity value.
4125 +         *
4126 +         * @param transformer a function returning the transformation
4127 +         * for an element
4128 +         * @param basis the identity (initial default value) for the reduction
4129 +         * @param reducer a commutative associative combining function
4130 +         * @return the result of accumulating the given transformation
4131 +         * of all entries
4132 +         */
4133 +        public int reduceEntriesToInt(ObjectToInt<Map.Entry<K,V>> transformer,
4134 +                                      int basis,
4135 +                                      IntByIntToInt reducer) {
4136 +            return fjp.invoke(ForkJoinTasks.reduceEntriesToInt
4137 +                              (ConcurrentHashMapV8.this, transformer, basis, reducer));
4138 +        }
4139 +    }
4140 +
4141 +    // ---------------------------------------------------------------------
4142 +
4143 +    /**
4144 +     * Predefined tasks for performing bulk parallel operations on
4145 +     * ConcurrentHashMaps. These tasks follow the forms and rules used
4146 +     * in class {@link Parallel}. Each method has the same name, but
4147 +     * returns a task rather than invoking it. These methods may be
4148 +     * useful in custom applications such as submitting a task without
4149 +     * waiting for completion, or combining with other tasks.
4150 +     */
4151 +    public static class ForkJoinTasks {
4152 +        private ForkJoinTasks() {}
4153 +
4154 +        /**
4155 +         * Returns a task that when invoked, performs the given
4156 +         * action for each (key, value)
4157 +         *
4158 +         * @param map the map
4159 +         * @param action the action
4160 +         * @return the task
4161 +         */
4162 +        public static <K,V> ForkJoinTask<Void> forEach
4163 +            (ConcurrentHashMapV8<K,V> map,
4164 +             BiAction<K,V> action) {
4165 +            if (action == null) throw new NullPointerException();
4166 +            return new ForEachMappingTask<K,V>(map, action);
4167 +        }
4168 +
4169 +        /**
4170 +         * Returns a task that when invoked, performs the given
4171 +         * action for each non-null transformation of each (key, value)
4172 +         *
4173 +         * @param map the map
4174 +         * @param transformer a function returning the transformation
4175 +         * for an element, or null of there is no transformation (in
4176 +         * which case the action is not applied).
4177 +         * @param action the action
4178 +         * @return the task
4179 +         */
4180 +        public static <K,V,U> ForkJoinTask<Void> forEach
4181 +            (ConcurrentHashMapV8<K,V> map,
4182 +             BiFun<? super K, ? super V, ? extends U> transformer,
4183 +             Action<U> action) {
4184 +            if (transformer == null || action == null)
4185 +                throw new NullPointerException();
4186 +            return new ForEachTransformedMappingTask<K,V,U>
4187 +                (map, transformer, action);
4188 +        }
4189 +
4190 +        /**
4191 +         * Returns a task that when invoked, returns a non-null
4192 +         * result from applying the given search function on each
4193 +         * (key, value), or null if none.  Further element processing
4194 +         * is suppressed upon success. However, this method does not
4195 +         * return until other in-progress parallel invocations of the
4196 +         * search function also complete.
4197 +         *
4198 +         * @param map the map
4199 +         * @param searchFunction a function returning a non-null
4200 +         * result on success, else null
4201 +         * @return the task
4202 +         */
4203 +        public static <K,V,U> ForkJoinTask<U> search
4204 +            (ConcurrentHashMapV8<K,V> map,
4205 +             BiFun<? super K, ? super V, ? extends U> searchFunction) {
4206 +            if (searchFunction == null) throw new NullPointerException();
4207 +            return new SearchMappingsTask<K,V,U>
4208 +                (map, searchFunction,
4209 +                 new AtomicReference<U>());
4210 +        }
4211 +
4212 +        /**
4213 +         * Returns a task that when invoked, returns the result of
4214 +         * accumulating the given transformation of all (key, value) pairs
4215 +         * using the given reducer to combine values, or null if none.
4216 +         *
4217 +         * @param map the map
4218 +         * @param transformer a function returning the transformation
4219 +         * for an element, or null of there is no transformation (in
4220 +         * which case it is not combined).
4221 +         * @param reducer a commutative associative combining function
4222 +         * @return the task
4223 +         */
4224 +        public static <K,V,U> ForkJoinTask<U> reduce
4225 +            (ConcurrentHashMapV8<K,V> map,
4226 +             BiFun<? super K, ? super V, ? extends U> transformer,
4227 +             BiFun<? super U, ? super U, ? extends U> reducer) {
4228 +            if (transformer == null || reducer == null)
4229 +                throw new NullPointerException();
4230 +            return new MapReduceMappingsTask<K,V,U>
4231 +                (map, transformer, reducer);
4232 +        }
4233 +
4234 +        /**
4235 +         * Returns a task that when invoked, returns the result of
4236 +         * accumulating the given transformation of all (key, value) pairs
4237 +         * using the given reducer to combine values, and the given
4238 +         * basis as an identity value.
4239 +         *
4240 +         * @param map the map
4241 +         * @param transformer a function returning the transformation
4242 +         * for an element
4243 +         * @param basis the identity (initial default value) for the reduction
4244 +         * @param reducer a commutative associative combining function
4245 +         * @return the task
4246 +         */
4247 +        public static <K,V> ForkJoinTask<Double> reduceToDouble
4248 +            (ConcurrentHashMapV8<K,V> map,
4249 +             ObjectByObjectToDouble<? super K, ? super V> transformer,
4250 +             double basis,
4251 +             DoubleByDoubleToDouble reducer) {
4252 +            if (transformer == null || reducer == null)
4253 +                throw new NullPointerException();
4254 +            return new MapReduceMappingsToDoubleTask<K,V>
4255 +                (map, transformer, basis, reducer);
4256 +        }
4257 +
4258 +        /**
4259 +         * Returns a task that when invoked, returns the result of
4260 +         * accumulating the given transformation of all (key, value) pairs
4261 +         * using the given reducer to combine values, and the given
4262 +         * basis as an identity value.
4263 +         *
4264 +         * @param map the map
4265 +         * @param transformer a function returning the transformation
4266 +         * for an element
4267 +         * @param basis the identity (initial default value) for the reduction
4268 +         * @param reducer a commutative associative combining function
4269 +         * @return the task
4270 +         */
4271 +        public static <K,V> ForkJoinTask<Long> reduceToLong
4272 +            (ConcurrentHashMapV8<K,V> map,
4273 +             ObjectByObjectToLong<? super K, ? super V> transformer,
4274 +             long basis,
4275 +             LongByLongToLong reducer) {
4276 +            if (transformer == null || reducer == null)
4277 +                throw new NullPointerException();
4278 +            return new MapReduceMappingsToLongTask<K,V>
4279 +                (map, transformer, basis, reducer);
4280 +        }
4281 +
4282 +        /**
4283 +         * Returns a task that when invoked, returns the result of
4284 +         * accumulating the given transformation of all (key, value) pairs
4285 +         * using the given reducer to combine values, and the given
4286 +         * basis as an identity value.
4287 +         *
4288 +         * @param transformer a function returning the transformation
4289 +         * for an element
4290 +         * @param basis the identity (initial default value) for the reduction
4291 +         * @param reducer a commutative associative combining function
4292 +         * @return the task
4293 +         */
4294 +        public static <K,V> ForkJoinTask<Integer> reduceToInt
4295 +            (ConcurrentHashMapV8<K,V> map,
4296 +             ObjectByObjectToInt<? super K, ? super V> transformer,
4297 +             int basis,
4298 +             IntByIntToInt reducer) {
4299 +            if (transformer == null || reducer == null)
4300 +                throw new NullPointerException();
4301 +            return new MapReduceMappingsToIntTask<K,V>
4302 +                (map, transformer, basis, reducer);
4303 +        }
4304 +
4305 +        /**
4306 +         * Returns a task that when invoked, performs the given action
4307 +         * for each key
4308 +         *
4309 +         * @param map the map
4310 +         * @param action the action
4311 +         * @return the task
4312 +         */
4313 +        public static <K,V> ForkJoinTask<Void> forEachKey
4314 +            (ConcurrentHashMapV8<K,V> map,
4315 +             Action<K> action) {
4316 +            if (action == null) throw new NullPointerException();
4317 +            return new ForEachKeyTask<K,V>(map, action);
4318 +        }
4319 +
4320 +        /**
4321 +         * Returns a task that when invoked, performs the given action
4322 +         * for each non-null transformation of each key
4323 +         *
4324 +         * @param map the map
4325 +         * @param transformer a function returning the transformation
4326 +         * for an element, or null of there is no transformation (in
4327 +         * which case the action is not applied).
4328 +         * @param action the action
4329 +         * @return the task
4330 +         */
4331 +        public static <K,V,U> ForkJoinTask<Void> forEachKey
4332 +            (ConcurrentHashMapV8<K,V> map,
4333 +             Fun<? super K, ? extends U> transformer,
4334 +             Action<U> action) {
4335 +            if (transformer == null || action == null)
4336 +                throw new NullPointerException();
4337 +            return new ForEachTransformedKeyTask<K,V,U>
4338 +                (map, transformer, action);
4339 +        }
4340 +
4341 +        /**
4342 +         * Returns a task that when invoked, returns a non-null result
4343 +         * from applying the given search function on each key, or
4344 +         * null if none.  Further element processing is suppressed
4345 +         * upon success. However, this method does not return until
4346 +         * other in-progress parallel invocations of the search
4347 +         * function also complete.
4348 +         *
4349 +         * @param map the map
4350 +         * @param searchFunction a function returning a non-null
4351 +         * result on success, else null
4352 +         * @return the task
4353 +         */
4354 +        public static <K,V,U> ForkJoinTask<U> searchKeys
4355 +            (ConcurrentHashMapV8<K,V> map,
4356 +             Fun<? super K, ? extends U> searchFunction) {
4357 +            if (searchFunction == null) throw new NullPointerException();
4358 +            return new SearchKeysTask<K,V,U>
4359 +                (map, searchFunction,
4360 +                 new AtomicReference<U>());
4361 +        }
4362 +
4363 +        /**
4364 +         * Returns a task that when invoked, returns the result of
4365 +         * accumulating all keys using the given reducer to combine
4366 +         * values, or null if none.
4367 +         *
4368 +         * @param map the map
4369 +         * @param reducer a commutative associative combining function
4370 +         * @return the task
4371 +         */
4372 +        public static <K,V> ForkJoinTask<K> reduceKeys
4373 +            (ConcurrentHashMapV8<K,V> map,
4374 +             BiFun<? super K, ? super K, ? extends K> reducer) {
4375 +            if (reducer == null) throw new NullPointerException();
4376 +            return new ReduceKeysTask<K,V>
4377 +                (map, reducer);
4378 +        }
4379 +        /**
4380 +         * Returns a task that when invoked, returns the result of
4381 +         * accumulating the given transformation of all keys using the given
4382 +         * reducer to combine values, or null if none.
4383 +         *
4384 +         * @param map the map
4385 +         * @param transformer a function returning the transformation
4386 +         * for an element, or null of there is no transformation (in
4387 +         * which case it is not combined).
4388 +         * @param reducer a commutative associative combining function
4389 +         * @return the task
4390 +         */
4391 +        public static <K,V,U> ForkJoinTask<U> reduceKeys
4392 +            (ConcurrentHashMapV8<K,V> map,
4393 +             Fun<? super K, ? extends U> transformer,
4394 +             BiFun<? super U, ? super U, ? extends U> reducer) {
4395 +            if (transformer == null || reducer == null)
4396 +                throw new NullPointerException();
4397 +            return new MapReduceKeysTask<K,V,U>
4398 +                (map, transformer, reducer);
4399 +        }
4400 +
4401 +        /**
4402 +         * Returns a task that when invoked, returns the result of
4403 +         * accumulating the given transformation of all keys using the given
4404 +         * reducer to combine values, and the given basis as an
4405 +         * identity value.
4406 +         *
4407 +         * @param map the map
4408 +         * @param transformer a function returning the transformation
4409 +         * for an element
4410 +         * @param basis the identity (initial default value) for the reduction
4411 +         * @param reducer a commutative associative combining function
4412 +         * @return the task
4413 +         */
4414 +        public static <K,V> ForkJoinTask<Double> reduceKeysToDouble
4415 +            (ConcurrentHashMapV8<K,V> map,
4416 +             ObjectToDouble<? super K> transformer,
4417 +             double basis,
4418 +             DoubleByDoubleToDouble reducer) {
4419 +            if (transformer == null || reducer == null)
4420 +                throw new NullPointerException();
4421 +            return new MapReduceKeysToDoubleTask<K,V>
4422 +                (map, transformer, basis, reducer);
4423 +        }
4424 +
4425 +        /**
4426 +         * Returns a task that when invoked, returns the result of
4427 +         * accumulating the given transformation of all keys using the given
4428 +         * reducer to combine values, and the given basis as an
4429 +         * identity value.
4430 +         *
4431 +         * @param map the map
4432 +         * @param transformer a function returning the transformation
4433 +         * for an element
4434 +         * @param basis the identity (initial default value) for the reduction
4435 +         * @param reducer a commutative associative combining function
4436 +         * @return the task
4437 +         */
4438 +        public static <K,V> ForkJoinTask<Long> reduceKeysToLong
4439 +            (ConcurrentHashMapV8<K,V> map,
4440 +             ObjectToLong<? super K> transformer,
4441 +             long basis,
4442 +             LongByLongToLong reducer) {
4443 +            if (transformer == null || reducer == null)
4444 +                throw new NullPointerException();
4445 +            return new MapReduceKeysToLongTask<K,V>
4446 +                (map, transformer, basis, reducer);
4447 +        }
4448 +
4449 +        /**
4450 +         * Returns a task that when invoked, returns the result of
4451 +         * accumulating the given transformation of all keys using the given
4452 +         * reducer to combine values, and the given basis as an
4453 +         * identity value.
4454 +         *
4455 +         * @param map the map
4456 +         * @param transformer a function returning the transformation
4457 +         * for an element
4458 +         * @param basis the identity (initial default value) for the reduction
4459 +         * @param reducer a commutative associative combining function
4460 +         * @return the task
4461 +         */
4462 +        public static <K,V> ForkJoinTask<Integer> reduceKeysToInt
4463 +            (ConcurrentHashMapV8<K,V> map,
4464 +             ObjectToInt<? super K> transformer,
4465 +             int basis,
4466 +             IntByIntToInt reducer) {
4467 +            if (transformer == null || reducer == null)
4468 +                throw new NullPointerException();
4469 +            return new MapReduceKeysToIntTask<K,V>
4470 +                (map, transformer, basis, reducer);
4471 +        }
4472 +
4473 +        /**
4474 +         * Returns a task that when invoked, performs the given action
4475 +         * for each value
4476 +         *
4477 +         * @param map the map
4478 +         * @param action the action
4479 +         */
4480 +        public static <K,V> ForkJoinTask<Void> forEachValue
4481 +            (ConcurrentHashMapV8<K,V> map,
4482 +             Action<V> action) {
4483 +            if (action == null) throw new NullPointerException();
4484 +            return new ForEachValueTask<K,V>(map, action);
4485 +        }
4486 +
4487 +        /**
4488 +         * Returns a task that when invoked, performs the given action
4489 +         * for each non-null transformation of each value
4490 +         *
4491 +         * @param map the map
4492 +         * @param transformer a function returning the transformation
4493 +         * for an element, or null of there is no transformation (in
4494 +         * which case the action is not applied).
4495 +         * @param action the action
4496 +         */
4497 +        public static <K,V,U> ForkJoinTask<Void> forEachValue
4498 +            (ConcurrentHashMapV8<K,V> map,
4499 +             Fun<? super V, ? extends U> transformer,
4500 +             Action<U> action) {
4501 +            if (transformer == null || action == null)
4502 +                throw new NullPointerException();
4503 +            return new ForEachTransformedValueTask<K,V,U>
4504 +                (map, transformer, action);
4505 +        }
4506 +
4507 +        /**
4508 +         * Returns a task that when invoked, returns a non-null result
4509 +         * from applying the given search function on each value, or
4510 +         * null if none.  Further element processing is suppressed
4511 +         * upon success. However, this method does not return until
4512 +         * other in-progress parallel invocations of the search
4513 +         * function also complete.
4514 +         *
4515 +         * @param map the map
4516 +         * @param searchFunction a function returning a non-null
4517 +         * result on success, else null
4518 +         * @return the task
4519 +         *
4520 +         */
4521 +        public static <K,V,U> ForkJoinTask<U> searchValues
4522 +            (ConcurrentHashMapV8<K,V> map,
4523 +             Fun<? super V, ? extends U> searchFunction) {
4524 +            if (searchFunction == null) throw new NullPointerException();
4525 +            return new SearchValuesTask<K,V,U>
4526 +                (map, searchFunction,
4527 +                 new AtomicReference<U>());
4528 +        }
4529 +
4530 +        /**
4531 +         * Returns a task that when invoked, returns the result of
4532 +         * accumulating all values using the given reducer to combine
4533 +         * values, or null if none.
4534 +         *
4535 +         * @param map the map
4536 +         * @param reducer a commutative associative combining function
4537 +         * @return the task
4538 +         */
4539 +        public static <K,V> ForkJoinTask<V> reduceValues
4540 +            (ConcurrentHashMapV8<K,V> map,
4541 +             BiFun<? super V, ? super V, ? extends V> reducer) {
4542 +            if (reducer == null) throw new NullPointerException();
4543 +            return new ReduceValuesTask<K,V>
4544 +                (map, reducer);
4545 +        }
4546 +
4547 +        /**
4548 +         * Returns a task that when invoked, returns the result of
4549 +         * accumulating the given transformation of all values using the
4550 +         * given reducer to combine values, or null if none.
4551 +         *
4552 +         * @param map the map
4553 +         * @param transformer a function returning the transformation
4554 +         * for an element, or null of there is no transformation (in
4555 +         * which case it is not combined).
4556 +         * @param reducer a commutative associative combining function
4557 +         * @return the task
4558 +         */
4559 +        public static <K,V,U> ForkJoinTask<U> reduceValues
4560 +            (ConcurrentHashMapV8<K,V> map,
4561 +             Fun<? super V, ? extends U> transformer,
4562 +             BiFun<? super U, ? super U, ? extends U> reducer) {
4563 +            if (transformer == null || reducer == null)
4564 +                throw new NullPointerException();
4565 +            return new MapReduceValuesTask<K,V,U>
4566 +                (map, transformer, reducer);
4567 +        }
4568 +
4569 +        /**
4570 +         * Returns a task that when invoked, returns the result of
4571 +         * accumulating the given transformation of all values using the
4572 +         * given reducer to combine values, and the given basis as an
4573 +         * identity value.
4574 +         *
4575 +         * @param map the map
4576 +         * @param transformer a function returning the transformation
4577 +         * for an element
4578 +         * @param basis the identity (initial default value) for the reduction
4579 +         * @param reducer a commutative associative combining function
4580 +         * @return the task
4581 +         */
4582 +        public static <K,V> ForkJoinTask<Double> reduceValuesToDouble
4583 +            (ConcurrentHashMapV8<K,V> map,
4584 +             ObjectToDouble<? super V> transformer,
4585 +             double basis,
4586 +             DoubleByDoubleToDouble reducer) {
4587 +            if (transformer == null || reducer == null)
4588 +                throw new NullPointerException();
4589 +            return new MapReduceValuesToDoubleTask<K,V>
4590 +                (map, transformer, basis, reducer);
4591 +        }
4592 +
4593 +        /**
4594 +         * Returns a task that when invoked, returns the result of
4595 +         * accumulating the given transformation of all values using the
4596 +         * given reducer to combine values, and the given basis as an
4597 +         * identity value.
4598 +         *
4599 +         * @param map the map
4600 +         * @param transformer a function returning the transformation
4601 +         * for an element
4602 +         * @param basis the identity (initial default value) for the reduction
4603 +         * @param reducer a commutative associative combining function
4604 +         * @return the task
4605 +         */
4606 +        public static <K,V> ForkJoinTask<Long> reduceValuesToLong
4607 +            (ConcurrentHashMapV8<K,V> map,
4608 +             ObjectToLong<? super V> transformer,
4609 +             long basis,
4610 +             LongByLongToLong reducer) {
4611 +            if (transformer == null || reducer == null)
4612 +                throw new NullPointerException();
4613 +            return new MapReduceValuesToLongTask<K,V>
4614 +                (map, transformer, basis, reducer);
4615 +        }
4616 +
4617 +        /**
4618 +         * Returns a task that when invoked, returns the result of
4619 +         * accumulating the given transformation of all values using the
4620 +         * given reducer to combine values, and the given basis as an
4621 +         * identity value.
4622 +         *
4623 +         * @param map the map
4624 +         * @param transformer a function returning the transformation
4625 +         * for an element
4626 +         * @param basis the identity (initial default value) for the reduction
4627 +         * @param reducer a commutative associative combining function
4628 +         * @return the task
4629 +         */
4630 +        public static <K,V> ForkJoinTask<Integer> reduceValuesToInt
4631 +            (ConcurrentHashMapV8<K,V> map,
4632 +             ObjectToInt<? super V> transformer,
4633 +             int basis,
4634 +             IntByIntToInt reducer) {
4635 +            if (transformer == null || reducer == null)
4636 +                throw new NullPointerException();
4637 +            return new MapReduceValuesToIntTask<K,V>
4638 +                (map, transformer, basis, reducer);
4639 +        }
4640 +
4641 +        /**
4642 +         * Returns a task that when invoked, perform the given action
4643 +         * for each entry
4644 +         *
4645 +         * @param map the map
4646 +         * @param action the action
4647 +         */
4648 +        public static <K,V> ForkJoinTask<Void> forEachEntry
4649 +            (ConcurrentHashMapV8<K,V> map,
4650 +             Action<Map.Entry<K,V>> action) {
4651 +            if (action == null) throw new NullPointerException();
4652 +            return new ForEachEntryTask<K,V>(map, action);
4653 +        }
4654 +
4655 +        /**
4656 +         * Returns a task that when invoked, perform the given action
4657 +         * for each non-null transformation of each entry
4658 +         *
4659 +         * @param map the map
4660 +         * @param transformer a function returning the transformation
4661 +         * for an element, or null of there is no transformation (in
4662 +         * which case the action is not applied).
4663 +         * @param action the action
4664 +         */
4665 +        public static <K,V,U> ForkJoinTask<Void> forEachEntry
4666 +            (ConcurrentHashMapV8<K,V> map,
4667 +             Fun<Map.Entry<K,V>, ? extends U> transformer,
4668 +             Action<U> action) {
4669 +            if (transformer == null || action == null)
4670 +                throw new NullPointerException();
4671 +            return new ForEachTransformedEntryTask<K,V,U>
4672 +                (map, transformer, action);
4673 +        }
4674 +
4675 +        /**
4676 +         * Returns a task that when invoked, returns a non-null result
4677 +         * from applying the given search function on each entry, or
4678 +         * null if none.  Further element processing is suppressed
4679 +         * upon success. However, this method does not return until
4680 +         * other in-progress parallel invocations of the search
4681 +         * function also complete.
4682 +         *
4683 +         * @param map the map
4684 +         * @param searchFunction a function returning a non-null
4685 +         * result on success, else null
4686 +         * @return the task
4687 +         *
4688 +         */
4689 +        public static <K,V,U> ForkJoinTask<U> searchEntries
4690 +            (ConcurrentHashMapV8<K,V> map,
4691 +             Fun<Map.Entry<K,V>, ? extends U> searchFunction) {
4692 +            if (searchFunction == null) throw new NullPointerException();
4693 +            return new SearchEntriesTask<K,V,U>
4694 +                (map, searchFunction,
4695 +                 new AtomicReference<U>());
4696 +        }
4697 +
4698 +        /**
4699 +         * Returns a task that when invoked, returns the result of
4700 +         * accumulating all entries using the given reducer to combine
4701 +         * values, or null if none.
4702 +         *
4703 +         * @param map the map
4704 +         * @param reducer a commutative associative combining function
4705 +         * @return the task
4706 +         */
4707 +        public static <K,V> ForkJoinTask<Map.Entry<K,V>> reduceEntries
4708 +            (ConcurrentHashMapV8<K,V> map,
4709 +             BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
4710 +            if (reducer == null) throw new NullPointerException();
4711 +            return new ReduceEntriesTask<K,V>
4712 +                (map, reducer);
4713 +        }
4714 +
4715 +        /**
4716 +         * Returns a task that when invoked, returns the result of
4717 +         * accumulating the given transformation of all entries using the
4718 +         * given reducer to combine values, or null if none.
4719 +         *
4720 +         * @param map the map
4721 +         * @param transformer a function returning the transformation
4722 +         * for an element, or null of there is no transformation (in
4723 +         * which case it is not combined).
4724 +         * @param reducer a commutative associative combining function
4725 +         * @return the task
4726 +         */
4727 +        public static <K,V,U> ForkJoinTask<U> reduceEntries
4728 +            (ConcurrentHashMapV8<K,V> map,
4729 +             Fun<Map.Entry<K,V>, ? extends U> transformer,
4730 +             BiFun<? super U, ? super U, ? extends U> reducer) {
4731 +            if (transformer == null || reducer == null)
4732 +                throw new NullPointerException();
4733 +            return new MapReduceEntriesTask<K,V,U>
4734 +                (map, transformer, reducer);
4735 +        }
4736 +
4737 +        /**
4738 +         * Returns a task that when invoked, returns the result of
4739 +         * accumulating the given transformation of all entries using the
4740 +         * given reducer to combine values, and the given basis as an
4741 +         * identity value.
4742 +         *
4743 +         * @param map the map
4744 +         * @param transformer a function returning the transformation
4745 +         * for an element
4746 +         * @param basis the identity (initial default value) for the reduction
4747 +         * @param reducer a commutative associative combining function
4748 +         * @return the task
4749 +         */
4750 +        public static <K,V> ForkJoinTask<Double> reduceEntriesToDouble
4751 +            (ConcurrentHashMapV8<K,V> map,
4752 +             ObjectToDouble<Map.Entry<K,V>> transformer,
4753 +             double basis,
4754 +             DoubleByDoubleToDouble reducer) {
4755 +            if (transformer == null || reducer == null)
4756 +                throw new NullPointerException();
4757 +            return new MapReduceEntriesToDoubleTask<K,V>
4758 +                (map, transformer, basis, reducer);
4759 +        }
4760 +
4761 +        /**
4762 +         * Returns a task that when invoked, returns the result of
4763 +         * accumulating the given transformation of all entries using the
4764 +         * given reducer to combine values, and the given basis as an
4765 +         * identity value.
4766 +         *
4767 +         * @param map the map
4768 +         * @param transformer a function returning the transformation
4769 +         * for an element
4770 +         * @param basis the identity (initial default value) for the reduction
4771 +         * @param reducer a commutative associative combining function
4772 +         * @return the task
4773 +         */
4774 +        public static <K,V> ForkJoinTask<Long> reduceEntriesToLong
4775 +            (ConcurrentHashMapV8<K,V> map,
4776 +             ObjectToLong<Map.Entry<K,V>> transformer,
4777 +             long basis,
4778 +             LongByLongToLong reducer) {
4779 +            if (transformer == null || reducer == null)
4780 +                throw new NullPointerException();
4781 +            return new MapReduceEntriesToLongTask<K,V>
4782 +                (map, transformer, basis, reducer);
4783 +        }
4784 +
4785 +        /**
4786 +         * Returns a task that when invoked, returns the result of
4787 +         * accumulating the given transformation of all entries using the
4788 +         * given reducer to combine values, and the given basis as an
4789 +         * identity value.
4790 +         *
4791 +         * @param map the map
4792 +         * @param transformer a function returning the transformation
4793 +         * for an element
4794 +         * @param basis the identity (initial default value) for the reduction
4795 +         * @param reducer a commutative associative combining function
4796 +         * @return the task
4797 +         */
4798 +        public static <K,V> ForkJoinTask<Integer> reduceEntriesToInt
4799 +            (ConcurrentHashMapV8<K,V> map,
4800 +             ObjectToInt<Map.Entry<K,V>> transformer,
4801 +             int basis,
4802 +             IntByIntToInt reducer) {
4803 +            if (transformer == null || reducer == null)
4804 +                throw new NullPointerException();
4805 +            return new MapReduceEntriesToIntTask<K,V>
4806 +                (map, transformer, basis, reducer);
4807 +        }
4808 +    }
4809 +
4810 +    // -------------------------------------------------------
4811 +
4812 +    /**
4813 +     * Base for FJ tasks for bulk operations. This adds a variant of
4814 +     * CountedCompleters and some split and merge bookeeping to
4815 +     * iterator functionality. The forEach and reduce methods are
4816 +     * similar to those illustrated in CountedCompleter documentation,
4817 +     * except that bottom-up reduction completions perform them within
4818 +     * their compute methods. The search methods are like forEach
4819 +     * except they continually poll for success and exit early.  Also,
4820 +     * exceptions are handled in a simpler manner, by just trying to
4821 +     * complete root task exceptionally.
4822 +     */
4823 +    static abstract class BulkTask<K,V,R> extends Traverser<K,V,R> {
4824 +        final BulkTask<K,V,?> parent;  // completion target
4825 +        int batch;                     // split control
4826 +        int pending;                   // completion control
4827 +
4828 +        /** Constructor for root tasks */
4829 +        BulkTask(ConcurrentHashMapV8<K,V> map) {
4830 +            super(map);
4831 +            this.parent = null;
4832 +            this.batch = -1; // force call to batch() on execution
4833 +        }
4834 +
4835 +        /** Constructor for subtasks */
4836 +        BulkTask(BulkTask<K,V,?> parent, int batch, boolean split) {
4837 +            super(parent, split);
4838 +            this.parent = parent;
4839 +            this.batch = batch;
4840 +        }
4841 +
4842 +        // FJ methods
4843 +
4844 +        /**
4845 +         * Propagate completion. Note that all reduce actions
4846 +         * bypass this method to combine while completing.
4847 +         */
4848 +        final void tryComplete() {
4849 +            BulkTask<K,V,?> a = this, s = a;
4850 +            for (int c;;) {
4851 +                if ((c = a.pending) == 0) {
4852 +                    if ((a = (s = a).parent) == null) {
4853 +                        s.quietlyComplete();
4854 +                        break;
4855 +                    }
4856 +                }
4857 +                else if (U.compareAndSwapInt(a, PENDING, c, c - 1))
4858 +                    break;
4859 +            }
4860 +        }
4861 +
4862 +        /**
4863 +         * Force root task to throw exception unless already complete.
4864 +         */
4865 +        final void tryAbortComputation(Throwable ex) {
4866 +            for (BulkTask<K,V,?> a = this;;) {
4867 +                BulkTask<K,V,?> p = a.parent;
4868 +                if (p == null) {
4869 +                    a.completeExceptionally(ex);
4870 +                    break;
4871 +                }
4872 +                a = p;
4873 +            }
4874 +        }
4875 +
4876 +        public final boolean exec() {
4877 +            try {
4878 +                compute();
4879 +            }
4880 +            catch(Throwable ex) {
4881 +                tryAbortComputation(ex);
4882 +            }
4883 +            return false;
4884 +        }
4885 +
4886 +        public abstract void compute();
4887 +
4888 +        // utilities
4889 +
4890 +        /** CompareAndSet pending count */
4891 +        final boolean casPending(int cmp, int val) {
4892 +            return U.compareAndSwapInt(this, PENDING, cmp, val);
4893 +        }
4894 +
4895 +        /**
4896 +         * Return approx exp2 of the number of times (minus one) to
4897 +         * split task by two before executing leaf action. This value
4898 +         * is faster to compute and more convenient to use as a guide
4899 +         * to splitting than is the depth, since it is used while
4900 +         * dividing by two anyway.
4901 +         */
4902 +        final int batch() {
4903 +            int b = batch;
4904 +            if (b < 0) {
4905 +                long n = map.counter.sum();
4906 +                int sp = getPool().getParallelism() << 3; // slack of 8
4907 +                b = batch = (n <= 0L)? 0 : (n < (long)sp) ? (int)n : sp;
4908 +            }
4909 +            return b;
4910 +        }
4911 +
4912 +        /**
4913 +         * Error message for hoisted null checks of functions
4914 +         */
4915 +        static final String NullFunctionMessage =
4916 +            "Unexpected null function";
4917 +
4918 +        /**
4919 +         * Return exportable snapshot entry
4920 +         */
4921 +        static <K,V> AbstractMap.SimpleEntry<K,V> entryFor(K k, V v) {
4922 +            return new AbstractMap.SimpleEntry(k, v);
4923 +        }
4924 +
4925 +        // Unsafe mechanics
4926 +        private static final sun.misc.Unsafe U;
4927 +        private static final long PENDING;
4928 +        static {
4929 +            try {
4930 +                U = sun.misc.Unsafe.getUnsafe();
4931 +                PENDING = U.objectFieldOffset
4932 +                    (BulkTask.class.getDeclaredField("pending"));
4933 +            } catch (Exception e) {
4934 +                throw new Error(e);
4935 +            }
4936 +        }
4937 +    }
4938 +
4939 +    /*
4940 +     * Task classes. Coded in a regular but ugly format/style to
4941 +     * simplify checks that each variant differs in the right way from
4942 +     * others.
4943 +     */
4944 +
4945 +    static final class ForEachKeyTask<K,V>
4946 +        extends BulkTask<K,V,Void> {
4947 +        final Action<K> action;
4948 +        ForEachKeyTask
4949 +            (ConcurrentHashMapV8<K,V> m,
4950 +             Action<K> action) {
4951 +            super(m);
4952 +            this.action = action;
4953 +        }
4954 +        ForEachKeyTask
4955 +            (BulkTask<K,V,?> p, int b, boolean split,
4956 +             Action<K> action) {
4957 +            super(p, b, split);
4958 +            this.action = action;
4959 +        }
4960 +        public final void compute() {
4961 +            final Action<K> action = this.action;
4962 +            if (action == null)
4963 +                throw new Error(NullFunctionMessage);
4964 +            int b = batch(), c;
4965 +            while (b > 1 && baseIndex != baseLimit) {
4966 +                do {} while (!casPending(c = pending, c+1));
4967 +                new ForEachKeyTask<K,V>(this, b >>>= 1, true, action).fork();
4968 +            }
4969 +            while (advance() != null)
4970 +                action.apply((K)nextKey);
4971 +            tryComplete();
4972 +        }
4973 +    }
4974 +
4975 +    static final class ForEachValueTask<K,V>
4976 +        extends BulkTask<K,V,Void> {
4977 +        final Action<V> action;
4978 +        ForEachValueTask
4979 +            (ConcurrentHashMapV8<K,V> m,
4980 +             Action<V> action) {
4981 +            super(m);
4982 +            this.action = action;
4983 +        }
4984 +        ForEachValueTask
4985 +            (BulkTask<K,V,?> p, int b, boolean split,
4986 +             Action<V> action) {
4987 +            super(p, b, split);
4988 +            this.action = action;
4989 +        }
4990 +        public final void compute() {
4991 +            final Action<V> action = this.action;
4992 +            if (action == null)
4993 +                throw new Error(NullFunctionMessage);
4994 +            int b = batch(), c;
4995 +            while (b > 1 && baseIndex != baseLimit) {
4996 +                do {} while (!casPending(c = pending, c+1));
4997 +                new ForEachValueTask<K,V>(this, b >>>= 1, true, action).fork();
4998 +            }
4999 +            Object v;
5000 +            while ((v = advance()) != null)
5001 +                action.apply((V)v);
5002 +            tryComplete();
5003 +        }
5004 +    }
5005 +
5006 +    static final class ForEachEntryTask<K,V>
5007 +        extends BulkTask<K,V,Void> {
5008 +        final Action<Entry<K,V>> action;
5009 +        ForEachEntryTask
5010 +            (ConcurrentHashMapV8<K,V> m,
5011 +             Action<Entry<K,V>> action) {
5012 +            super(m);
5013 +            this.action = action;
5014 +        }
5015 +        ForEachEntryTask
5016 +            (BulkTask<K,V,?> p, int b, boolean split,
5017 +             Action<Entry<K,V>> action) {
5018 +            super(p, b, split);
5019 +            this.action = action;
5020 +        }
5021 +        public final void compute() {
5022 +            final Action<Entry<K,V>> action = this.action;
5023 +            if (action == null)
5024 +                throw new Error(NullFunctionMessage);
5025 +            int b = batch(), c;
5026 +            while (b > 1 && baseIndex != baseLimit) {
5027 +                do {} while (!casPending(c = pending, c+1));
5028 +                new ForEachEntryTask<K,V>(this, b >>>= 1, true, action).fork();
5029 +            }
5030 +            Object v;
5031 +            while ((v = advance()) != null)
5032 +                action.apply(entryFor((K)nextKey, (V)v));
5033 +            tryComplete();
5034 +        }
5035 +    }
5036 +
5037 +    static final class ForEachMappingTask<K,V>
5038 +        extends BulkTask<K,V,Void> {
5039 +        final BiAction<K,V> action;
5040 +        ForEachMappingTask
5041 +            (ConcurrentHashMapV8<K,V> m,
5042 +             BiAction<K,V> action) {
5043 +            super(m);
5044 +            this.action = action;
5045 +        }
5046 +        ForEachMappingTask
5047 +            (BulkTask<K,V,?> p, int b, boolean split,
5048 +             BiAction<K,V> action) {
5049 +            super(p, b, split);
5050 +            this.action = action;
5051 +        }
5052 +
5053 +        public final void compute() {
5054 +            final BiAction<K,V> action = this.action;
5055 +            if (action == null)
5056 +                throw new Error(NullFunctionMessage);
5057 +            int b = batch(), c;
5058 +            while (b > 1 && baseIndex != baseLimit) {
5059 +                do {} while (!casPending(c = pending, c+1));
5060 +                new ForEachMappingTask<K,V>(this, b >>>= 1, true,
5061 +                                            action).fork();
5062 +            }
5063 +            Object v;
5064 +            while ((v = advance()) != null)
5065 +                action.apply((K)nextKey, (V)v);
5066 +            tryComplete();
5067 +        }
5068 +    }
5069 +
5070 +    static final class ForEachTransformedKeyTask<K,V,U>
5071 +        extends BulkTask<K,V,Void> {
5072 +        final Fun<? super K, ? extends U> transformer;
5073 +        final Action<U> action;
5074 +        ForEachTransformedKeyTask
5075 +            (ConcurrentHashMapV8<K,V> m,
5076 +             Fun<? super K, ? extends U> transformer,
5077 +             Action<U> action) {
5078 +            super(m);
5079 +            this.transformer = transformer;
5080 +            this.action = action;
5081 +
5082 +        }
5083 +        ForEachTransformedKeyTask
5084 +            (BulkTask<K,V,?> p, int b, boolean split,
5085 +             Fun<? super K, ? extends U> transformer,
5086 +             Action<U> action) {
5087 +            super(p, b, split);
5088 +            this.transformer = transformer;
5089 +            this.action = action;
5090 +        }
5091 +        public final void compute() {
5092 +            final Fun<? super K, ? extends U> transformer =
5093 +                this.transformer;
5094 +            final Action<U> action = this.action;
5095 +            if (transformer == null || action == null)
5096 +                throw new Error(NullFunctionMessage);
5097 +            int b = batch(), c;
5098 +            while (b > 1 && baseIndex != baseLimit) {
5099 +                do {} while (!casPending(c = pending, c+1));
5100 +                new ForEachTransformedKeyTask<K,V,U>
5101 +                    (this, b >>>= 1, true, transformer, action).fork();
5102 +            }
5103 +            U u;
5104 +            while (advance() != null) {
5105 +                if ((u = transformer.apply((K)nextKey)) != null)
5106 +                    action.apply(u);
5107 +            }
5108 +            tryComplete();
5109 +        }
5110 +    }
5111 +
5112 +    static final class ForEachTransformedValueTask<K,V,U>
5113 +        extends BulkTask<K,V,Void> {
5114 +        final Fun<? super V, ? extends U> transformer;
5115 +        final Action<U> action;
5116 +        ForEachTransformedValueTask
5117 +            (ConcurrentHashMapV8<K,V> m,
5118 +             Fun<? super V, ? extends U> transformer,
5119 +             Action<U> action) {
5120 +            super(m);
5121 +            this.transformer = transformer;
5122 +            this.action = action;
5123 +
5124 +        }
5125 +        ForEachTransformedValueTask
5126 +            (BulkTask<K,V,?> p, int b, boolean split,
5127 +             Fun<? super V, ? extends U> transformer,
5128 +             Action<U> action) {
5129 +            super(p, b, split);
5130 +            this.transformer = transformer;
5131 +            this.action = action;
5132 +        }
5133 +        public final void compute() {
5134 +            final Fun<? super V, ? extends U> transformer =
5135 +                this.transformer;
5136 +            final Action<U> action = this.action;
5137 +            if (transformer == null || action == null)
5138 +                throw new Error(NullFunctionMessage);
5139 +            int b = batch(), c;
5140 +            while (b > 1 && baseIndex != baseLimit) {
5141 +                do {} while (!casPending(c = pending, c+1));
5142 +                new ForEachTransformedValueTask<K,V,U>
5143 +                    (this, b >>>= 1, true, transformer, action).fork();
5144 +            }
5145 +            Object v; U u;
5146 +            while ((v = advance()) != null) {
5147 +                if ((u = transformer.apply((V)v)) != null)
5148 +                    action.apply(u);
5149 +            }
5150 +            tryComplete();
5151 +        }
5152 +    }
5153 +
5154 +    static final class ForEachTransformedEntryTask<K,V,U>
5155 +        extends BulkTask<K,V,Void> {
5156 +        final Fun<Map.Entry<K,V>, ? extends U> transformer;
5157 +        final Action<U> action;
5158 +        ForEachTransformedEntryTask
5159 +            (ConcurrentHashMapV8<K,V> m,
5160 +             Fun<Map.Entry<K,V>, ? extends U> transformer,
5161 +             Action<U> action) {
5162 +            super(m);
5163 +            this.transformer = transformer;
5164 +            this.action = action;
5165 +
5166 +        }
5167 +        ForEachTransformedEntryTask
5168 +            (BulkTask<K,V,?> p, int b, boolean split,
5169 +             Fun<Map.Entry<K,V>, ? extends U> transformer,
5170 +             Action<U> action) {
5171 +            super(p, b, split);
5172 +            this.transformer = transformer;
5173 +            this.action = action;
5174 +        }
5175 +        public final void compute() {
5176 +            final Fun<Map.Entry<K,V>, ? extends U> transformer =
5177 +                this.transformer;
5178 +            final Action<U> action = this.action;
5179 +            if (transformer == null || action == null)
5180 +                throw new Error(NullFunctionMessage);
5181 +            int b = batch(), c;
5182 +            while (b > 1 && baseIndex != baseLimit) {
5183 +                do {} while (!casPending(c = pending, c+1));
5184 +                new ForEachTransformedEntryTask<K,V,U>
5185 +                    (this, b >>>= 1, true, transformer, action).fork();
5186 +            }
5187 +            Object v; U u;
5188 +            while ((v = advance()) != null) {
5189 +                if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5190 +                    action.apply(u);
5191 +            }
5192 +            tryComplete();
5193 +        }
5194 +    }
5195 +
5196 +    static final class ForEachTransformedMappingTask<K,V,U>
5197 +        extends BulkTask<K,V,Void> {
5198 +        final BiFun<? super K, ? super V, ? extends U> transformer;
5199 +        final Action<U> action;
5200 +        ForEachTransformedMappingTask
5201 +            (ConcurrentHashMapV8<K,V> m,
5202 +             BiFun<? super K, ? super V, ? extends U> transformer,
5203 +             Action<U> action) {
5204 +            super(m);
5205 +            this.transformer = transformer;
5206 +            this.action = action;
5207 +
5208 +        }
5209 +        ForEachTransformedMappingTask
5210 +            (BulkTask<K,V,?> p, int b, boolean split,
5211 +             BiFun<? super K, ? super V, ? extends U> transformer,
5212 +             Action<U> action) {
5213 +            super(p, b, split);
5214 +            this.transformer = transformer;
5215 +            this.action = action;
5216 +        }
5217 +        public final void compute() {
5218 +            final BiFun<? super K, ? super V, ? extends U> transformer =
5219 +                this.transformer;
5220 +            final Action<U> action = this.action;
5221 +            if (transformer == null || action == null)
5222 +                throw new Error(NullFunctionMessage);
5223 +            int b = batch(), c;
5224 +            while (b > 1 && baseIndex != baseLimit) {
5225 +                do {} while (!casPending(c = pending, c+1));
5226 +                new ForEachTransformedMappingTask<K,V,U>
5227 +                    (this, b >>>= 1, true, transformer, action).fork();
5228 +            }
5229 +            Object v; U u;
5230 +            while ((v = advance()) != null) {
5231 +                if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5232 +                    action.apply(u);
5233 +            }
5234 +            tryComplete();
5235 +        }
5236 +    }
5237 +
5238 +    static final class SearchKeysTask<K,V,U>
5239 +        extends BulkTask<K,V,U> {
5240 +        final Fun<? super K, ? extends U> searchFunction;
5241 +        final AtomicReference<U> result;
5242 +        SearchKeysTask
5243 +            (ConcurrentHashMapV8<K,V> m,
5244 +             Fun<? super K, ? extends U> searchFunction,
5245 +             AtomicReference<U> result) {
5246 +            super(m);
5247 +            this.searchFunction = searchFunction; this.result = result;
5248 +        }
5249 +        SearchKeysTask
5250 +            (BulkTask<K,V,?> p, int b, boolean split,
5251 +             Fun<? super K, ? extends U> searchFunction,
5252 +             AtomicReference<U> result) {
5253 +            super(p, b, split);
5254 +            this.searchFunction = searchFunction; this.result = result;
5255 +        }
5256 +        public final void compute() {
5257 +            AtomicReference<U> result = this.result;
5258 +            final Fun<? super K, ? extends U> searchFunction =
5259 +                this.searchFunction;
5260 +            if (searchFunction == null || result == null)
5261 +                throw new Error(NullFunctionMessage);
5262 +            int b = batch(), c;
5263 +            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5264 +                do {} while (!casPending(c = pending, c+1));
5265 +                new SearchKeysTask<K,V,U>(this, b >>>= 1, true,
5266 +                                          searchFunction, result).fork();
5267 +            }
5268 +            U u;
5269 +            while (result.get() == null && advance() != null) {
5270 +                if ((u = searchFunction.apply((K)nextKey)) != null) {
5271 +                    result.compareAndSet(null, u);
5272 +                    break;
5273 +                }
5274 +            }
5275 +            tryComplete();
5276 +        }
5277 +        public final U getRawResult() { return result.get(); }
5278 +    }
5279 +
5280 +    static final class SearchValuesTask<K,V,U>
5281 +        extends BulkTask<K,V,U> {
5282 +        final Fun<? super V, ? extends U> searchFunction;
5283 +        final AtomicReference<U> result;
5284 +        SearchValuesTask
5285 +            (ConcurrentHashMapV8<K,V> m,
5286 +             Fun<? super V, ? extends U> searchFunction,
5287 +             AtomicReference<U> result) {
5288 +            super(m);
5289 +            this.searchFunction = searchFunction; this.result = result;
5290 +        }
5291 +        SearchValuesTask
5292 +            (BulkTask<K,V,?> p, int b, boolean split,
5293 +             Fun<? super V, ? extends U> searchFunction,
5294 +             AtomicReference<U> result) {
5295 +            super(p, b, split);
5296 +            this.searchFunction = searchFunction; this.result = result;
5297 +        }
5298 +        public final void compute() {
5299 +            AtomicReference<U> result = this.result;
5300 +            final Fun<? super V, ? extends U> searchFunction =
5301 +                this.searchFunction;
5302 +            if (searchFunction == null || result == null)
5303 +                throw new Error(NullFunctionMessage);
5304 +            int b = batch(), c;
5305 +            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5306 +                do {} while (!casPending(c = pending, c+1));
5307 +                new SearchValuesTask<K,V,U>(this, b >>>= 1, true,
5308 +                                            searchFunction, result).fork();
5309 +            }
5310 +            Object v; U u;
5311 +            while (result.get() == null && (v = advance()) != null) {
5312 +                if ((u = searchFunction.apply((V)v)) != null) {
5313 +                    result.compareAndSet(null, u);
5314 +                    break;
5315 +                }
5316 +            }
5317 +            tryComplete();
5318 +        }
5319 +        public final U getRawResult() { return result.get(); }
5320 +    }
5321 +
5322 +    static final class SearchEntriesTask<K,V,U>
5323 +        extends BulkTask<K,V,U> {
5324 +        final Fun<Entry<K,V>, ? extends U> searchFunction;
5325 +        final AtomicReference<U> result;
5326 +        SearchEntriesTask
5327 +            (ConcurrentHashMapV8<K,V> m,
5328 +             Fun<Entry<K,V>, ? extends U> searchFunction,
5329 +             AtomicReference<U> result) {
5330 +            super(m);
5331 +            this.searchFunction = searchFunction; this.result = result;
5332 +        }
5333 +        SearchEntriesTask
5334 +            (BulkTask<K,V,?> p, int b, boolean split,
5335 +             Fun<Entry<K,V>, ? extends U> searchFunction,
5336 +             AtomicReference<U> result) {
5337 +            super(p, b, split);
5338 +            this.searchFunction = searchFunction; this.result = result;
5339 +        }
5340 +        public final void compute() {
5341 +            AtomicReference<U> result = this.result;
5342 +            final Fun<Entry<K,V>, ? extends U> searchFunction =
5343 +                this.searchFunction;
5344 +            if (searchFunction == null || result == null)
5345 +                throw new Error(NullFunctionMessage);
5346 +            int b = batch(), c;
5347 +            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5348 +                do {} while (!casPending(c = pending, c+1));
5349 +                new SearchEntriesTask<K,V,U>(this, b >>>= 1, true,
5350 +                                             searchFunction, result).fork();
5351 +            }
5352 +            Object v; U u;
5353 +            while (result.get() == null && (v = advance()) != null) {
5354 +                if ((u = searchFunction.apply(entryFor((K)nextKey, (V)v))) != null) {
5355 +                    result.compareAndSet(null, u);
5356 +                    break;
5357 +                }
5358 +            }
5359 +            tryComplete();
5360 +        }
5361 +        public final U getRawResult() { return result.get(); }
5362 +    }
5363 +
5364 +    static final class SearchMappingsTask<K,V,U>
5365 +        extends BulkTask<K,V,U> {
5366 +        final BiFun<? super K, ? super V, ? extends U> searchFunction;
5367 +        final AtomicReference<U> result;
5368 +        SearchMappingsTask
5369 +            (ConcurrentHashMapV8<K,V> m,
5370 +             BiFun<? super K, ? super V, ? extends U> searchFunction,
5371 +             AtomicReference<U> result) {
5372 +            super(m);
5373 +            this.searchFunction = searchFunction; this.result = result;
5374 +        }
5375 +        SearchMappingsTask
5376 +            (BulkTask<K,V,?> p, int b, boolean split,
5377 +             BiFun<? super K, ? super V, ? extends U> searchFunction,
5378 +             AtomicReference<U> result) {
5379 +            super(p, b, split);
5380 +            this.searchFunction = searchFunction; this.result = result;
5381 +        }
5382 +        public final void compute() {
5383 +            AtomicReference<U> result = this.result;
5384 +            final BiFun<? super K, ? super V, ? extends U> searchFunction =
5385 +                this.searchFunction;
5386 +            if (searchFunction == null || result == null)
5387 +                throw new Error(NullFunctionMessage);
5388 +            int b = batch(), c;
5389 +            while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5390 +                do {} while (!casPending(c = pending, c+1));
5391 +                new SearchMappingsTask<K,V,U>(this, b >>>= 1, true,
5392 +                                              searchFunction, result).fork();
5393 +            }
5394 +            Object v; U u;
5395 +            while (result.get() == null && (v = advance()) != null) {
5396 +                if ((u = searchFunction.apply((K)nextKey, (V)v)) != null) {
5397 +                    result.compareAndSet(null, u);
5398 +                    break;
5399 +                }
5400 +            }
5401 +            tryComplete();
5402 +        }
5403 +        public final U getRawResult() { return result.get(); }
5404 +    }
5405 +
5406 +    static final class ReduceKeysTask<K,V>
5407 +        extends BulkTask<K,V,K> {
5408 +        final BiFun<? super K, ? super K, ? extends K> reducer;
5409 +        K result;
5410 +        ReduceKeysTask<K,V> sibling;
5411 +        ReduceKeysTask
5412 +            (ConcurrentHashMapV8<K,V> m,
5413 +             BiFun<? super K, ? super K, ? extends K> reducer) {
5414 +            super(m);
5415 +            this.reducer = reducer;
5416 +        }
5417 +        ReduceKeysTask
5418 +            (BulkTask<K,V,?> p, int b, boolean split,
5419 +             BiFun<? super K, ? super K, ? extends K> reducer) {
5420 +            super(p, b, split);
5421 +            this.reducer = reducer;
5422 +        }
5423 +
5424 +        public final void compute() {
5425 +            ReduceKeysTask<K,V> t = this;
5426 +            final BiFun<? super K, ? super K, ? extends K> reducer =
5427 +                this.reducer;
5428 +            if (reducer == null)
5429 +                throw new Error(NullFunctionMessage);
5430 +            int b = batch();
5431 +            while (b > 1 && t.baseIndex != t.baseLimit) {
5432 +                b >>>= 1;
5433 +                t.pending = 1;
5434 +                ReduceKeysTask<K,V> rt =
5435 +                    new ReduceKeysTask<K,V>
5436 +                    (t, b, true, reducer);
5437 +                t = new ReduceKeysTask<K,V>
5438 +                    (t, b, false, reducer);
5439 +                t.sibling = rt;
5440 +                rt.sibling = t;
5441 +                rt.fork();
5442 +            }
5443 +            K r = null;
5444 +            while (t.advance() != null) {
5445 +                K u = (K)t.nextKey;
5446 +                r = (r == null) ? u : reducer.apply(r, u);
5447 +            }
5448 +            t.result = r;
5449 +            for (;;) {
5450 +                int c; BulkTask<K,V,?> par; ReduceKeysTask<K,V> s, p; K u;
5451 +                if ((par = t.parent) == null ||
5452 +                    !(par instanceof ReduceKeysTask)) {
5453 +                    t.quietlyComplete();
5454 +                    break;
5455 +                }
5456 +                else if ((c = (p = (ReduceKeysTask<K,V>)par).pending) == 0) {
5457 +                    if ((s = t.sibling) != null && (u = s.result) != null)
5458 +                        r = (r == null) ? u : reducer.apply(r, u);
5459 +                    (t = p).result = r;
5460 +                }
5461 +                else if (p.casPending(c, 0))
5462 +                    break;
5463 +            }
5464 +        }
5465 +        public final K getRawResult() { return result; }
5466 +    }
5467 +
5468 +    static final class ReduceValuesTask<K,V>
5469 +        extends BulkTask<K,V,V> {
5470 +        final BiFun<? super V, ? super V, ? extends V> reducer;
5471 +        V result;
5472 +        ReduceValuesTask<K,V> sibling;
5473 +        ReduceValuesTask
5474 +            (ConcurrentHashMapV8<K,V> m,
5475 +             BiFun<? super V, ? super V, ? extends V> reducer) {
5476 +            super(m);
5477 +            this.reducer = reducer;
5478 +        }
5479 +        ReduceValuesTask
5480 +            (BulkTask<K,V,?> p, int b, boolean split,
5481 +             BiFun<? super V, ? super V, ? extends V> reducer) {
5482 +            super(p, b, split);
5483 +            this.reducer = reducer;
5484 +        }
5485 +
5486 +        public final void compute() {
5487 +            ReduceValuesTask<K,V> t = this;
5488 +            final BiFun<? super V, ? super V, ? extends V> reducer =
5489 +                this.reducer;
5490 +            if (reducer == null)
5491 +                throw new Error(NullFunctionMessage);
5492 +            int b = batch();
5493 +            while (b > 1 && t.baseIndex != t.baseLimit) {
5494 +                b >>>= 1;
5495 +                t.pending = 1;
5496 +                ReduceValuesTask<K,V> rt =
5497 +                    new ReduceValuesTask<K,V>
5498 +                    (t, b, true, reducer);
5499 +                t = new ReduceValuesTask<K,V>
5500 +                    (t, b, false, reducer);
5501 +                t.sibling = rt;
5502 +                rt.sibling = t;
5503 +                rt.fork();
5504 +            }
5505 +            V r = null;
5506 +            Object v;
5507 +            while ((v = t.advance()) != null) {
5508 +                V u = (V)v;
5509 +                r = (r == null) ? u : reducer.apply(r, u);
5510 +            }
5511 +            t.result = r;
5512 +            for (;;) {
5513 +                int c; BulkTask<K,V,?> par; ReduceValuesTask<K,V> s, p; V u;
5514 +                if ((par = t.parent) == null ||
5515 +                    !(par instanceof ReduceValuesTask)) {
5516 +                    t.quietlyComplete();
5517 +                    break;
5518 +                }
5519 +                else if ((c = (p = (ReduceValuesTask<K,V>)par).pending) == 0) {
5520 +                    if ((s = t.sibling) != null && (u = s.result) != null)
5521 +                        r = (r == null) ? u : reducer.apply(r, u);
5522 +                    (t = p).result = r;
5523 +                }
5524 +                else if (p.casPending(c, 0))
5525 +                    break;
5526 +            }
5527 +        }
5528 +        public final V getRawResult() { return result; }
5529 +    }
5530 +
5531 +    static final class ReduceEntriesTask<K,V>
5532 +        extends BulkTask<K,V,Map.Entry<K,V>> {
5533 +        final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer;
5534 +        Map.Entry<K,V> result;
5535 +        ReduceEntriesTask<K,V> sibling;
5536 +        ReduceEntriesTask
5537 +            (ConcurrentHashMapV8<K,V> m,
5538 +             BiFun<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5539 +            super(m);
5540 +            this.reducer = reducer;
5541 +        }
5542 +        ReduceEntriesTask
5543 +            (BulkTask<K,V,?> p, int b, boolean split,
5544 +             BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
5545 +            super(p, b, split);
5546 +            this.reducer = reducer;
5547 +        }
5548 +
5549 +        public final void compute() {
5550 +            ReduceEntriesTask<K,V> t = this;
5551 +            final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer =
5552 +                this.reducer;
5553 +            if (reducer == null)
5554 +                throw new Error(NullFunctionMessage);
5555 +            int b = batch();
5556 +            while (b > 1 && t.baseIndex != t.baseLimit) {
5557 +                b >>>= 1;
5558 +                t.pending = 1;
5559 +                ReduceEntriesTask<K,V> rt =
5560 +                    new ReduceEntriesTask<K,V>
5561 +                    (t, b, true, reducer);
5562 +                t = new ReduceEntriesTask<K,V>
5563 +                    (t, b, false, reducer);
5564 +                t.sibling = rt;
5565 +                rt.sibling = t;
5566 +                rt.fork();
5567 +            }
5568 +            Map.Entry<K,V> r = null;
5569 +            Object v;
5570 +            while ((v = t.advance()) != null) {
5571 +                Map.Entry<K,V> u = entryFor((K)t.nextKey, (V)v);
5572 +                r = (r == null) ? u : reducer.apply(r, u);
5573 +            }
5574 +            t.result = r;
5575 +            for (;;) {
5576 +                int c; BulkTask<K,V,?> par; ReduceEntriesTask<K,V> s, p;
5577 +                Map.Entry<K,V> u;
5578 +                if ((par = t.parent) == null ||
5579 +                    !(par instanceof ReduceEntriesTask)) {
5580 +                    t.quietlyComplete();
5581 +                    break;
5582 +                }
5583 +                else if ((c = (p = (ReduceEntriesTask<K,V>)par).pending) == 0) {
5584 +                    if ((s = t.sibling) != null && (u = s.result) != null)
5585 +                        r = (r == null) ? u : reducer.apply(r, u);
5586 +                    (t = p).result = r;
5587 +                }
5588 +                else if (p.casPending(c, 0))
5589 +                    break;
5590 +            }
5591 +        }
5592 +        public final Map.Entry<K,V> getRawResult() { return result; }
5593 +    }
5594 +
5595 +    static final class MapReduceKeysTask<K,V,U>
5596 +        extends BulkTask<K,V,U> {
5597 +        final Fun<? super K, ? extends U> transformer;
5598 +        final BiFun<? super U, ? super U, ? extends U> reducer;
5599 +        U result;
5600 +        MapReduceKeysTask<K,V,U> sibling;
5601 +        MapReduceKeysTask
5602 +            (ConcurrentHashMapV8<K,V> m,
5603 +             Fun<? super K, ? extends U> transformer,
5604 +             BiFun<? super U, ? super U, ? extends U> reducer) {
5605 +            super(m);
5606 +            this.transformer = transformer;
5607 +            this.reducer = reducer;
5608 +        }
5609 +        MapReduceKeysTask
5610 +            (BulkTask<K,V,?> p, int b, boolean split,
5611 +             Fun<? super K, ? extends U> transformer,
5612 +             BiFun<? super U, ? super U, ? extends U> reducer) {
5613 +            super(p, b, split);
5614 +            this.transformer = transformer;
5615 +            this.reducer = reducer;
5616 +        }
5617 +        public final void compute() {
5618 +            MapReduceKeysTask<K,V,U> t = this;
5619 +            final Fun<? super K, ? extends U> transformer =
5620 +                this.transformer;
5621 +            final BiFun<? super U, ? super U, ? extends U> reducer =
5622 +                this.reducer;
5623 +            if (transformer == null || reducer == null)
5624 +                throw new Error(NullFunctionMessage);
5625 +            int b = batch();
5626 +            while (b > 1 && t.baseIndex != t.baseLimit) {
5627 +                b >>>= 1;
5628 +                t.pending = 1;
5629 +                MapReduceKeysTask<K,V,U> rt =
5630 +                    new MapReduceKeysTask<K,V,U>
5631 +                    (t, b, true, transformer, reducer);
5632 +                t = new MapReduceKeysTask<K,V,U>
5633 +                    (t, b, false, transformer, reducer);
5634 +                t.sibling = rt;
5635 +                rt.sibling = t;
5636 +                rt.fork();
5637 +            }
5638 +            U r = null, u;
5639 +            while (t.advance() != null) {
5640 +                if ((u = transformer.apply((K)t.nextKey)) != null)
5641 +                    r = (r == null) ? u : reducer.apply(r, u);
5642 +            }
5643 +            t.result = r;
5644 +            for (;;) {
5645 +                int c; BulkTask<K,V,?> par; MapReduceKeysTask<K,V,U> s, p;
5646 +                if ((par = t.parent) == null ||
5647 +                    !(par instanceof MapReduceKeysTask)) {
5648 +                    t.quietlyComplete();
5649 +                    break;
5650 +                }
5651 +                else if ((c = (p = (MapReduceKeysTask<K,V,U>)par).pending) == 0) {
5652 +                    if ((s = t.sibling) != null && (u = s.result) != null)
5653 +                        r = (r == null) ? u : reducer.apply(r, u);
5654 +                    (t = p).result = r;
5655 +                }
5656 +                else if (p.casPending(c, 0))
5657 +                    break;
5658 +            }
5659 +        }
5660 +        public final U getRawResult() { return result; }
5661 +    }
5662 +
5663 +    static final class MapReduceValuesTask<K,V,U>
5664 +        extends BulkTask<K,V,U> {
5665 +        final Fun<? super V, ? extends U> transformer;
5666 +        final BiFun<? super U, ? super U, ? extends U> reducer;
5667 +        U result;
5668 +        MapReduceValuesTask<K,V,U> sibling;
5669 +        MapReduceValuesTask
5670 +            (ConcurrentHashMapV8<K,V> m,
5671 +             Fun<? super V, ? extends U> transformer,
5672 +             BiFun<? super U, ? super U, ? extends U> reducer) {
5673 +            super(m);
5674 +            this.transformer = transformer;
5675 +            this.reducer = reducer;
5676 +        }
5677 +        MapReduceValuesTask
5678 +            (BulkTask<K,V,?> p, int b, boolean split,
5679 +             Fun<? super V, ? extends U> transformer,
5680 +             BiFun<? super U, ? super U, ? extends U> reducer) {
5681 +            super(p, b, split);
5682 +            this.transformer = transformer;
5683 +            this.reducer = reducer;
5684 +        }
5685 +        public final void compute() {
5686 +            MapReduceValuesTask<K,V,U> t = this;
5687 +            final Fun<? super V, ? extends U> transformer =
5688 +                this.transformer;
5689 +            final BiFun<? super U, ? super U, ? extends U> reducer =
5690 +                this.reducer;
5691 +            if (transformer == null || reducer == null)
5692 +                throw new Error(NullFunctionMessage);
5693 +            int b = batch();
5694 +            while (b > 1 && t.baseIndex != t.baseLimit) {
5695 +                b >>>= 1;
5696 +                t.pending = 1;
5697 +                MapReduceValuesTask<K,V,U> rt =
5698 +                    new MapReduceValuesTask<K,V,U>
5699 +                    (t, b, true, transformer, reducer);
5700 +                t = new MapReduceValuesTask<K,V,U>
5701 +                    (t, b, false, transformer, reducer);
5702 +                t.sibling = rt;
5703 +                rt.sibling = t;
5704 +                rt.fork();
5705 +            }
5706 +            U r = null, u;
5707 +            Object v;
5708 +            while ((v = t.advance()) != null) {
5709 +                if ((u = transformer.apply((V)v)) != null)
5710 +                    r = (r == null) ? u : reducer.apply(r, u);
5711 +            }
5712 +            t.result = r;
5713 +            for (;;) {
5714 +                int c; BulkTask<K,V,?> par; MapReduceValuesTask<K,V,U> s, p;
5715 +                if ((par = t.parent) == null ||
5716 +                    !(par instanceof MapReduceValuesTask)) {
5717 +                    t.quietlyComplete();
5718 +                    break;
5719 +                }
5720 +                else if ((c = (p = (MapReduceValuesTask<K,V,U>)par).pending) == 0) {
5721 +                    if ((s = t.sibling) != null && (u = s.result) != null)
5722 +                        r = (r == null) ? u : reducer.apply(r, u);
5723 +                    (t = p).result = r;
5724 +                }
5725 +                else if (p.casPending(c, 0))
5726 +                    break;
5727 +            }
5728 +        }
5729 +        public final U getRawResult() { return result; }
5730 +    }
5731 +
5732 +    static final class MapReduceEntriesTask<K,V,U>
5733 +        extends BulkTask<K,V,U> {
5734 +        final Fun<Map.Entry<K,V>, ? extends U> transformer;
5735 +        final BiFun<? super U, ? super U, ? extends U> reducer;
5736 +        U result;
5737 +        MapReduceEntriesTask<K,V,U> sibling;
5738 +        MapReduceEntriesTask
5739 +            (ConcurrentHashMapV8<K,V> m,
5740 +             Fun<Map.Entry<K,V>, ? extends U> transformer,
5741 +             BiFun<? super U, ? super U, ? extends U> reducer) {
5742 +            super(m);
5743 +            this.transformer = transformer;
5744 +            this.reducer = reducer;
5745 +        }
5746 +        MapReduceEntriesTask
5747 +            (BulkTask<K,V,?> p, int b, boolean split,
5748 +             Fun<Map.Entry<K,V>, ? extends U> transformer,
5749 +             BiFun<? super U, ? super U, ? extends U> reducer) {
5750 +            super(p, b, split);
5751 +            this.transformer = transformer;
5752 +            this.reducer = reducer;
5753 +        }
5754 +        public final void compute() {
5755 +            MapReduceEntriesTask<K,V,U> t = this;
5756 +            final Fun<Map.Entry<K,V>, ? extends U> transformer =
5757 +                this.transformer;
5758 +            final BiFun<? super U, ? super U, ? extends U> reducer =
5759 +                this.reducer;
5760 +            if (transformer == null || reducer == null)
5761 +                throw new Error(NullFunctionMessage);
5762 +            int b = batch();
5763 +            while (b > 1 && t.baseIndex != t.baseLimit) {
5764 +                b >>>= 1;
5765 +                t.pending = 1;
5766 +                MapReduceEntriesTask<K,V,U> rt =
5767 +                    new MapReduceEntriesTask<K,V,U>
5768 +                    (t, b, true, transformer, reducer);
5769 +                t = new MapReduceEntriesTask<K,V,U>
5770 +                    (t, b, false, transformer, reducer);
5771 +                t.sibling = rt;
5772 +                rt.sibling = t;
5773 +                rt.fork();
5774 +            }
5775 +            U r = null, u;
5776 +            Object v;
5777 +            while ((v = t.advance()) != null) {
5778 +                if ((u = transformer.apply(entryFor((K)t.nextKey, (V)v))) != null)
5779 +                    r = (r == null) ? u : reducer.apply(r, u);
5780 +            }
5781 +            t.result = r;
5782 +            for (;;) {
5783 +                int c; BulkTask<K,V,?> par; MapReduceEntriesTask<K,V,U> s, p;
5784 +                if ((par = t.parent) == null ||
5785 +                    !(par instanceof MapReduceEntriesTask)) {
5786 +                    t.quietlyComplete();
5787 +                    break;
5788 +                }
5789 +                else if ((c = (p = (MapReduceEntriesTask<K,V,U>)par).pending) == 0) {
5790 +                    if ((s = t.sibling) != null && (u = s.result) != null)
5791 +                        r = (r == null) ? u : reducer.apply(r, u);
5792 +                    (t = p).result = r;
5793 +                }
5794 +                else if (p.casPending(c, 0))
5795 +                    break;
5796 +            }
5797 +        }
5798 +        public final U getRawResult() { return result; }
5799 +    }
5800 +
5801 +    static final class MapReduceMappingsTask<K,V,U>
5802 +        extends BulkTask<K,V,U> {
5803 +        final BiFun<? super K, ? super V, ? extends U> transformer;
5804 +        final BiFun<? super U, ? super U, ? extends U> reducer;
5805 +        U result;
5806 +        MapReduceMappingsTask<K,V,U> sibling;
5807 +        MapReduceMappingsTask
5808 +            (ConcurrentHashMapV8<K,V> m,
5809 +             BiFun<? super K, ? super V, ? extends U> transformer,
5810 +             BiFun<? super U, ? super U, ? extends U> reducer) {
5811 +            super(m);
5812 +            this.transformer = transformer;
5813 +            this.reducer = reducer;
5814 +        }
5815 +        MapReduceMappingsTask
5816 +            (BulkTask<K,V,?> p, int b, boolean split,
5817 +             BiFun<? super K, ? super V, ? extends U> transformer,
5818 +             BiFun<? super U, ? super U, ? extends U> reducer) {
5819 +            super(p, b, split);
5820 +            this.transformer = transformer;
5821 +            this.reducer = reducer;
5822 +        }
5823 +        public final void compute() {
5824 +            MapReduceMappingsTask<K,V,U> t = this;
5825 +            final BiFun<? super K, ? super V, ? extends U> transformer =
5826 +                this.transformer;
5827 +            final BiFun<? super U, ? super U, ? extends U> reducer =
5828 +                this.reducer;
5829 +            if (transformer == null || reducer == null)
5830 +                throw new Error(NullFunctionMessage);
5831 +            int b = batch();
5832 +            while (b > 1 && t.baseIndex != t.baseLimit) {
5833 +                b >>>= 1;
5834 +                t.pending = 1;
5835 +                MapReduceMappingsTask<K,V,U> rt =
5836 +                    new MapReduceMappingsTask<K,V,U>
5837 +                    (t, b, true, transformer, reducer);
5838 +                t = new MapReduceMappingsTask<K,V,U>
5839 +                    (t, b, false, transformer, reducer);
5840 +                t.sibling = rt;
5841 +                rt.sibling = t;
5842 +                rt.fork();
5843 +            }
5844 +            U r = null, u;
5845 +            Object v;
5846 +            while ((v = t.advance()) != null) {
5847 +                if ((u = transformer.apply((K)t.nextKey, (V)v)) != null)
5848 +                    r = (r == null) ? u : reducer.apply(r, u);
5849 +            }
5850 +            for (;;) {
5851 +                int c; BulkTask<K,V,?> par; MapReduceMappingsTask<K,V,U> s, p;
5852 +                if ((par = t.parent) == null ||
5853 +                    !(par instanceof MapReduceMappingsTask)) {
5854 +                    t.quietlyComplete();
5855 +                    break;
5856 +                }
5857 +                else if ((c = (p = (MapReduceMappingsTask<K,V,U>)par).pending) == 0) {
5858 +                    if ((s = t.sibling) != null && (u = s.result) != null)
5859 +                        r = (r == null) ? u : reducer.apply(r, u);
5860 +                    (t = p).result = r;
5861 +                }
5862 +                else if (p.casPending(c, 0))
5863 +                    break;
5864 +            }
5865 +        }
5866 +        public final U getRawResult() { return result; }
5867 +    }
5868 +
5869 +    static final class MapReduceKeysToDoubleTask<K,V>
5870 +        extends BulkTask<K,V,Double> {
5871 +        final ObjectToDouble<? super K> transformer;
5872 +        final DoubleByDoubleToDouble reducer;
5873 +        final double basis;
5874 +        double result;
5875 +        MapReduceKeysToDoubleTask<K,V> sibling;
5876 +        MapReduceKeysToDoubleTask
5877 +            (ConcurrentHashMapV8<K,V> m,
5878 +             ObjectToDouble<? super K> transformer,
5879 +             double basis,
5880 +             DoubleByDoubleToDouble reducer) {
5881 +            super(m);
5882 +            this.transformer = transformer;
5883 +            this.basis = basis; this.reducer = reducer;
5884 +        }
5885 +        MapReduceKeysToDoubleTask
5886 +            (BulkTask<K,V,?> p, int b, boolean split,
5887 +             ObjectToDouble<? super K> transformer,
5888 +             double basis,
5889 +             DoubleByDoubleToDouble reducer) {
5890 +            super(p, b, split);
5891 +            this.transformer = transformer;
5892 +            this.basis = basis; this.reducer = reducer;
5893 +        }
5894 +        public final void compute() {
5895 +            MapReduceKeysToDoubleTask<K,V> t = this;
5896 +            final ObjectToDouble<? super K> transformer =
5897 +                this.transformer;
5898 +            final DoubleByDoubleToDouble reducer = this.reducer;
5899 +            if (transformer == null || reducer == null)
5900 +                throw new Error(NullFunctionMessage);
5901 +            final double id = this.basis;
5902 +            int b = batch();
5903 +            while (b > 1 && t.baseIndex != t.baseLimit) {
5904 +                b >>>= 1;
5905 +                t.pending = 1;
5906 +                MapReduceKeysToDoubleTask<K,V> rt =
5907 +                    new MapReduceKeysToDoubleTask<K,V>
5908 +                    (t, b, true, transformer, id, reducer);
5909 +                t = new MapReduceKeysToDoubleTask<K,V>
5910 +                    (t, b, false, transformer, id, reducer);
5911 +                t.sibling = rt;
5912 +                rt.sibling = t;
5913 +                rt.fork();
5914 +            }
5915 +            double r = id;
5916 +            while (t.advance() != null)
5917 +                r = reducer.apply(r, transformer.apply((K)t.nextKey));
5918 +            t.result = r;
5919 +            for (;;) {
5920 +                int c; BulkTask<K,V,?> par; MapReduceKeysToDoubleTask<K,V> s, p;
5921 +                if ((par = t.parent) == null ||
5922 +                    !(par instanceof MapReduceKeysToDoubleTask)) {
5923 +                    t.quietlyComplete();
5924 +                    break;
5925 +                }
5926 +                else if ((c = (p = (MapReduceKeysToDoubleTask<K,V>)par).pending) == 0) {
5927 +                    if ((s = t.sibling) != null)
5928 +                        r = reducer.apply(r, s.result);
5929 +                    (t = p).result = r;
5930 +                }
5931 +                else if (p.casPending(c, 0))
5932 +                    break;
5933 +            }
5934 +        }
5935 +        public final Double getRawResult() { return result; }
5936 +    }
5937 +
5938 +    static final class MapReduceValuesToDoubleTask<K,V>
5939 +        extends BulkTask<K,V,Double> {
5940 +        final ObjectToDouble<? super V> transformer;
5941 +        final DoubleByDoubleToDouble reducer;
5942 +        final double basis;
5943 +        double result;
5944 +        MapReduceValuesToDoubleTask<K,V> sibling;
5945 +        MapReduceValuesToDoubleTask
5946 +            (ConcurrentHashMapV8<K,V> m,
5947 +             ObjectToDouble<? super V> transformer,
5948 +             double basis,
5949 +             DoubleByDoubleToDouble reducer) {
5950 +            super(m);
5951 +            this.transformer = transformer;
5952 +            this.basis = basis; this.reducer = reducer;
5953 +        }
5954 +        MapReduceValuesToDoubleTask
5955 +            (BulkTask<K,V,?> p, int b, boolean split,
5956 +             ObjectToDouble<? super V> transformer,
5957 +             double basis,
5958 +             DoubleByDoubleToDouble reducer) {
5959 +            super(p, b, split);
5960 +            this.transformer = transformer;
5961 +            this.basis = basis; this.reducer = reducer;
5962 +        }
5963 +        public final void compute() {
5964 +            MapReduceValuesToDoubleTask<K,V> t = this;
5965 +            final ObjectToDouble<? super V> transformer =
5966 +                this.transformer;
5967 +            final DoubleByDoubleToDouble reducer = this.reducer;
5968 +            if (transformer == null || reducer == null)
5969 +                throw new Error(NullFunctionMessage);
5970 +            final double id = this.basis;
5971 +            int b = batch();
5972 +            while (b > 1 && t.baseIndex != t.baseLimit) {
5973 +                b >>>= 1;
5974 +                t.pending = 1;
5975 +                MapReduceValuesToDoubleTask<K,V> rt =
5976 +                    new MapReduceValuesToDoubleTask<K,V>
5977 +                    (t, b, true, transformer, id, reducer);
5978 +                t = new MapReduceValuesToDoubleTask<K,V>
5979 +                    (t, b, false, transformer, id, reducer);
5980 +                t.sibling = rt;
5981 +                rt.sibling = t;
5982 +                rt.fork();
5983 +            }
5984 +            double r = id;
5985 +            Object v;
5986 +            while ((v = t.advance()) != null)
5987 +                r = reducer.apply(r, transformer.apply((V)v));
5988 +            t.result = r;
5989 +            for (;;) {
5990 +                int c; BulkTask<K,V,?> par; MapReduceValuesToDoubleTask<K,V> s, p;
5991 +                if ((par = t.parent) == null ||
5992 +                    !(par instanceof MapReduceValuesToDoubleTask)) {
5993 +                    t.quietlyComplete();
5994 +                    break;
5995 +                }
5996 +                else if ((c = (p = (MapReduceValuesToDoubleTask<K,V>)par).pending) == 0) {
5997 +                    if ((s = t.sibling) != null)
5998 +                        r = reducer.apply(r, s.result);
5999 +                    (t = p).result = r;
6000 +                }
6001 +                else if (p.casPending(c, 0))
6002 +                    break;
6003 +            }
6004 +        }
6005 +        public final Double getRawResult() { return result; }
6006 +    }
6007 +
6008 +    static final class MapReduceEntriesToDoubleTask<K,V>
6009 +        extends BulkTask<K,V,Double> {
6010 +        final ObjectToDouble<Map.Entry<K,V>> transformer;
6011 +        final DoubleByDoubleToDouble reducer;
6012 +        final double basis;
6013 +        double result;
6014 +        MapReduceEntriesToDoubleTask<K,V> sibling;
6015 +        MapReduceEntriesToDoubleTask
6016 +            (ConcurrentHashMapV8<K,V> m,
6017 +             ObjectToDouble<Map.Entry<K,V>> transformer,
6018 +             double basis,
6019 +             DoubleByDoubleToDouble reducer) {
6020 +            super(m);
6021 +            this.transformer = transformer;
6022 +            this.basis = basis; this.reducer = reducer;
6023 +        }
6024 +        MapReduceEntriesToDoubleTask
6025 +            (BulkTask<K,V,?> p, int b, boolean split,
6026 +             ObjectToDouble<Map.Entry<K,V>> transformer,
6027 +             double basis,
6028 +             DoubleByDoubleToDouble reducer) {
6029 +            super(p, b, split);
6030 +            this.transformer = transformer;
6031 +            this.basis = basis; this.reducer = reducer;
6032 +        }
6033 +        public final void compute() {
6034 +            MapReduceEntriesToDoubleTask<K,V> t = this;
6035 +            final ObjectToDouble<Map.Entry<K,V>> transformer =
6036 +                this.transformer;
6037 +            final DoubleByDoubleToDouble reducer = this.reducer;
6038 +            if (transformer == null || reducer == null)
6039 +                throw new Error(NullFunctionMessage);
6040 +            final double id = this.basis;
6041 +            int b = batch();
6042 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6043 +                b >>>= 1;
6044 +                t.pending = 1;
6045 +                MapReduceEntriesToDoubleTask<K,V> rt =
6046 +                    new MapReduceEntriesToDoubleTask<K,V>
6047 +                    (t, b, true, transformer, id, reducer);
6048 +                t = new MapReduceEntriesToDoubleTask<K,V>
6049 +                    (t, b, false, transformer, id, reducer);
6050 +                t.sibling = rt;
6051 +                rt.sibling = t;
6052 +                rt.fork();
6053 +            }
6054 +            double r = id;
6055 +            Object v;
6056 +            while ((v = t.advance()) != null)
6057 +                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6058 +            t.result = r;
6059 +            for (;;) {
6060 +                int c; BulkTask<K,V,?> par; MapReduceEntriesToDoubleTask<K,V> s, p;
6061 +                if ((par = t.parent) == null ||
6062 +                    !(par instanceof MapReduceEntriesToDoubleTask)) {
6063 +                    t.quietlyComplete();
6064 +                    break;
6065 +                }
6066 +                else if ((c = (p = (MapReduceEntriesToDoubleTask<K,V>)par).pending) == 0) {
6067 +                    if ((s = t.sibling) != null)
6068 +                        r = reducer.apply(r, s.result);
6069 +                    (t = p).result = r;
6070 +                }
6071 +                else if (p.casPending(c, 0))
6072 +                    break;
6073 +            }
6074 +        }
6075 +        public final Double getRawResult() { return result; }
6076 +    }
6077 +
6078 +    static final class MapReduceMappingsToDoubleTask<K,V>
6079 +        extends BulkTask<K,V,Double> {
6080 +        final ObjectByObjectToDouble<? super K, ? super V> transformer;
6081 +        final DoubleByDoubleToDouble reducer;
6082 +        final double basis;
6083 +        double result;
6084 +        MapReduceMappingsToDoubleTask<K,V> sibling;
6085 +        MapReduceMappingsToDoubleTask
6086 +            (ConcurrentHashMapV8<K,V> m,
6087 +             ObjectByObjectToDouble<? super K, ? super V> transformer,
6088 +             double basis,
6089 +             DoubleByDoubleToDouble reducer) {
6090 +            super(m);
6091 +            this.transformer = transformer;
6092 +            this.basis = basis; this.reducer = reducer;
6093 +        }
6094 +        MapReduceMappingsToDoubleTask
6095 +            (BulkTask<K,V,?> p, int b, boolean split,
6096 +             ObjectByObjectToDouble<? super K, ? super V> transformer,
6097 +             double basis,
6098 +             DoubleByDoubleToDouble reducer) {
6099 +            super(p, b, split);
6100 +            this.transformer = transformer;
6101 +            this.basis = basis; this.reducer = reducer;
6102 +        }
6103 +        public final void compute() {
6104 +            MapReduceMappingsToDoubleTask<K,V> t = this;
6105 +            final ObjectByObjectToDouble<? super K, ? super V> transformer =
6106 +                this.transformer;
6107 +            final DoubleByDoubleToDouble reducer = this.reducer;
6108 +            if (transformer == null || reducer == null)
6109 +                throw new Error(NullFunctionMessage);
6110 +            final double id = this.basis;
6111 +            int b = batch();
6112 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6113 +                b >>>= 1;
6114 +                t.pending = 1;
6115 +                MapReduceMappingsToDoubleTask<K,V> rt =
6116 +                    new MapReduceMappingsToDoubleTask<K,V>
6117 +                    (t, b, true, transformer, id, reducer);
6118 +                t = new MapReduceMappingsToDoubleTask<K,V>
6119 +                    (t, b, false, transformer, id, reducer);
6120 +                t.sibling = rt;
6121 +                rt.sibling = t;
6122 +                rt.fork();
6123 +            }
6124 +            double r = id;
6125 +            Object v;
6126 +            while ((v = t.advance()) != null)
6127 +                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6128 +            t.result = r;
6129 +            for (;;) {
6130 +                int c; BulkTask<K,V,?> par; MapReduceMappingsToDoubleTask<K,V> s, p;
6131 +                if ((par = t.parent) == null ||
6132 +                    !(par instanceof MapReduceMappingsToDoubleTask)) {
6133 +                    t.quietlyComplete();
6134 +                    break;
6135 +                }
6136 +                else if ((c = (p = (MapReduceMappingsToDoubleTask<K,V>)par).pending) == 0) {
6137 +                    if ((s = t.sibling) != null)
6138 +                        r = reducer.apply(r, s.result);
6139 +                    (t = p).result = r;
6140 +                }
6141 +                else if (p.casPending(c, 0))
6142 +                    break;
6143 +            }
6144 +        }
6145 +        public final Double getRawResult() { return result; }
6146 +    }
6147 +
6148 +    static final class MapReduceKeysToLongTask<K,V>
6149 +        extends BulkTask<K,V,Long> {
6150 +        final ObjectToLong<? super K> transformer;
6151 +        final LongByLongToLong reducer;
6152 +        final long basis;
6153 +        long result;
6154 +        MapReduceKeysToLongTask<K,V> sibling;
6155 +        MapReduceKeysToLongTask
6156 +            (ConcurrentHashMapV8<K,V> m,
6157 +             ObjectToLong<? super K> transformer,
6158 +             long basis,
6159 +             LongByLongToLong reducer) {
6160 +            super(m);
6161 +            this.transformer = transformer;
6162 +            this.basis = basis; this.reducer = reducer;
6163 +        }
6164 +        MapReduceKeysToLongTask
6165 +            (BulkTask<K,V,?> p, int b, boolean split,
6166 +             ObjectToLong<? super K> transformer,
6167 +             long basis,
6168 +             LongByLongToLong reducer) {
6169 +            super(p, b, split);
6170 +            this.transformer = transformer;
6171 +            this.basis = basis; this.reducer = reducer;
6172 +        }
6173 +        public final void compute() {
6174 +            MapReduceKeysToLongTask<K,V> t = this;
6175 +            final ObjectToLong<? super K> transformer =
6176 +                this.transformer;
6177 +            final LongByLongToLong reducer = this.reducer;
6178 +            if (transformer == null || reducer == null)
6179 +                throw new Error(NullFunctionMessage);
6180 +            final long id = this.basis;
6181 +            int b = batch();
6182 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6183 +                b >>>= 1;
6184 +                t.pending = 1;
6185 +                MapReduceKeysToLongTask<K,V> rt =
6186 +                    new MapReduceKeysToLongTask<K,V>
6187 +                    (t, b, true, transformer, id, reducer);
6188 +                t = new MapReduceKeysToLongTask<K,V>
6189 +                    (t, b, false, transformer, id, reducer);
6190 +                t.sibling = rt;
6191 +                rt.sibling = t;
6192 +                rt.fork();
6193 +            }
6194 +            long r = id;
6195 +            while (t.advance() != null)
6196 +                r = reducer.apply(r, transformer.apply((K)t.nextKey));
6197 +            t.result = r;
6198 +            for (;;) {
6199 +                int c; BulkTask<K,V,?> par; MapReduceKeysToLongTask<K,V> s, p;
6200 +                if ((par = t.parent) == null ||
6201 +                    !(par instanceof MapReduceKeysToLongTask)) {
6202 +                    t.quietlyComplete();
6203 +                    break;
6204 +                }
6205 +                else if ((c = (p = (MapReduceKeysToLongTask<K,V>)par).pending) == 0) {
6206 +                    if ((s = t.sibling) != null)
6207 +                        r = reducer.apply(r, s.result);
6208 +                    (t = p).result = r;
6209 +                }
6210 +                else if (p.casPending(c, 0))
6211 +                    break;
6212 +            }
6213 +        }
6214 +        public final Long getRawResult() { return result; }
6215 +    }
6216 +
6217 +    static final class MapReduceValuesToLongTask<K,V>
6218 +        extends BulkTask<K,V,Long> {
6219 +        final ObjectToLong<? super V> transformer;
6220 +        final LongByLongToLong reducer;
6221 +        final long basis;
6222 +        long result;
6223 +        MapReduceValuesToLongTask<K,V> sibling;
6224 +        MapReduceValuesToLongTask
6225 +            (ConcurrentHashMapV8<K,V> m,
6226 +             ObjectToLong<? super V> transformer,
6227 +             long basis,
6228 +             LongByLongToLong reducer) {
6229 +            super(m);
6230 +            this.transformer = transformer;
6231 +            this.basis = basis; this.reducer = reducer;
6232 +        }
6233 +        MapReduceValuesToLongTask
6234 +            (BulkTask<K,V,?> p, int b, boolean split,
6235 +             ObjectToLong<? super V> transformer,
6236 +             long basis,
6237 +             LongByLongToLong reducer) {
6238 +            super(p, b, split);
6239 +            this.transformer = transformer;
6240 +            this.basis = basis; this.reducer = reducer;
6241 +        }
6242 +        public final void compute() {
6243 +            MapReduceValuesToLongTask<K,V> t = this;
6244 +            final ObjectToLong<? super V> transformer =
6245 +                this.transformer;
6246 +            final LongByLongToLong reducer = this.reducer;
6247 +            if (transformer == null || reducer == null)
6248 +                throw new Error(NullFunctionMessage);
6249 +            final long id = this.basis;
6250 +            int b = batch();
6251 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6252 +                b >>>= 1;
6253 +                t.pending = 1;
6254 +                MapReduceValuesToLongTask<K,V> rt =
6255 +                    new MapReduceValuesToLongTask<K,V>
6256 +                    (t, b, true, transformer, id, reducer);
6257 +                t = new MapReduceValuesToLongTask<K,V>
6258 +                    (t, b, false, transformer, id, reducer);
6259 +                t.sibling = rt;
6260 +                rt.sibling = t;
6261 +                rt.fork();
6262 +            }
6263 +            long r = id;
6264 +            Object v;
6265 +            while ((v = t.advance()) != null)
6266 +                r = reducer.apply(r, transformer.apply((V)v));
6267 +            t.result = r;
6268 +            for (;;) {
6269 +                int c; BulkTask<K,V,?> par; MapReduceValuesToLongTask<K,V> s, p;
6270 +                if ((par = t.parent) == null ||
6271 +                    !(par instanceof MapReduceValuesToLongTask)) {
6272 +                    t.quietlyComplete();
6273 +                    break;
6274 +                }
6275 +                else if ((c = (p = (MapReduceValuesToLongTask<K,V>)par).pending) == 0) {
6276 +                    if ((s = t.sibling) != null)
6277 +                        r = reducer.apply(r, s.result);
6278 +                    (t = p).result = r;
6279 +                }
6280 +                else if (p.casPending(c, 0))
6281 +                    break;
6282 +            }
6283 +        }
6284 +        public final Long getRawResult() { return result; }
6285 +    }
6286 +
6287 +    static final class MapReduceEntriesToLongTask<K,V>
6288 +        extends BulkTask<K,V,Long> {
6289 +        final ObjectToLong<Map.Entry<K,V>> transformer;
6290 +        final LongByLongToLong reducer;
6291 +        final long basis;
6292 +        long result;
6293 +        MapReduceEntriesToLongTask<K,V> sibling;
6294 +        MapReduceEntriesToLongTask
6295 +            (ConcurrentHashMapV8<K,V> m,
6296 +             ObjectToLong<Map.Entry<K,V>> transformer,
6297 +             long basis,
6298 +             LongByLongToLong reducer) {
6299 +            super(m);
6300 +            this.transformer = transformer;
6301 +            this.basis = basis; this.reducer = reducer;
6302 +        }
6303 +        MapReduceEntriesToLongTask
6304 +            (BulkTask<K,V,?> p, int b, boolean split,
6305 +             ObjectToLong<Map.Entry<K,V>> transformer,
6306 +             long basis,
6307 +             LongByLongToLong reducer) {
6308 +            super(p, b, split);
6309 +            this.transformer = transformer;
6310 +            this.basis = basis; this.reducer = reducer;
6311 +        }
6312 +        public final void compute() {
6313 +            MapReduceEntriesToLongTask<K,V> t = this;
6314 +            final ObjectToLong<Map.Entry<K,V>> transformer =
6315 +                this.transformer;
6316 +            final LongByLongToLong reducer = this.reducer;
6317 +            if (transformer == null || reducer == null)
6318 +                throw new Error(NullFunctionMessage);
6319 +            final long id = this.basis;
6320 +            int b = batch();
6321 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6322 +                b >>>= 1;
6323 +                t.pending = 1;
6324 +                MapReduceEntriesToLongTask<K,V> rt =
6325 +                    new MapReduceEntriesToLongTask<K,V>
6326 +                    (t, b, true, transformer, id, reducer);
6327 +                t = new MapReduceEntriesToLongTask<K,V>
6328 +                    (t, b, false, transformer, id, reducer);
6329 +                t.sibling = rt;
6330 +                rt.sibling = t;
6331 +                rt.fork();
6332 +            }
6333 +            long r = id;
6334 +            Object v;
6335 +            while ((v = t.advance()) != null)
6336 +                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6337 +            t.result = r;
6338 +            for (;;) {
6339 +                int c; BulkTask<K,V,?> par; MapReduceEntriesToLongTask<K,V> s, p;
6340 +                if ((par = t.parent) == null ||
6341 +                    !(par instanceof MapReduceEntriesToLongTask)) {
6342 +                    t.quietlyComplete();
6343 +                    break;
6344 +                }
6345 +                else if ((c = (p = (MapReduceEntriesToLongTask<K,V>)par).pending) == 0) {
6346 +                    if ((s = t.sibling) != null)
6347 +                        r = reducer.apply(r, s.result);
6348 +                    (t = p).result = r;
6349 +                }
6350 +                else if (p.casPending(c, 0))
6351 +                    break;
6352 +            }
6353 +        }
6354 +        public final Long getRawResult() { return result; }
6355 +    }
6356 +
6357 +    static final class MapReduceMappingsToLongTask<K,V>
6358 +        extends BulkTask<K,V,Long> {
6359 +        final ObjectByObjectToLong<? super K, ? super V> transformer;
6360 +        final LongByLongToLong reducer;
6361 +        final long basis;
6362 +        long result;
6363 +        MapReduceMappingsToLongTask<K,V> sibling;
6364 +        MapReduceMappingsToLongTask
6365 +            (ConcurrentHashMapV8<K,V> m,
6366 +             ObjectByObjectToLong<? super K, ? super V> transformer,
6367 +             long basis,
6368 +             LongByLongToLong reducer) {
6369 +            super(m);
6370 +            this.transformer = transformer;
6371 +            this.basis = basis; this.reducer = reducer;
6372 +        }
6373 +        MapReduceMappingsToLongTask
6374 +            (BulkTask<K,V,?> p, int b, boolean split,
6375 +             ObjectByObjectToLong<? super K, ? super V> transformer,
6376 +             long basis,
6377 +             LongByLongToLong reducer) {
6378 +            super(p, b, split);
6379 +            this.transformer = transformer;
6380 +            this.basis = basis; this.reducer = reducer;
6381 +        }
6382 +        public final void compute() {
6383 +            MapReduceMappingsToLongTask<K,V> t = this;
6384 +            final ObjectByObjectToLong<? super K, ? super V> transformer =
6385 +                this.transformer;
6386 +            final LongByLongToLong reducer = this.reducer;
6387 +            if (transformer == null || reducer == null)
6388 +                throw new Error(NullFunctionMessage);
6389 +            final long id = this.basis;
6390 +            int b = batch();
6391 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6392 +                b >>>= 1;
6393 +                t.pending = 1;
6394 +                MapReduceMappingsToLongTask<K,V> rt =
6395 +                    new MapReduceMappingsToLongTask<K,V>
6396 +                    (t, b, true, transformer, id, reducer);
6397 +                t = new MapReduceMappingsToLongTask<K,V>
6398 +                    (t, b, false, transformer, id, reducer);
6399 +                t.sibling = rt;
6400 +                rt.sibling = t;
6401 +                rt.fork();
6402 +            }
6403 +            long r = id;
6404 +            Object v;
6405 +            while ((v = t.advance()) != null)
6406 +                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6407 +            t.result = r;
6408 +            for (;;) {
6409 +                int c; BulkTask<K,V,?> par; MapReduceMappingsToLongTask<K,V> s, p;
6410 +                if ((par = t.parent) == null ||
6411 +                    !(par instanceof MapReduceMappingsToLongTask)) {
6412 +                    t.quietlyComplete();
6413 +                    break;
6414 +                }
6415 +                else if ((c = (p = (MapReduceMappingsToLongTask<K,V>)par).pending) == 0) {
6416 +                    if ((s = t.sibling) != null)
6417 +                        r = reducer.apply(r, s.result);
6418 +                    (t = p).result = r;
6419 +                }
6420 +                else if (p.casPending(c, 0))
6421 +                    break;
6422 +            }
6423 +        }
6424 +        public final Long getRawResult() { return result; }
6425 +    }
6426 +
6427 +    static final class MapReduceKeysToIntTask<K,V>
6428 +        extends BulkTask<K,V,Integer> {
6429 +        final ObjectToInt<? super K> transformer;
6430 +        final IntByIntToInt reducer;
6431 +        final int basis;
6432 +        int result;
6433 +        MapReduceKeysToIntTask<K,V> sibling;
6434 +        MapReduceKeysToIntTask
6435 +            (ConcurrentHashMapV8<K,V> m,
6436 +             ObjectToInt<? super K> transformer,
6437 +             int basis,
6438 +             IntByIntToInt reducer) {
6439 +            super(m);
6440 +            this.transformer = transformer;
6441 +            this.basis = basis; this.reducer = reducer;
6442 +        }
6443 +        MapReduceKeysToIntTask
6444 +            (BulkTask<K,V,?> p, int b, boolean split,
6445 +             ObjectToInt<? super K> transformer,
6446 +             int basis,
6447 +             IntByIntToInt reducer) {
6448 +            super(p, b, split);
6449 +            this.transformer = transformer;
6450 +            this.basis = basis; this.reducer = reducer;
6451 +        }
6452 +        public final void compute() {
6453 +            MapReduceKeysToIntTask<K,V> t = this;
6454 +            final ObjectToInt<? super K> transformer =
6455 +                this.transformer;
6456 +            final IntByIntToInt reducer = this.reducer;
6457 +            if (transformer == null || reducer == null)
6458 +                throw new Error(NullFunctionMessage);
6459 +            final int id = this.basis;
6460 +            int b = batch();
6461 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6462 +                b >>>= 1;
6463 +                t.pending = 1;
6464 +                MapReduceKeysToIntTask<K,V> rt =
6465 +                    new MapReduceKeysToIntTask<K,V>
6466 +                    (t, b, true, transformer, id, reducer);
6467 +                t = new MapReduceKeysToIntTask<K,V>
6468 +                    (t, b, false, transformer, id, reducer);
6469 +                t.sibling = rt;
6470 +                rt.sibling = t;
6471 +                rt.fork();
6472 +            }
6473 +            int r = id;
6474 +            while (t.advance() != null)
6475 +                r = reducer.apply(r, transformer.apply((K)t.nextKey));
6476 +            t.result = r;
6477 +            for (;;) {
6478 +                int c; BulkTask<K,V,?> par; MapReduceKeysToIntTask<K,V> s, p;
6479 +                if ((par = t.parent) == null ||
6480 +                    !(par instanceof MapReduceKeysToIntTask)) {
6481 +                    t.quietlyComplete();
6482 +                    break;
6483 +                }
6484 +                else if ((c = (p = (MapReduceKeysToIntTask<K,V>)par).pending) == 0) {
6485 +                    if ((s = t.sibling) != null)
6486 +                        r = reducer.apply(r, s.result);
6487 +                    (t = p).result = r;
6488 +                }
6489 +                else if (p.casPending(c, 0))
6490 +                    break;
6491 +            }
6492 +        }
6493 +        public final Integer getRawResult() { return result; }
6494 +    }
6495 +
6496 +    static final class MapReduceValuesToIntTask<K,V>
6497 +        extends BulkTask<K,V,Integer> {
6498 +        final ObjectToInt<? super V> transformer;
6499 +        final IntByIntToInt reducer;
6500 +        final int basis;
6501 +        int result;
6502 +        MapReduceValuesToIntTask<K,V> sibling;
6503 +        MapReduceValuesToIntTask
6504 +            (ConcurrentHashMapV8<K,V> m,
6505 +             ObjectToInt<? super V> transformer,
6506 +             int basis,
6507 +             IntByIntToInt reducer) {
6508 +            super(m);
6509 +            this.transformer = transformer;
6510 +            this.basis = basis; this.reducer = reducer;
6511 +        }
6512 +        MapReduceValuesToIntTask
6513 +            (BulkTask<K,V,?> p, int b, boolean split,
6514 +             ObjectToInt<? super V> transformer,
6515 +             int basis,
6516 +             IntByIntToInt reducer) {
6517 +            super(p, b, split);
6518 +            this.transformer = transformer;
6519 +            this.basis = basis; this.reducer = reducer;
6520 +        }
6521 +        public final void compute() {
6522 +            MapReduceValuesToIntTask<K,V> t = this;
6523 +            final ObjectToInt<? super V> transformer =
6524 +                this.transformer;
6525 +            final IntByIntToInt reducer = this.reducer;
6526 +            if (transformer == null || reducer == null)
6527 +                throw new Error(NullFunctionMessage);
6528 +            final int id = this.basis;
6529 +            int b = batch();
6530 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6531 +                b >>>= 1;
6532 +                t.pending = 1;
6533 +                MapReduceValuesToIntTask<K,V> rt =
6534 +                    new MapReduceValuesToIntTask<K,V>
6535 +                    (t, b, true, transformer, id, reducer);
6536 +                t = new MapReduceValuesToIntTask<K,V>
6537 +                    (t, b, false, transformer, id, reducer);
6538 +                t.sibling = rt;
6539 +                rt.sibling = t;
6540 +                rt.fork();
6541 +            }
6542 +            int r = id;
6543 +            Object v;
6544 +            while ((v = t.advance()) != null)
6545 +                r = reducer.apply(r, transformer.apply((V)v));
6546 +            t.result = r;
6547 +            for (;;) {
6548 +                int c; BulkTask<K,V,?> par; MapReduceValuesToIntTask<K,V> s, p;
6549 +                if ((par = t.parent) == null ||
6550 +                    !(par instanceof MapReduceValuesToIntTask)) {
6551 +                    t.quietlyComplete();
6552 +                    break;
6553 +                }
6554 +                else if ((c = (p = (MapReduceValuesToIntTask<K,V>)par).pending) == 0) {
6555 +                    if ((s = t.sibling) != null)
6556 +                        r = reducer.apply(r, s.result);
6557 +                    (t = p).result = r;
6558 +                }
6559 +                else if (p.casPending(c, 0))
6560 +                    break;
6561 +            }
6562 +        }
6563 +        public final Integer getRawResult() { return result; }
6564 +    }
6565 +
6566 +    static final class MapReduceEntriesToIntTask<K,V>
6567 +        extends BulkTask<K,V,Integer> {
6568 +        final ObjectToInt<Map.Entry<K,V>> transformer;
6569 +        final IntByIntToInt reducer;
6570 +        final int basis;
6571 +        int result;
6572 +        MapReduceEntriesToIntTask<K,V> sibling;
6573 +        MapReduceEntriesToIntTask
6574 +            (ConcurrentHashMapV8<K,V> m,
6575 +             ObjectToInt<Map.Entry<K,V>> transformer,
6576 +             int basis,
6577 +             IntByIntToInt reducer) {
6578 +            super(m);
6579 +            this.transformer = transformer;
6580 +            this.basis = basis; this.reducer = reducer;
6581 +        }
6582 +        MapReduceEntriesToIntTask
6583 +            (BulkTask<K,V,?> p, int b, boolean split,
6584 +             ObjectToInt<Map.Entry<K,V>> transformer,
6585 +             int basis,
6586 +             IntByIntToInt reducer) {
6587 +            super(p, b, split);
6588 +            this.transformer = transformer;
6589 +            this.basis = basis; this.reducer = reducer;
6590 +        }
6591 +        public final void compute() {
6592 +            MapReduceEntriesToIntTask<K,V> t = this;
6593 +            final ObjectToInt<Map.Entry<K,V>> transformer =
6594 +                this.transformer;
6595 +            final IntByIntToInt reducer = this.reducer;
6596 +            if (transformer == null || reducer == null)
6597 +                throw new Error(NullFunctionMessage);
6598 +            final int id = this.basis;
6599 +            int b = batch();
6600 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6601 +                b >>>= 1;
6602 +                t.pending = 1;
6603 +                MapReduceEntriesToIntTask<K,V> rt =
6604 +                    new MapReduceEntriesToIntTask<K,V>
6605 +                    (t, b, true, transformer, id, reducer);
6606 +                t = new MapReduceEntriesToIntTask<K,V>
6607 +                    (t, b, false, transformer, id, reducer);
6608 +                t.sibling = rt;
6609 +                rt.sibling = t;
6610 +                rt.fork();
6611 +            }
6612 +            int r = id;
6613 +            Object v;
6614 +            while ((v = t.advance()) != null)
6615 +                r = reducer.apply(r, transformer.apply(entryFor((K)t.nextKey, (V)v)));
6616 +            t.result = r;
6617 +            for (;;) {
6618 +                int c; BulkTask<K,V,?> par; MapReduceEntriesToIntTask<K,V> s, p;
6619 +                if ((par = t.parent) == null ||
6620 +                    !(par instanceof MapReduceEntriesToIntTask)) {
6621 +                    t.quietlyComplete();
6622 +                    break;
6623 +                }
6624 +                else if ((c = (p = (MapReduceEntriesToIntTask<K,V>)par).pending) == 0) {
6625 +                    if ((s = t.sibling) != null)
6626 +                        r = reducer.apply(r, s.result);
6627 +                    (t = p).result = r;
6628 +                }
6629 +                else if (p.casPending(c, 0))
6630 +                    break;
6631 +            }
6632 +        }
6633 +        public final Integer getRawResult() { return result; }
6634 +    }
6635 +
6636 +    static final class MapReduceMappingsToIntTask<K,V>
6637 +        extends BulkTask<K,V,Integer> {
6638 +        final ObjectByObjectToInt<? super K, ? super V> transformer;
6639 +        final IntByIntToInt reducer;
6640 +        final int basis;
6641 +        int result;
6642 +        MapReduceMappingsToIntTask<K,V> sibling;
6643 +        MapReduceMappingsToIntTask
6644 +            (ConcurrentHashMapV8<K,V> m,
6645 +             ObjectByObjectToInt<? super K, ? super V> transformer,
6646 +             int basis,
6647 +             IntByIntToInt reducer) {
6648 +            super(m);
6649 +            this.transformer = transformer;
6650 +            this.basis = basis; this.reducer = reducer;
6651 +        }
6652 +        MapReduceMappingsToIntTask
6653 +            (BulkTask<K,V,?> p, int b, boolean split,
6654 +             ObjectByObjectToInt<? super K, ? super V> transformer,
6655 +             int basis,
6656 +             IntByIntToInt reducer) {
6657 +            super(p, b, split);
6658 +            this.transformer = transformer;
6659 +            this.basis = basis; this.reducer = reducer;
6660 +        }
6661 +        public final void compute() {
6662 +            MapReduceMappingsToIntTask<K,V> t = this;
6663 +            final ObjectByObjectToInt<? super K, ? super V> transformer =
6664 +                this.transformer;
6665 +            final IntByIntToInt reducer = this.reducer;
6666 +            if (transformer == null || reducer == null)
6667 +                throw new Error(NullFunctionMessage);
6668 +            final int id = this.basis;
6669 +            int b = batch();
6670 +            while (b > 1 && t.baseIndex != t.baseLimit) {
6671 +                b >>>= 1;
6672 +                t.pending = 1;
6673 +                MapReduceMappingsToIntTask<K,V> rt =
6674 +                    new MapReduceMappingsToIntTask<K,V>
6675 +                    (t, b, true, transformer, id, reducer);
6676 +                t = new MapReduceMappingsToIntTask<K,V>
6677 +                    (t, b, false, transformer, id, reducer);
6678 +                t.sibling = rt;
6679 +                rt.sibling = t;
6680 +                rt.fork();
6681 +            }
6682 +            int r = id;
6683 +            Object v;
6684 +            while ((v = t.advance()) != null)
6685 +                r = reducer.apply(r, transformer.apply((K)t.nextKey, (V)v));
6686 +            t.result = r;
6687 +            for (;;) {
6688 +                int c; BulkTask<K,V,?> par; MapReduceMappingsToIntTask<K,V> s, p;
6689 +                if ((par = t.parent) == null ||
6690 +                    !(par instanceof MapReduceMappingsToIntTask)) {
6691 +                    t.quietlyComplete();
6692 +                    break;
6693 +                }
6694 +                else if ((c = (p = (MapReduceMappingsToIntTask<K,V>)par).pending) == 0) {
6695 +                    if ((s = t.sibling) != null)
6696 +                        r = reducer.apply(r, s.result);
6697 +                    (t = p).result = r;
6698 +                }
6699 +                else if (p.casPending(c, 0))
6700 +                    break;
6701 +            }
6702 +        }
6703 +        public final Integer getRawResult() { return result; }
6704 +    }
6705 +
6706 +
6707      // Unsafe mechanics
6708      private static final sun.misc.Unsafe UNSAFE;
6709      private static final long counterOffset;
# Line 3348 | Line 6758 | public class ConcurrentHashMapV8<K, V>
6758              }
6759          }
6760      }
3351
6761   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines