7 |
|
package java.util.concurrent; |
8 |
|
import java.util.concurrent.ForkJoinPool; |
9 |
|
import java.util.concurrent.CountedCompleter; |
10 |
+ |
import java.util.function.*; |
11 |
+ |
import java.util.stream.Spliterator; |
12 |
+ |
import java.util.stream.Stream; |
13 |
+ |
import java.util.stream.Streams; |
14 |
|
|
15 |
|
import java.util.Comparator; |
16 |
|
import java.util.Arrays; |
93 |
|
* same mapping value. |
94 |
|
* |
95 |
|
* <p>A ConcurrentHashMap can be used as scalable frequency map (a |
96 |
< |
* form of histogram or multiset) by using {@link LongAdder} values |
97 |
< |
* and initializing via {@link #computeIfAbsent}. For example, to add |
98 |
< |
* a count to a {@code ConcurrentHashMap<String,LongAdder> freqs}, you |
99 |
< |
* can use {@code freqs.computeIfAbsent(k -> new |
100 |
< |
* LongAdder()).increment();} |
96 |
> |
* form of histogram or multiset) by using {@link |
97 |
> |
* java.util.concurrent.atomic.LongAdder} values and initializing via |
98 |
> |
* {@link #computeIfAbsent}. For example, to add a count to a {@code |
99 |
> |
* ConcurrentHashMap<String,LongAdder> freqs}, you can use {@code |
100 |
> |
* freqs.computeIfAbsent(k -> new LongAdder()).increment();} |
101 |
|
* |
102 |
|
* <p>This class and its views and iterators implement all of the |
103 |
|
* <em>optional</em> methods of the {@link Map} and {@link Iterator} |
205 |
|
* |
206 |
|
* <p>All arguments to all task methods must be non-null. |
207 |
|
* |
204 |
– |
* <p><em>jsr166e note: During transition, this class |
205 |
– |
* uses nested functional interfaces with different names but the |
206 |
– |
* same forms as those expected for JDK8.</em> |
207 |
– |
* |
208 |
|
* <p>This class is a member of the |
209 |
|
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
210 |
|
* Java Collections Framework</a>. |
218 |
|
implements ConcurrentMap<K, V>, Serializable { |
219 |
|
private static final long serialVersionUID = 7249069246763182397L; |
220 |
|
|
221 |
– |
/** |
222 |
– |
* A partitionable iterator. A Spliterator can be traversed |
223 |
– |
* directly, but can also be partitioned (before traversal) by |
224 |
– |
* creating another Spliterator that covers a non-overlapping |
225 |
– |
* portion of the elements, and so may be amenable to parallel |
226 |
– |
* execution. |
227 |
– |
* |
228 |
– |
* <p>This interface exports a subset of expected JDK8 |
229 |
– |
* functionality. |
230 |
– |
* |
231 |
– |
* <p>Sample usage: Here is one (of the several) ways to compute |
232 |
– |
* the sum of the values held in a map using the ForkJoin |
233 |
– |
* framework. As illustrated here, Spliterators are well suited to |
234 |
– |
* designs in which a task repeatedly splits off half its work |
235 |
– |
* into forked subtasks until small enough to process directly, |
236 |
– |
* and then joins these subtasks. Variants of this style can also |
237 |
– |
* be used in completion-based designs. |
238 |
– |
* |
239 |
– |
* <pre> |
240 |
– |
* {@code ConcurrentHashMap<String, Long> m = ... |
241 |
– |
* // split as if have 8 * parallelism, for load balance |
242 |
– |
* int n = m.size(); |
243 |
– |
* int p = aForkJoinPool.getParallelism() * 8; |
244 |
– |
* int split = (n < p)? n : p; |
245 |
– |
* long sum = aForkJoinPool.invoke(new SumValues(m.valueSpliterator(), split, null)); |
246 |
– |
* // ... |
247 |
– |
* static class SumValues extends RecursiveTask<Long> { |
248 |
– |
* final Spliterator<Long> s; |
249 |
– |
* final int split; // split while > 1 |
250 |
– |
* final SumValues nextJoin; // records forked subtasks to join |
251 |
– |
* SumValues(Spliterator<Long> s, int depth, SumValues nextJoin) { |
252 |
– |
* this.s = s; this.depth = depth; this.nextJoin = nextJoin; |
253 |
– |
* } |
254 |
– |
* public Long compute() { |
255 |
– |
* long sum = 0; |
256 |
– |
* SumValues subtasks = null; // fork subtasks |
257 |
– |
* for (int s = split >>> 1; s > 0; s >>>= 1) |
258 |
– |
* (subtasks = new SumValues(s.split(), s, subtasks)).fork(); |
259 |
– |
* while (s.hasNext()) // directly process remaining elements |
260 |
– |
* sum += s.next(); |
261 |
– |
* for (SumValues t = subtasks; t != null; t = t.nextJoin) |
262 |
– |
* sum += t.join(); // collect subtask results |
263 |
– |
* return sum; |
264 |
– |
* } |
265 |
– |
* } |
266 |
– |
* }</pre> |
267 |
– |
*/ |
268 |
– |
public static interface Spliterator<T> extends Iterator<T> { |
269 |
– |
/** |
270 |
– |
* Returns a Spliterator covering approximately half of the |
271 |
– |
* elements, guaranteed not to overlap with those subsequently |
272 |
– |
* returned by this Spliterator. After invoking this method, |
273 |
– |
* the current Spliterator will <em>not</em> produce any of |
274 |
– |
* the elements of the returned Spliterator, but the two |
275 |
– |
* Spliterators together will produce all of the elements that |
276 |
– |
* would have been produced by this Spliterator had this |
277 |
– |
* method not been called. The exact number of elements |
278 |
– |
* produced by the returned Spliterator is not guaranteed, and |
279 |
– |
* may be zero (i.e., with {@code hasNext()} reporting {@code |
280 |
– |
* false}) if this Spliterator cannot be further split. |
281 |
– |
* |
282 |
– |
* @return a Spliterator covering approximately half of the |
283 |
– |
* elements |
284 |
– |
* @throws IllegalStateException if this Spliterator has |
285 |
– |
* already commenced traversing elements |
286 |
– |
*/ |
287 |
– |
Spliterator<T> split(); |
288 |
– |
} |
289 |
– |
|
221 |
|
/* |
222 |
|
* Overview: |
223 |
|
* |
382 |
|
* LongAdder. We need to incorporate a specialization rather than |
383 |
|
* just use a LongAdder in order to access implicit |
384 |
|
* contention-sensing that leads to creation of multiple |
385 |
< |
* CounterCells. The counter mechanics avoid contention on |
385 |
> |
* Cells. The counter mechanics avoid contention on |
386 |
|
* updates but can encounter cache thrashing if read too |
387 |
|
* frequently during concurrent access. To avoid reading so often, |
388 |
|
* resizing under contention is attempted only upon adding to a |
472 |
|
// See their internal docs for explanation. |
473 |
|
|
474 |
|
// A padded cell for distributing counts |
475 |
< |
static final class CounterCell { |
475 |
> |
static final class Cell { |
476 |
|
volatile long p0, p1, p2, p3, p4, p5, p6; |
477 |
|
volatile long value; |
478 |
|
volatile long q0, q1, q2, q3, q4, q5, q6; |
479 |
< |
CounterCell(long x) { value = x; } |
479 |
> |
Cell(long x) { value = x; } |
480 |
|
} |
481 |
|
|
482 |
|
/** |
483 |
|
* Holder for the thread-local hash code determining which |
484 |
< |
* CounterCell to use. The code is initialized via the |
485 |
< |
* counterHashCodeGenerator, but may be moved upon collisions. |
484 |
> |
* Cell to use. The code is initialized via the |
485 |
> |
* cellHashCodeGenerator, but may be moved upon collisions. |
486 |
|
*/ |
487 |
< |
static final class CounterHashCode { |
487 |
> |
static final class CellHashCode { |
488 |
|
int code; |
489 |
|
} |
490 |
|
|
491 |
|
/** |
492 |
< |
* Generates initial value for per-thread CounterHashCodes |
492 |
> |
* Generates initial value for per-thread CellHashCodes |
493 |
|
*/ |
494 |
< |
static final AtomicInteger counterHashCodeGenerator = new AtomicInteger(); |
494 |
> |
static final AtomicInteger cellHashCodeGenerator = new AtomicInteger(); |
495 |
|
|
496 |
|
/** |
497 |
< |
* Increment for counterHashCodeGenerator. See class ThreadLocal |
497 |
> |
* Increment for cellHashCodeGenerator. See class ThreadLocal |
498 |
|
* for explanation. |
499 |
|
*/ |
500 |
|
static final int SEED_INCREMENT = 0x61c88647; |
502 |
|
/** |
503 |
|
* Per-thread counter hash codes. Shared across all instances |
504 |
|
*/ |
505 |
< |
static final ThreadLocal<CounterHashCode> threadCounterHashCode = |
506 |
< |
new ThreadLocal<CounterHashCode>(); |
505 |
> |
static final ThreadLocal<CellHashCode> threadCellHashCode = |
506 |
> |
new ThreadLocal<CellHashCode>(); |
507 |
|
|
508 |
|
/* ---------------- Fields -------------- */ |
509 |
|
|
548 |
|
/** |
549 |
|
* Spinlock (locked via CAS) used when resizing and/or creating Cells. |
550 |
|
*/ |
551 |
< |
private transient volatile int counterBusy; |
551 |
> |
private transient volatile int cellsBusy; |
552 |
|
|
553 |
|
/** |
554 |
|
* Table of counter cells. When non-null, size is a power of 2. |
555 |
|
*/ |
556 |
< |
private transient volatile CounterCell[] counterCells; |
556 |
> |
private transient volatile Cell[] counterCells; |
557 |
|
|
558 |
|
// views |
559 |
|
private transient KeySetView<K,V> keySet; |
1334 |
|
|
1335 |
|
/** Implementation for computeIfAbsent */ |
1336 |
|
@SuppressWarnings("unchecked") private final V internalComputeIfAbsent |
1337 |
< |
(K k, Fun<? super K, ? extends V> mf) { |
1337 |
> |
(K k, Function<? super K, ? extends V> mf) { |
1338 |
|
if (k == null || mf == null) |
1339 |
|
throw new NullPointerException(); |
1340 |
|
int h = spread(k.hashCode()); |
1437 |
|
/** Implementation for compute */ |
1438 |
|
@SuppressWarnings("unchecked") private final V internalCompute |
1439 |
|
(K k, boolean onlyIfPresent, |
1440 |
< |
BiFun<? super K, ? super V, ? extends V> mf) { |
1440 |
> |
BiFunction<? super K, ? super V, ? extends V> mf) { |
1441 |
|
if (k == null || mf == null) |
1442 |
|
throw new NullPointerException(); |
1443 |
|
int h = spread(k.hashCode()); |
1550 |
|
|
1551 |
|
/** Implementation for merge */ |
1552 |
|
@SuppressWarnings("unchecked") private final V internalMerge |
1553 |
< |
(K k, V v, BiFun<? super V, ? super V, ? extends V> mf) { |
1553 |
> |
(K k, V v, BiFunction<? super V, ? super V, ? extends V> mf) { |
1554 |
|
if (k == null || v == null || mf == null) |
1555 |
|
throw new NullPointerException(); |
1556 |
|
int h = spread(k.hashCode()); |
1840 |
|
* @param check if <0, don't check resize, if <= 1 only check if uncontended |
1841 |
|
*/ |
1842 |
|
private final void addCount(long x, int check) { |
1843 |
< |
CounterCell[] as; long b, s; |
1843 |
> |
Cell[] as; long b, s; |
1844 |
|
if ((as = counterCells) != null || |
1845 |
|
!U.compareAndSwapLong(this, BASECOUNT, b = baseCount, s = b + x)) { |
1846 |
< |
CounterHashCode hc; CounterCell a; long v; int m; |
1846 |
> |
CellHashCode hc; Cell a; long v; int m; |
1847 |
|
boolean uncontended = true; |
1848 |
< |
if ((hc = threadCounterHashCode.get()) == null || |
1848 |
> |
if ((hc = threadCellHashCode.get()) == null || |
1849 |
|
as == null || (m = as.length - 1) < 0 || |
1850 |
|
(a = as[m & hc.code]) == null || |
1851 |
|
!(uncontended = |
2061 |
|
/* ---------------- Counter support -------------- */ |
2062 |
|
|
2063 |
|
final long sumCount() { |
2064 |
< |
CounterCell[] as = counterCells; CounterCell a; |
2064 |
> |
Cell[] as = counterCells; Cell a; |
2065 |
|
long sum = baseCount; |
2066 |
|
if (as != null) { |
2067 |
|
for (int i = 0; i < as.length; ++i) { |
2073 |
|
} |
2074 |
|
|
2075 |
|
// See LongAdder version for explanation |
2076 |
< |
private final void fullAddCount(long x, CounterHashCode hc, |
2076 |
> |
private final void fullAddCount(long x, CellHashCode hc, |
2077 |
|
boolean wasUncontended) { |
2078 |
|
int h; |
2079 |
|
if (hc == null) { |
2080 |
< |
hc = new CounterHashCode(); |
2081 |
< |
int s = counterHashCodeGenerator.addAndGet(SEED_INCREMENT); |
2080 |
> |
hc = new CellHashCode(); |
2081 |
> |
int s = cellHashCodeGenerator.addAndGet(SEED_INCREMENT); |
2082 |
|
h = hc.code = (s == 0) ? 1 : s; // Avoid zero |
2083 |
< |
threadCounterHashCode.set(hc); |
2083 |
> |
threadCellHashCode.set(hc); |
2084 |
|
} |
2085 |
|
else |
2086 |
|
h = hc.code; |
2087 |
|
boolean collide = false; // True if last slot nonempty |
2088 |
|
for (;;) { |
2089 |
< |
CounterCell[] as; CounterCell a; int n; long v; |
2089 |
> |
Cell[] as; Cell a; int n; long v; |
2090 |
|
if ((as = counterCells) != null && (n = as.length) > 0) { |
2091 |
|
if ((a = as[(n - 1) & h]) == null) { |
2092 |
< |
if (counterBusy == 0) { // Try to attach new Cell |
2093 |
< |
CounterCell r = new CounterCell(x); // Optimistic create |
2094 |
< |
if (counterBusy == 0 && |
2095 |
< |
U.compareAndSwapInt(this, COUNTERBUSY, 0, 1)) { |
2092 |
> |
if (cellsBusy == 0) { // Try to attach new Cell |
2093 |
> |
Cell r = new Cell(x); // Optimistic create |
2094 |
> |
if (cellsBusy == 0 && |
2095 |
> |
U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) { |
2096 |
|
boolean created = false; |
2097 |
|
try { // Recheck under lock |
2098 |
< |
CounterCell[] rs; int m, j; |
2098 |
> |
Cell[] rs; int m, j; |
2099 |
|
if ((rs = counterCells) != null && |
2100 |
|
(m = rs.length) > 0 && |
2101 |
|
rs[j = (m - 1) & h] == null) { |
2103 |
|
created = true; |
2104 |
|
} |
2105 |
|
} finally { |
2106 |
< |
counterBusy = 0; |
2106 |
> |
cellsBusy = 0; |
2107 |
|
} |
2108 |
|
if (created) |
2109 |
|
break; |
2120 |
|
collide = false; // At max size or stale |
2121 |
|
else if (!collide) |
2122 |
|
collide = true; |
2123 |
< |
else if (counterBusy == 0 && |
2124 |
< |
U.compareAndSwapInt(this, COUNTERBUSY, 0, 1)) { |
2123 |
> |
else if (cellsBusy == 0 && |
2124 |
> |
U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) { |
2125 |
|
try { |
2126 |
|
if (counterCells == as) {// Expand table unless stale |
2127 |
< |
CounterCell[] rs = new CounterCell[n << 1]; |
2127 |
> |
Cell[] rs = new Cell[n << 1]; |
2128 |
|
for (int i = 0; i < n; ++i) |
2129 |
|
rs[i] = as[i]; |
2130 |
|
counterCells = rs; |
2131 |
|
} |
2132 |
|
} finally { |
2133 |
< |
counterBusy = 0; |
2133 |
> |
cellsBusy = 0; |
2134 |
|
} |
2135 |
|
collide = false; |
2136 |
|
continue; // Retry with expanded table |
2139 |
|
h ^= h >>> 17; |
2140 |
|
h ^= h << 5; |
2141 |
|
} |
2142 |
< |
else if (counterBusy == 0 && counterCells == as && |
2143 |
< |
U.compareAndSwapInt(this, COUNTERBUSY, 0, 1)) { |
2142 |
> |
else if (cellsBusy == 0 && counterCells == as && |
2143 |
> |
U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) { |
2144 |
|
boolean init = false; |
2145 |
|
try { // Initialize table |
2146 |
|
if (counterCells == as) { |
2147 |
< |
CounterCell[] rs = new CounterCell[2]; |
2148 |
< |
rs[h & 1] = new CounterCell(x); |
2147 |
> |
Cell[] rs = new Cell[2]; |
2148 |
> |
rs[h & 1] = new Cell(x); |
2149 |
|
counterCells = rs; |
2150 |
|
init = true; |
2151 |
|
} |
2152 |
|
} finally { |
2153 |
< |
counterBusy = 0; |
2153 |
> |
cellsBusy = 0; |
2154 |
|
} |
2155 |
|
if (init) |
2156 |
|
break; |
2201 |
|
* across threads, iteration terminates if a bounds checks fails |
2202 |
|
* for a table read. |
2203 |
|
* |
2204 |
+ |
* This class supports both Spliterator-based traversal and |
2205 |
+ |
* CountedCompleter-based bulk tasks. The same "batch" field is |
2206 |
+ |
* used, but in slightly different ways, in the two cases. For |
2207 |
+ |
* Spliterators, it is a saturating (at Integer.MAX_VALUE) |
2208 |
+ |
* estimate of element coverage. For CHM tasks, it is a pre-scaled |
2209 |
+ |
* size that halves down to zero for leaf tasks, that is only |
2210 |
+ |
* computed upon execution of the task. (Tasks can be submitted to |
2211 |
+ |
* any pool, of any size, so we don't know scale factors until |
2212 |
+ |
* running.) |
2213 |
+ |
* |
2214 |
|
* This class extends CountedCompleter to streamline parallel |
2215 |
|
* iteration in bulk operations. This adds only a few fields of |
2216 |
|
* space overhead, which is small enough in cases where it is not |
2230 |
|
int baseLimit; // index bound for initial table |
2231 |
|
int baseSize; // initial table size |
2232 |
|
int batch; // split control |
2292 |
– |
|
2233 |
|
/** Creates iterator for all entries in the table. */ |
2234 |
|
Traverser(ConcurrentHashMap<K, V> map) { |
2235 |
|
this.map = map; |
2236 |
+ |
Node<V>[] t; |
2237 |
+ |
if ((t = tab = map.table) != null) |
2238 |
+ |
baseLimit = baseSize = t.length; |
2239 |
|
} |
2240 |
|
|
2241 |
< |
/** Creates iterator for split() methods and task constructors */ |
2241 |
> |
/** Task constructor */ |
2242 |
|
Traverser(ConcurrentHashMap<K,V> map, Traverser<K,V,?> it, int batch) { |
2243 |
|
super(it); |
2244 |
< |
this.batch = batch; |
2245 |
< |
if ((this.map = map) != null && it != null) { // split parent |
2244 |
> |
this.map = map; |
2245 |
> |
this.batch = batch; // -1 if unknown |
2246 |
> |
if (it == null) { |
2247 |
|
Node<V>[] t; |
2248 |
< |
if ((t = it.tab) == null && |
2249 |
< |
(t = it.tab = map.table) != null) |
2250 |
< |
it.baseLimit = it.baseSize = t.length; |
2251 |
< |
this.tab = t; |
2248 |
> |
if ((t = tab = map.table) != null) |
2249 |
> |
baseLimit = baseSize = t.length; |
2250 |
> |
} |
2251 |
> |
else { // split parent |
2252 |
> |
this.tab = it.tab; |
2253 |
|
this.baseSize = it.baseSize; |
2254 |
|
int hi = this.baseLimit = it.baseLimit; |
2255 |
|
it.baseLimit = this.index = this.baseIndex = |
2257 |
|
} |
2258 |
|
} |
2259 |
|
|
2260 |
+ |
/** Spliterator constructor */ |
2261 |
+ |
Traverser(ConcurrentHashMap<K,V> map, Traverser<K,V,?> it) { |
2262 |
+ |
super(it); |
2263 |
+ |
this.map = map; |
2264 |
+ |
if (it == null) { |
2265 |
+ |
Node<V>[] t; |
2266 |
+ |
if ((t = tab = map.table) != null) |
2267 |
+ |
baseLimit = baseSize = t.length; |
2268 |
+ |
long n = map.sumCount(); |
2269 |
+ |
batch = ((n > (long)Integer.MAX_VALUE) ? Integer.MAX_VALUE : |
2270 |
+ |
(int)n); |
2271 |
+ |
} |
2272 |
+ |
else { |
2273 |
+ |
this.tab = it.tab; |
2274 |
+ |
this.baseSize = it.baseSize; |
2275 |
+ |
int hi = this.baseLimit = it.baseLimit; |
2276 |
+ |
it.baseLimit = this.index = this.baseIndex = |
2277 |
+ |
(hi + it.baseIndex + 1) >>> 1; |
2278 |
+ |
this.batch = it.batch >>>= 1; |
2279 |
+ |
} |
2280 |
+ |
} |
2281 |
+ |
|
2282 |
|
/** |
2283 |
|
* Advances next; returns nextVal or null if terminated. |
2284 |
|
* See above for explanation. |
2343 |
|
* anyway. |
2344 |
|
*/ |
2345 |
|
final int preSplit() { |
2346 |
< |
ConcurrentHashMap<K, V> m; int b; Node<V>[] t; ForkJoinPool pool; |
2347 |
< |
if ((b = batch) < 0 && (m = map) != null) { // force initialization |
2348 |
< |
if ((t = tab) == null && (t = tab = m.table) != null) |
2349 |
< |
baseLimit = baseSize = t.length; |
2350 |
< |
if (t != null) { |
2351 |
< |
long n = m.sumCount(); |
2352 |
< |
int par = ((pool = getPool()) == null) ? |
2386 |
< |
ForkJoinPool.getCommonPoolParallelism() : |
2387 |
< |
pool.getParallelism(); |
2388 |
< |
int sp = par << 3; // slack of 8 |
2389 |
< |
b = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp; |
2390 |
< |
} |
2346 |
> |
int b; ForkJoinPool pool; |
2347 |
> |
if ((b = batch) < 0) { // force initialization |
2348 |
> |
int sp = (((pool = getPool()) == null) ? |
2349 |
> |
ForkJoinPool.getCommonPoolParallelism() : |
2350 |
> |
pool.getParallelism()) << 3; // slack of 8 |
2351 |
> |
long n = map.sumCount(); |
2352 |
> |
b = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp; |
2353 |
|
} |
2354 |
|
b = (b <= 1 || baseIndex == baseLimit) ? 0 : (b >>> 1); |
2355 |
|
if ((batch = b) > 0) |
2357 |
|
return b; |
2358 |
|
} |
2359 |
|
|
2360 |
+ |
// spliterator support |
2361 |
+ |
|
2362 |
+ |
public long exactSizeIfKnown() { |
2363 |
+ |
return -1; |
2364 |
+ |
} |
2365 |
+ |
|
2366 |
+ |
public boolean hasExactSplits() { |
2367 |
+ |
return false; |
2368 |
+ |
} |
2369 |
+ |
|
2370 |
+ |
public int getNaturalSplits() { |
2371 |
+ |
return baseLimit > baseIndex ? 1 : 0; |
2372 |
+ |
} |
2373 |
+ |
|
2374 |
+ |
public long estimateSize() { |
2375 |
+ |
return batch; |
2376 |
+ |
} |
2377 |
|
} |
2378 |
|
|
2379 |
|
/* ---------------- Public operations -------------- */ |
2643 |
|
} |
2644 |
|
|
2645 |
|
/** |
2646 |
< |
* If the specified key is not already associated with a value, |
2647 |
< |
* computes its value using the given mappingFunction and enters |
2648 |
< |
* it into the map unless null. This is equivalent to |
2649 |
< |
* <pre> {@code |
2650 |
< |
* if (map.containsKey(key)) |
2651 |
< |
* return map.get(key); |
2652 |
< |
* value = mappingFunction.apply(key); |
2653 |
< |
* if (value != null) |
2654 |
< |
* map.put(key, value); |
2676 |
< |
* return value;}</pre> |
2677 |
< |
* |
2678 |
< |
* except that the action is performed atomically. If the |
2679 |
< |
* function returns {@code null} no mapping is recorded. If the |
2680 |
< |
* function itself throws an (unchecked) exception, the exception |
2681 |
< |
* is rethrown to its caller, and no mapping is recorded. Some |
2682 |
< |
* attempted update operations on this map by other threads may be |
2683 |
< |
* blocked while computation is in progress, so the computation |
2684 |
< |
* should be short and simple, and must not attempt to update any |
2685 |
< |
* other mappings of this Map. The most appropriate usage is to |
2686 |
< |
* construct a new object serving as an initial mapped value, or |
2687 |
< |
* memoized result, as in: |
2688 |
< |
* |
2689 |
< |
* <pre> {@code |
2690 |
< |
* map.computeIfAbsent(key, new Fun<K, V>() { |
2691 |
< |
* public V map(K k) { return new Value(f(k)); }});}</pre> |
2646 |
> |
* If the specified key is not already associated with a value (or |
2647 |
> |
* is mapped to {@code null}), attempts to compute its value using |
2648 |
> |
* the given mapping function and enters it into this map unless |
2649 |
> |
* {@code null}. The entire method invocation is performed |
2650 |
> |
* atomically, so the function is applied at most once per key. |
2651 |
> |
* Some attempted update operations on this map by other threads |
2652 |
> |
* may be blocked while computation is in progress, so the |
2653 |
> |
* computation should be short and simple, and must not attempt to |
2654 |
> |
* update any other mappings of this Map. |
2655 |
|
* |
2656 |
|
* @param key key with which the specified value is to be associated |
2657 |
|
* @param mappingFunction the function to compute a value |
2666 |
|
* in which case the mapping is left unestablished |
2667 |
|
*/ |
2668 |
|
public V computeIfAbsent |
2669 |
< |
(K key, Fun<? super K, ? extends V> mappingFunction) { |
2669 |
> |
(K key, Function<? super K, ? extends V> mappingFunction) { |
2670 |
|
return internalComputeIfAbsent(key, mappingFunction); |
2671 |
|
} |
2672 |
|
|
2673 |
|
/** |
2674 |
< |
* If the given key is present, computes a new mapping value given a key and |
2675 |
< |
* its current mapped value. This is equivalent to |
2676 |
< |
* <pre> {@code |
2677 |
< |
* if (map.containsKey(key)) { |
2715 |
< |
* value = remappingFunction.apply(key, map.get(key)); |
2716 |
< |
* if (value != null) |
2717 |
< |
* map.put(key, value); |
2718 |
< |
* else |
2719 |
< |
* map.remove(key); |
2720 |
< |
* } |
2721 |
< |
* }</pre> |
2722 |
< |
* |
2723 |
< |
* except that the action is performed atomically. If the |
2724 |
< |
* function returns {@code null}, the mapping is removed. If the |
2725 |
< |
* function itself throws an (unchecked) exception, the exception |
2726 |
< |
* is rethrown to its caller, and the current mapping is left |
2727 |
< |
* unchanged. Some attempted update operations on this map by |
2674 |
> |
* If the value for the specified key is present and non-null, |
2675 |
> |
* attempts to compute a new mapping given the key and its current |
2676 |
> |
* mapped value. The entire method invocation is performed |
2677 |
> |
* atomically. Some attempted update operations on this map by |
2678 |
|
* other threads may be blocked while computation is in progress, |
2679 |
|
* so the computation should be short and simple, and must not |
2680 |
< |
* attempt to update any other mappings of this Map. For example, |
2731 |
< |
* to either create or append new messages to a value mapping: |
2680 |
> |
* attempt to update any other mappings of this Map. |
2681 |
|
* |
2682 |
|
* @param key key with which the specified value is to be associated |
2683 |
|
* @param remappingFunction the function to compute a value |
2691 |
|
* in which case the mapping is unchanged |
2692 |
|
*/ |
2693 |
|
public V computeIfPresent |
2694 |
< |
(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) { |
2694 |
> |
(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
2695 |
|
return internalCompute(key, true, remappingFunction); |
2696 |
|
} |
2697 |
|
|
2698 |
|
/** |
2699 |
< |
* Computes a new mapping value given a key and |
2700 |
< |
* its current mapped value (or {@code null} if there is no current |
2701 |
< |
* mapping). This is equivalent to |
2702 |
< |
* <pre> {@code |
2703 |
< |
* value = remappingFunction.apply(key, map.get(key)); |
2704 |
< |
* if (value != null) |
2705 |
< |
* map.put(key, value); |
2757 |
< |
* else |
2758 |
< |
* map.remove(key); |
2759 |
< |
* }</pre> |
2760 |
< |
* |
2761 |
< |
* except that the action is performed atomically. If the |
2762 |
< |
* function returns {@code null}, the mapping is removed. If the |
2763 |
< |
* function itself throws an (unchecked) exception, the exception |
2764 |
< |
* is rethrown to its caller, and the current mapping is left |
2765 |
< |
* unchanged. Some attempted update operations on this map by |
2766 |
< |
* other threads may be blocked while computation is in progress, |
2767 |
< |
* so the computation should be short and simple, and must not |
2768 |
< |
* attempt to update any other mappings of this Map. For example, |
2769 |
< |
* to either create or append new messages to a value mapping: |
2770 |
< |
* |
2771 |
< |
* <pre> {@code |
2772 |
< |
* Map<Key, String> map = ...; |
2773 |
< |
* final String msg = ...; |
2774 |
< |
* map.compute(key, new BiFun<Key, String, String>() { |
2775 |
< |
* public String apply(Key k, String v) { |
2776 |
< |
* return (v == null) ? msg : v + msg;});}}</pre> |
2699 |
> |
* Attempts to compute a mapping for the specified key and its |
2700 |
> |
* current mapped value (or {@code null} if there is no current |
2701 |
> |
* mapping). The entire method invocation is performed atomically. |
2702 |
> |
* Some attempted update operations on this map by other threads |
2703 |
> |
* may be blocked while computation is in progress, so the |
2704 |
> |
* computation should be short and simple, and must not attempt to |
2705 |
> |
* update any other mappings of this Map. |
2706 |
|
* |
2707 |
|
* @param key key with which the specified value is to be associated |
2708 |
|
* @param remappingFunction the function to compute a value |
2716 |
|
* in which case the mapping is unchanged |
2717 |
|
*/ |
2718 |
|
public V compute |
2719 |
< |
(K key, BiFun<? super K, ? super V, ? extends V> remappingFunction) { |
2719 |
> |
(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
2720 |
|
return internalCompute(key, false, remappingFunction); |
2721 |
|
} |
2722 |
|
|
2723 |
|
/** |
2724 |
< |
* If the specified key is not already associated |
2725 |
< |
* with a value, associate it with the given value. |
2726 |
< |
* Otherwise, replace the value with the results of |
2727 |
< |
* the given remapping function. This is equivalent to: |
2728 |
< |
* <pre> {@code |
2729 |
< |
* if (!map.containsKey(key)) |
2730 |
< |
* map.put(value); |
2731 |
< |
* else { |
2732 |
< |
* newValue = remappingFunction.apply(map.get(key), value); |
2733 |
< |
* if (value != null) |
2734 |
< |
* map.put(key, value); |
2735 |
< |
* else |
2736 |
< |
* map.remove(key); |
2737 |
< |
* } |
2738 |
< |
* }</pre> |
2739 |
< |
* except that the action is performed atomically. If the |
2740 |
< |
* function returns {@code null}, the mapping is removed. If the |
2741 |
< |
* function itself throws an (unchecked) exception, the exception |
2813 |
< |
* is rethrown to its caller, and the current mapping is left |
2814 |
< |
* unchanged. Some attempted update operations on this map by |
2815 |
< |
* other threads may be blocked while computation is in progress, |
2816 |
< |
* so the computation should be short and simple, and must not |
2817 |
< |
* attempt to update any other mappings of this Map. |
2724 |
> |
* If the specified key is not already associated with a |
2725 |
> |
* (non-null) value, associates it with the given value. |
2726 |
> |
* Otherwise, replaces the value with the results of the given |
2727 |
> |
* remapping function, or removes if {@code null}. The entire |
2728 |
> |
* method invocation is performed atomically. Some attempted |
2729 |
> |
* update operations on this map by other threads may be blocked |
2730 |
> |
* while computation is in progress, so the computation should be |
2731 |
> |
* short and simple, and must not attempt to update any other |
2732 |
> |
* mappings of this Map. |
2733 |
> |
* |
2734 |
> |
* @param key key with which the specified value is to be associated |
2735 |
> |
* @param value the value to use if absent |
2736 |
> |
* @param remappingFunction the function to recompute a value if present |
2737 |
> |
* @return the new value associated with the specified key, or null if none |
2738 |
> |
* @throws NullPointerException if the specified key or the |
2739 |
> |
* remappingFunction is null |
2740 |
> |
* @throws RuntimeException or Error if the remappingFunction does so, |
2741 |
> |
* in which case the mapping is unchanged |
2742 |
|
*/ |
2743 |
|
public V merge |
2744 |
|
(K key, V value, |
2745 |
< |
BiFun<? super V, ? super V, ? extends V> remappingFunction) { |
2745 |
> |
BiFunction<? super V, ? super V, ? extends V> remappingFunction) { |
2746 |
|
return internalMerge(key, value, remappingFunction); |
2747 |
|
} |
2748 |
|
|
2881 |
|
} |
2882 |
|
|
2883 |
|
/** |
2960 |
– |
* Returns a partitionable iterator of the keys in this map. |
2961 |
– |
* |
2962 |
– |
* @return a partitionable iterator of the keys in this map |
2963 |
– |
*/ |
2964 |
– |
public Spliterator<K> keySpliterator() { |
2965 |
– |
return new KeyIterator<K,V>(this); |
2966 |
– |
} |
2967 |
– |
|
2968 |
– |
/** |
2969 |
– |
* Returns a partitionable iterator of the values in this map. |
2970 |
– |
* |
2971 |
– |
* @return a partitionable iterator of the values in this map |
2972 |
– |
*/ |
2973 |
– |
public Spliterator<V> valueSpliterator() { |
2974 |
– |
return new ValueIterator<K,V>(this); |
2975 |
– |
} |
2976 |
– |
|
2977 |
– |
/** |
2978 |
– |
* Returns a partitionable iterator of the entries in this map. |
2979 |
– |
* |
2980 |
– |
* @return a partitionable iterator of the entries in this map |
2981 |
– |
*/ |
2982 |
– |
public Spliterator<Map.Entry<K,V>> entrySpliterator() { |
2983 |
– |
return new EntryIterator<K,V>(this); |
2984 |
– |
} |
2985 |
– |
|
2986 |
– |
/** |
2884 |
|
* Returns the hash code value for this {@link Map}, i.e., |
2885 |
|
* the sum of, for each key-value pair in the map, |
2886 |
|
* {@code key.hashCode() ^ value.hashCode()}. |
2965 |
|
|
2966 |
|
@SuppressWarnings("serial") static final class KeyIterator<K,V> |
2967 |
|
extends Traverser<K,V,Object> |
2968 |
< |
implements Spliterator<K>, Enumeration<K> { |
2968 |
> |
implements Spliterator<K>, Iterator<K>, Enumeration<K> { |
2969 |
|
KeyIterator(ConcurrentHashMap<K, V> map) { super(map); } |
2970 |
|
KeyIterator(ConcurrentHashMap<K, V> map, Traverser<K,V,Object> it) { |
2971 |
< |
super(map, it, -1); |
2971 |
> |
super(map, it); |
2972 |
|
} |
2973 |
|
public KeyIterator<K,V> split() { |
2974 |
|
if (nextKey != null) |
2984 |
|
} |
2985 |
|
|
2986 |
|
public final K nextElement() { return next(); } |
2987 |
+ |
|
2988 |
+ |
public Iterator<K> iterator() { return this; } |
2989 |
+ |
|
2990 |
+ |
public void forEach(Block<? super K> action) { |
2991 |
+ |
if (action == null) throw new NullPointerException(); |
2992 |
+ |
while (advance() != null) |
2993 |
+ |
action.accept((K)nextKey); |
2994 |
+ |
} |
2995 |
|
} |
2996 |
|
|
2997 |
|
@SuppressWarnings("serial") static final class ValueIterator<K,V> |
2998 |
|
extends Traverser<K,V,Object> |
2999 |
< |
implements Spliterator<V>, Enumeration<V> { |
2999 |
> |
implements Spliterator<V>, Iterator<V>, Enumeration<V> { |
3000 |
|
ValueIterator(ConcurrentHashMap<K, V> map) { super(map); } |
3001 |
|
ValueIterator(ConcurrentHashMap<K, V> map, Traverser<K,V,Object> it) { |
3002 |
< |
super(map, it, -1); |
3002 |
> |
super(map, it); |
3003 |
|
} |
3004 |
|
public ValueIterator<K,V> split() { |
3005 |
|
if (nextKey != null) |
3016 |
|
} |
3017 |
|
|
3018 |
|
public final V nextElement() { return next(); } |
3019 |
+ |
|
3020 |
+ |
public Iterator<V> iterator() { return this; } |
3021 |
+ |
|
3022 |
+ |
public void forEach(Block<? super V> action) { |
3023 |
+ |
if (action == null) throw new NullPointerException(); |
3024 |
+ |
V v; |
3025 |
+ |
while ((v = advance()) != null) |
3026 |
+ |
action.accept(v); |
3027 |
+ |
} |
3028 |
|
} |
3029 |
|
|
3030 |
|
@SuppressWarnings("serial") static final class EntryIterator<K,V> |
3031 |
|
extends Traverser<K,V,Object> |
3032 |
< |
implements Spliterator<Map.Entry<K,V>> { |
3032 |
> |
implements Spliterator<Map.Entry<K,V>>, Iterator<Map.Entry<K,V>> { |
3033 |
|
EntryIterator(ConcurrentHashMap<K, V> map) { super(map); } |
3034 |
|
EntryIterator(ConcurrentHashMap<K, V> map, Traverser<K,V,Object> it) { |
3035 |
< |
super(map, it, -1); |
3035 |
> |
super(map, it); |
3036 |
|
} |
3037 |
|
public EntryIterator<K,V> split() { |
3038 |
|
if (nextKey != null) |
3048 |
|
nextVal = null; |
3049 |
|
return new MapEntry<K,V>((K)k, v, map); |
3050 |
|
} |
3051 |
+ |
|
3052 |
+ |
public Iterator<Map.Entry<K,V>> iterator() { return this; } |
3053 |
+ |
|
3054 |
+ |
public void forEach(Block<? super Map.Entry<K,V>> action) { |
3055 |
+ |
if (action == null) throw new NullPointerException(); |
3056 |
+ |
V v; |
3057 |
+ |
while ((v = advance()) != null) |
3058 |
+ |
action.accept(entryFor((K)nextKey, v)); |
3059 |
+ |
} |
3060 |
|
} |
3061 |
|
|
3062 |
|
/** |
3236 |
|
|
3237 |
|
// ------------------------------------------------------- |
3238 |
|
|
3316 |
– |
// Sams |
3317 |
– |
/** Interface describing a void action of one argument */ |
3318 |
– |
public interface Action<A> { void apply(A a); } |
3319 |
– |
/** Interface describing a void action of two arguments */ |
3320 |
– |
public interface BiAction<A,B> { void apply(A a, B b); } |
3321 |
– |
/** Interface describing a function of one argument */ |
3322 |
– |
public interface Fun<A,T> { T apply(A a); } |
3323 |
– |
/** Interface describing a function of two arguments */ |
3324 |
– |
public interface BiFun<A,B,T> { T apply(A a, B b); } |
3325 |
– |
/** Interface describing a function of no arguments */ |
3326 |
– |
public interface Generator<T> { T apply(); } |
3327 |
– |
/** Interface describing a function mapping its argument to a double */ |
3328 |
– |
public interface ObjectToDouble<A> { double apply(A a); } |
3329 |
– |
/** Interface describing a function mapping its argument to a long */ |
3330 |
– |
public interface ObjectToLong<A> { long apply(A a); } |
3331 |
– |
/** Interface describing a function mapping its argument to an int */ |
3332 |
– |
public interface ObjectToInt<A> {int apply(A a); } |
3333 |
– |
/** Interface describing a function mapping two arguments to a double */ |
3334 |
– |
public interface ObjectByObjectToDouble<A,B> { double apply(A a, B b); } |
3335 |
– |
/** Interface describing a function mapping two arguments to a long */ |
3336 |
– |
public interface ObjectByObjectToLong<A,B> { long apply(A a, B b); } |
3337 |
– |
/** Interface describing a function mapping two arguments to an int */ |
3338 |
– |
public interface ObjectByObjectToInt<A,B> {int apply(A a, B b); } |
3339 |
– |
/** Interface describing a function mapping a double to a double */ |
3340 |
– |
public interface DoubleToDouble { double apply(double a); } |
3341 |
– |
/** Interface describing a function mapping a long to a long */ |
3342 |
– |
public interface LongToLong { long apply(long a); } |
3343 |
– |
/** Interface describing a function mapping an int to an int */ |
3344 |
– |
public interface IntToInt { int apply(int a); } |
3345 |
– |
/** Interface describing a function mapping two doubles to a double */ |
3346 |
– |
public interface DoubleByDoubleToDouble { double apply(double a, double b); } |
3347 |
– |
/** Interface describing a function mapping two longs to a long */ |
3348 |
– |
public interface LongByLongToLong { long apply(long a, long b); } |
3349 |
– |
/** Interface describing a function mapping two ints to an int */ |
3350 |
– |
public interface IntByIntToInt { int apply(int a, int b); } |
3351 |
– |
|
3352 |
– |
|
3353 |
– |
// ------------------------------------------------------- |
3354 |
– |
|
3239 |
|
// Sequential bulk operations |
3240 |
|
|
3241 |
|
/** |
3244 |
|
* @param action the action |
3245 |
|
*/ |
3246 |
|
@SuppressWarnings("unchecked") public void forEachSequentially |
3247 |
< |
(BiAction<K,V> action) { |
3247 |
> |
(BiBlock<? super K, ? super V> action) { |
3248 |
|
if (action == null) throw new NullPointerException(); |
3249 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3250 |
|
V v; |
3251 |
|
while ((v = it.advance()) != null) |
3252 |
< |
action.apply((K)it.nextKey, v); |
3252 |
> |
action.accept((K)it.nextKey, v); |
3253 |
|
} |
3254 |
|
|
3255 |
|
/** |
3262 |
|
* @param action the action |
3263 |
|
*/ |
3264 |
|
@SuppressWarnings("unchecked") public <U> void forEachSequentially |
3265 |
< |
(BiFun<? super K, ? super V, ? extends U> transformer, |
3266 |
< |
Action<U> action) { |
3265 |
> |
(BiFunction<? super K, ? super V, ? extends U> transformer, |
3266 |
> |
Block<? super U> action) { |
3267 |
|
if (transformer == null || action == null) |
3268 |
|
throw new NullPointerException(); |
3269 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3270 |
|
V v; U u; |
3271 |
|
while ((v = it.advance()) != null) { |
3272 |
|
if ((u = transformer.apply((K)it.nextKey, v)) != null) |
3273 |
< |
action.apply(u); |
3273 |
> |
action.accept(u); |
3274 |
|
} |
3275 |
|
} |
3276 |
|
|
3284 |
|
* function on each (key, value), or null if none |
3285 |
|
*/ |
3286 |
|
@SuppressWarnings("unchecked") public <U> U searchSequentially |
3287 |
< |
(BiFun<? super K, ? super V, ? extends U> searchFunction) { |
3287 |
> |
(BiFunction<? super K, ? super V, ? extends U> searchFunction) { |
3288 |
|
if (searchFunction == null) throw new NullPointerException(); |
3289 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3290 |
|
V v; U u; |
3308 |
|
* of all (key, value) pairs |
3309 |
|
*/ |
3310 |
|
@SuppressWarnings("unchecked") public <U> U reduceSequentially |
3311 |
< |
(BiFun<? super K, ? super V, ? extends U> transformer, |
3312 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
3311 |
> |
(BiFunction<? super K, ? super V, ? extends U> transformer, |
3312 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
3313 |
|
if (transformer == null || reducer == null) |
3314 |
|
throw new NullPointerException(); |
3315 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3334 |
|
* of all (key, value) pairs |
3335 |
|
*/ |
3336 |
|
@SuppressWarnings("unchecked") public double reduceToDoubleSequentially |
3337 |
< |
(ObjectByObjectToDouble<? super K, ? super V> transformer, |
3337 |
> |
(DoubleBiFunction<? super K, ? super V> transformer, |
3338 |
|
double basis, |
3339 |
< |
DoubleByDoubleToDouble reducer) { |
3339 |
> |
DoubleBinaryOperator reducer) { |
3340 |
|
if (transformer == null || reducer == null) |
3341 |
|
throw new NullPointerException(); |
3342 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3343 |
|
double r = basis; V v; |
3344 |
|
while ((v = it.advance()) != null) |
3345 |
< |
r = reducer.apply(r, transformer.apply((K)it.nextKey, v)); |
3345 |
> |
r = reducer.applyAsDouble(r, transformer.applyAsDouble((K)it.nextKey, v)); |
3346 |
|
return r; |
3347 |
|
} |
3348 |
|
|
3359 |
|
* of all (key, value) pairs |
3360 |
|
*/ |
3361 |
|
@SuppressWarnings("unchecked") public long reduceToLongSequentially |
3362 |
< |
(ObjectByObjectToLong<? super K, ? super V> transformer, |
3362 |
> |
(LongBiFunction<? super K, ? super V> transformer, |
3363 |
|
long basis, |
3364 |
< |
LongByLongToLong reducer) { |
3364 |
> |
LongBinaryOperator reducer) { |
3365 |
|
if (transformer == null || reducer == null) |
3366 |
|
throw new NullPointerException(); |
3367 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3368 |
|
long r = basis; V v; |
3369 |
|
while ((v = it.advance()) != null) |
3370 |
< |
r = reducer.apply(r, transformer.apply((K)it.nextKey, v)); |
3370 |
> |
r = reducer.applyAsLong(r, transformer.applyAsLong((K)it.nextKey, v)); |
3371 |
|
return r; |
3372 |
|
} |
3373 |
|
|
3384 |
|
* of all (key, value) pairs |
3385 |
|
*/ |
3386 |
|
@SuppressWarnings("unchecked") public int reduceToIntSequentially |
3387 |
< |
(ObjectByObjectToInt<? super K, ? super V> transformer, |
3387 |
> |
(IntBiFunction<? super K, ? super V> transformer, |
3388 |
|
int basis, |
3389 |
< |
IntByIntToInt reducer) { |
3389 |
> |
IntBinaryOperator reducer) { |
3390 |
|
if (transformer == null || reducer == null) |
3391 |
|
throw new NullPointerException(); |
3392 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3393 |
|
int r = basis; V v; |
3394 |
|
while ((v = it.advance()) != null) |
3395 |
< |
r = reducer.apply(r, transformer.apply((K)it.nextKey, v)); |
3395 |
> |
r = reducer.applyAsInt(r, transformer.applyAsInt((K)it.nextKey, v)); |
3396 |
|
return r; |
3397 |
|
} |
3398 |
|
|
3402 |
|
* @param action the action |
3403 |
|
*/ |
3404 |
|
@SuppressWarnings("unchecked") public void forEachKeySequentially |
3405 |
< |
(Action<K> action) { |
3405 |
> |
(Block<? super K> action) { |
3406 |
|
if (action == null) throw new NullPointerException(); |
3407 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3408 |
|
while (it.advance() != null) |
3409 |
< |
action.apply((K)it.nextKey); |
3409 |
> |
action.accept((K)it.nextKey); |
3410 |
|
} |
3411 |
|
|
3412 |
|
/** |
3419 |
|
* @param action the action |
3420 |
|
*/ |
3421 |
|
@SuppressWarnings("unchecked") public <U> void forEachKeySequentially |
3422 |
< |
(Fun<? super K, ? extends U> transformer, |
3423 |
< |
Action<U> action) { |
3422 |
> |
(Function<? super K, ? extends U> transformer, |
3423 |
> |
Block<? super U> action) { |
3424 |
|
if (transformer == null || action == null) |
3425 |
|
throw new NullPointerException(); |
3426 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3427 |
|
U u; |
3428 |
|
while (it.advance() != null) { |
3429 |
|
if ((u = transformer.apply((K)it.nextKey)) != null) |
3430 |
< |
action.apply(u); |
3430 |
> |
action.accept(u); |
3431 |
|
} |
3432 |
|
ForkJoinTasks.forEachKey |
3433 |
|
(this, transformer, action).invoke(); |
3443 |
|
* function on each key, or null if none |
3444 |
|
*/ |
3445 |
|
@SuppressWarnings("unchecked") public <U> U searchKeysSequentially |
3446 |
< |
(Fun<? super K, ? extends U> searchFunction) { |
3446 |
> |
(Function<? super K, ? extends U> searchFunction) { |
3447 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3448 |
|
U u; |
3449 |
|
while (it.advance() != null) { |
3462 |
|
* reducer to combine values, or null if none |
3463 |
|
*/ |
3464 |
|
@SuppressWarnings("unchecked") public K reduceKeysSequentially |
3465 |
< |
(BiFun<? super K, ? super K, ? extends K> reducer) { |
3465 |
> |
(BiFunction<? super K, ? super K, ? extends K> reducer) { |
3466 |
|
if (reducer == null) throw new NullPointerException(); |
3467 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3468 |
|
K r = null; |
3486 |
|
* of all keys |
3487 |
|
*/ |
3488 |
|
@SuppressWarnings("unchecked") public <U> U reduceKeysSequentially |
3489 |
< |
(Fun<? super K, ? extends U> transformer, |
3490 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
3489 |
> |
(Function<? super K, ? extends U> transformer, |
3490 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
3491 |
|
if (transformer == null || reducer == null) |
3492 |
|
throw new NullPointerException(); |
3493 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3512 |
|
* of all keys |
3513 |
|
*/ |
3514 |
|
@SuppressWarnings("unchecked") public double reduceKeysToDoubleSequentially |
3515 |
< |
(ObjectToDouble<? super K> transformer, |
3515 |
> |
(DoubleFunction<? super K> transformer, |
3516 |
|
double basis, |
3517 |
< |
DoubleByDoubleToDouble reducer) { |
3517 |
> |
DoubleBinaryOperator reducer) { |
3518 |
|
if (transformer == null || reducer == null) |
3519 |
|
throw new NullPointerException(); |
3520 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3521 |
|
double r = basis; |
3522 |
|
while (it.advance() != null) |
3523 |
< |
r = reducer.apply(r, transformer.apply((K)it.nextKey)); |
3523 |
> |
r = reducer.applyAsDouble(r, transformer.applyAsDouble((K)it.nextKey)); |
3524 |
|
return r; |
3525 |
|
} |
3526 |
|
|
3537 |
|
* of all keys |
3538 |
|
*/ |
3539 |
|
@SuppressWarnings("unchecked") public long reduceKeysToLongSequentially |
3540 |
< |
(ObjectToLong<? super K> transformer, |
3540 |
> |
(LongFunction<? super K> transformer, |
3541 |
|
long basis, |
3542 |
< |
LongByLongToLong reducer) { |
3542 |
> |
LongBinaryOperator reducer) { |
3543 |
|
if (transformer == null || reducer == null) |
3544 |
|
throw new NullPointerException(); |
3545 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3546 |
|
long r = basis; |
3547 |
|
while (it.advance() != null) |
3548 |
< |
r = reducer.apply(r, transformer.apply((K)it.nextKey)); |
3548 |
> |
r = reducer.applyAsLong(r, transformer.applyAsLong((K)it.nextKey)); |
3549 |
|
return r; |
3550 |
|
} |
3551 |
|
|
3562 |
|
* of all keys |
3563 |
|
*/ |
3564 |
|
@SuppressWarnings("unchecked") public int reduceKeysToIntSequentially |
3565 |
< |
(ObjectToInt<? super K> transformer, |
3565 |
> |
(IntFunction<? super K> transformer, |
3566 |
|
int basis, |
3567 |
< |
IntByIntToInt reducer) { |
3567 |
> |
IntBinaryOperator reducer) { |
3568 |
|
if (transformer == null || reducer == null) |
3569 |
|
throw new NullPointerException(); |
3570 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3571 |
|
int r = basis; |
3572 |
|
while (it.advance() != null) |
3573 |
< |
r = reducer.apply(r, transformer.apply((K)it.nextKey)); |
3573 |
> |
r = reducer.applyAsInt(r, transformer.applyAsInt((K)it.nextKey)); |
3574 |
|
return r; |
3575 |
|
} |
3576 |
|
|
3579 |
|
* |
3580 |
|
* @param action the action |
3581 |
|
*/ |
3582 |
< |
public void forEachValueSequentially(Action<V> action) { |
3582 |
> |
public void forEachValueSequentially(Block<? super V> action) { |
3583 |
|
if (action == null) throw new NullPointerException(); |
3584 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3585 |
|
V v; |
3586 |
|
while ((v = it.advance()) != null) |
3587 |
< |
action.apply(v); |
3587 |
> |
action.accept(v); |
3588 |
|
} |
3589 |
|
|
3590 |
|
/** |
3596 |
|
* which case the action is not applied). |
3597 |
|
*/ |
3598 |
|
public <U> void forEachValueSequentially |
3599 |
< |
(Fun<? super V, ? extends U> transformer, |
3600 |
< |
Action<U> action) { |
3599 |
> |
(Function<? super V, ? extends U> transformer, |
3600 |
> |
Block<? super U> action) { |
3601 |
|
if (transformer == null || action == null) |
3602 |
|
throw new NullPointerException(); |
3603 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3604 |
|
V v; U u; |
3605 |
|
while ((v = it.advance()) != null) { |
3606 |
|
if ((u = transformer.apply(v)) != null) |
3607 |
< |
action.apply(u); |
3607 |
> |
action.accept(u); |
3608 |
|
} |
3609 |
|
} |
3610 |
|
|
3619 |
|
* |
3620 |
|
*/ |
3621 |
|
public <U> U searchValuesSequentially |
3622 |
< |
(Fun<? super V, ? extends U> searchFunction) { |
3622 |
> |
(Function<? super V, ? extends U> searchFunction) { |
3623 |
|
if (searchFunction == null) throw new NullPointerException(); |
3624 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3625 |
|
V v; U u; |
3638 |
|
* @return the result of accumulating all values |
3639 |
|
*/ |
3640 |
|
public V reduceValuesSequentially |
3641 |
< |
(BiFun<? super V, ? super V, ? extends V> reducer) { |
3641 |
> |
(BiFunction<? super V, ? super V, ? extends V> reducer) { |
3642 |
|
if (reducer == null) throw new NullPointerException(); |
3643 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3644 |
|
V r = null; V v; |
3660 |
|
* of all values |
3661 |
|
*/ |
3662 |
|
public <U> U reduceValuesSequentially |
3663 |
< |
(Fun<? super V, ? extends U> transformer, |
3664 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
3663 |
> |
(Function<? super V, ? extends U> transformer, |
3664 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
3665 |
|
if (transformer == null || reducer == null) |
3666 |
|
throw new NullPointerException(); |
3667 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3686 |
|
* of all values |
3687 |
|
*/ |
3688 |
|
public double reduceValuesToDoubleSequentially |
3689 |
< |
(ObjectToDouble<? super V> transformer, |
3689 |
> |
(DoubleFunction<? super V> transformer, |
3690 |
|
double basis, |
3691 |
< |
DoubleByDoubleToDouble reducer) { |
3691 |
> |
DoubleBinaryOperator reducer) { |
3692 |
|
if (transformer == null || reducer == null) |
3693 |
|
throw new NullPointerException(); |
3694 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3695 |
|
double r = basis; V v; |
3696 |
|
while ((v = it.advance()) != null) |
3697 |
< |
r = reducer.apply(r, transformer.apply(v)); |
3697 |
> |
r = reducer.applyAsDouble(r, transformer.applyAsDouble(v)); |
3698 |
|
return r; |
3699 |
|
} |
3700 |
|
|
3711 |
|
* of all values |
3712 |
|
*/ |
3713 |
|
public long reduceValuesToLongSequentially |
3714 |
< |
(ObjectToLong<? super V> transformer, |
3714 |
> |
(LongFunction<? super V> transformer, |
3715 |
|
long basis, |
3716 |
< |
LongByLongToLong reducer) { |
3716 |
> |
LongBinaryOperator reducer) { |
3717 |
|
if (transformer == null || reducer == null) |
3718 |
|
throw new NullPointerException(); |
3719 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3720 |
|
long r = basis; V v; |
3721 |
|
while ((v = it.advance()) != null) |
3722 |
< |
r = reducer.apply(r, transformer.apply(v)); |
3722 |
> |
r = reducer.applyAsLong(r, transformer.applyAsLong(v)); |
3723 |
|
return r; |
3724 |
|
} |
3725 |
|
|
3736 |
|
* of all values |
3737 |
|
*/ |
3738 |
|
public int reduceValuesToIntSequentially |
3739 |
< |
(ObjectToInt<? super V> transformer, |
3739 |
> |
(IntFunction<? super V> transformer, |
3740 |
|
int basis, |
3741 |
< |
IntByIntToInt reducer) { |
3741 |
> |
IntBinaryOperator reducer) { |
3742 |
|
if (transformer == null || reducer == null) |
3743 |
|
throw new NullPointerException(); |
3744 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3745 |
|
int r = basis; V v; |
3746 |
|
while ((v = it.advance()) != null) |
3747 |
< |
r = reducer.apply(r, transformer.apply(v)); |
3747 |
> |
r = reducer.applyAsInt(r, transformer.applyAsInt(v)); |
3748 |
|
return r; |
3749 |
|
} |
3750 |
|
|
3754 |
|
* @param action the action |
3755 |
|
*/ |
3756 |
|
@SuppressWarnings("unchecked") public void forEachEntrySequentially |
3757 |
< |
(Action<Map.Entry<K,V>> action) { |
3757 |
> |
(Block<? super Map.Entry<K,V>> action) { |
3758 |
|
if (action == null) throw new NullPointerException(); |
3759 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3760 |
|
V v; |
3761 |
|
while ((v = it.advance()) != null) |
3762 |
< |
action.apply(entryFor((K)it.nextKey, v)); |
3762 |
> |
action.accept(entryFor((K)it.nextKey, v)); |
3763 |
|
} |
3764 |
|
|
3765 |
|
/** |
3772 |
|
* @param action the action |
3773 |
|
*/ |
3774 |
|
@SuppressWarnings("unchecked") public <U> void forEachEntrySequentially |
3775 |
< |
(Fun<Map.Entry<K,V>, ? extends U> transformer, |
3776 |
< |
Action<U> action) { |
3775 |
> |
(Function<Map.Entry<K,V>, ? extends U> transformer, |
3776 |
> |
Block<? super U> action) { |
3777 |
|
if (transformer == null || action == null) |
3778 |
|
throw new NullPointerException(); |
3779 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3780 |
|
V v; U u; |
3781 |
|
while ((v = it.advance()) != null) { |
3782 |
|
if ((u = transformer.apply(entryFor((K)it.nextKey, v))) != null) |
3783 |
< |
action.apply(u); |
3783 |
> |
action.accept(u); |
3784 |
|
} |
3785 |
|
} |
3786 |
|
|
3794 |
|
* function on each entry, or null if none |
3795 |
|
*/ |
3796 |
|
@SuppressWarnings("unchecked") public <U> U searchEntriesSequentially |
3797 |
< |
(Fun<Map.Entry<K,V>, ? extends U> searchFunction) { |
3797 |
> |
(Function<Map.Entry<K,V>, ? extends U> searchFunction) { |
3798 |
|
if (searchFunction == null) throw new NullPointerException(); |
3799 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3800 |
|
V v; U u; |
3813 |
|
* @return the result of accumulating all entries |
3814 |
|
*/ |
3815 |
|
@SuppressWarnings("unchecked") public Map.Entry<K,V> reduceEntriesSequentially |
3816 |
< |
(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
3816 |
> |
(BiFunction<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
3817 |
|
if (reducer == null) throw new NullPointerException(); |
3818 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3819 |
|
Map.Entry<K,V> r = null; V v; |
3837 |
|
* of all entries |
3838 |
|
*/ |
3839 |
|
@SuppressWarnings("unchecked") public <U> U reduceEntriesSequentially |
3840 |
< |
(Fun<Map.Entry<K,V>, ? extends U> transformer, |
3841 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
3840 |
> |
(Function<Map.Entry<K,V>, ? extends U> transformer, |
3841 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
3842 |
|
if (transformer == null || reducer == null) |
3843 |
|
throw new NullPointerException(); |
3844 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3863 |
|
* of all entries |
3864 |
|
*/ |
3865 |
|
@SuppressWarnings("unchecked") public double reduceEntriesToDoubleSequentially |
3866 |
< |
(ObjectToDouble<Map.Entry<K,V>> transformer, |
3866 |
> |
(DoubleFunction<Map.Entry<K,V>> transformer, |
3867 |
|
double basis, |
3868 |
< |
DoubleByDoubleToDouble reducer) { |
3868 |
> |
DoubleBinaryOperator reducer) { |
3869 |
|
if (transformer == null || reducer == null) |
3870 |
|
throw new NullPointerException(); |
3871 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3872 |
|
double r = basis; V v; |
3873 |
|
while ((v = it.advance()) != null) |
3874 |
< |
r = reducer.apply(r, transformer.apply(entryFor((K)it.nextKey, v))); |
3874 |
> |
r = reducer.applyAsDouble(r, transformer.applyAsDouble(entryFor((K)it.nextKey, v))); |
3875 |
|
return r; |
3876 |
|
} |
3877 |
|
|
3888 |
|
* of all entries |
3889 |
|
*/ |
3890 |
|
@SuppressWarnings("unchecked") public long reduceEntriesToLongSequentially |
3891 |
< |
(ObjectToLong<Map.Entry<K,V>> transformer, |
3891 |
> |
(LongFunction<Map.Entry<K,V>> transformer, |
3892 |
|
long basis, |
3893 |
< |
LongByLongToLong reducer) { |
3893 |
> |
LongBinaryOperator reducer) { |
3894 |
|
if (transformer == null || reducer == null) |
3895 |
|
throw new NullPointerException(); |
3896 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3897 |
|
long r = basis; V v; |
3898 |
|
while ((v = it.advance()) != null) |
3899 |
< |
r = reducer.apply(r, transformer.apply(entryFor((K)it.nextKey, v))); |
3899 |
> |
r = reducer.applyAsLong(r, transformer.applyAsLong(entryFor((K)it.nextKey, v))); |
3900 |
|
return r; |
3901 |
|
} |
3902 |
|
|
3913 |
|
* of all entries |
3914 |
|
*/ |
3915 |
|
@SuppressWarnings("unchecked") public int reduceEntriesToIntSequentially |
3916 |
< |
(ObjectToInt<Map.Entry<K,V>> transformer, |
3916 |
> |
(IntFunction<Map.Entry<K,V>> transformer, |
3917 |
|
int basis, |
3918 |
< |
IntByIntToInt reducer) { |
3918 |
> |
IntBinaryOperator reducer) { |
3919 |
|
if (transformer == null || reducer == null) |
3920 |
|
throw new NullPointerException(); |
3921 |
|
Traverser<K,V,Object> it = new Traverser<K,V,Object>(this); |
3922 |
|
int r = basis; V v; |
3923 |
|
while ((v = it.advance()) != null) |
3924 |
< |
r = reducer.apply(r, transformer.apply(entryFor((K)it.nextKey, v))); |
3924 |
> |
r = reducer.applyAsInt(r, transformer.applyAsInt(entryFor((K)it.nextKey, v))); |
3925 |
|
return r; |
3926 |
|
} |
3927 |
|
|
3932 |
|
* |
3933 |
|
* @param action the action |
3934 |
|
*/ |
3935 |
< |
public void forEachInParallel(BiAction<K,V> action) { |
3935 |
> |
public void forEachInParallel(BiBlock<? super K,? super V> action) { |
3936 |
|
ForkJoinTasks.forEach |
3937 |
|
(this, action).invoke(); |
3938 |
|
} |
3947 |
|
* @param action the action |
3948 |
|
*/ |
3949 |
|
public <U> void forEachInParallel |
3950 |
< |
(BiFun<? super K, ? super V, ? extends U> transformer, |
3951 |
< |
Action<U> action) { |
3950 |
> |
(BiFunction<? super K, ? super V, ? extends U> transformer, |
3951 |
> |
Block<? super U> action) { |
3952 |
|
ForkJoinTasks.forEach |
3953 |
|
(this, transformer, action).invoke(); |
3954 |
|
} |
3966 |
|
* function on each (key, value), or null if none |
3967 |
|
*/ |
3968 |
|
public <U> U searchInParallel |
3969 |
< |
(BiFun<? super K, ? super V, ? extends U> searchFunction) { |
3969 |
> |
(BiFunction<? super K, ? super V, ? extends U> searchFunction) { |
3970 |
|
return ForkJoinTasks.search |
3971 |
|
(this, searchFunction).invoke(); |
3972 |
|
} |
3984 |
|
* of all (key, value) pairs |
3985 |
|
*/ |
3986 |
|
public <U> U reduceInParallel |
3987 |
< |
(BiFun<? super K, ? super V, ? extends U> transformer, |
3988 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
3987 |
> |
(BiFunction<? super K, ? super V, ? extends U> transformer, |
3988 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
3989 |
|
return ForkJoinTasks.reduce |
3990 |
|
(this, transformer, reducer).invoke(); |
3991 |
|
} |
4003 |
|
* of all (key, value) pairs |
4004 |
|
*/ |
4005 |
|
public double reduceToDoubleInParallel |
4006 |
< |
(ObjectByObjectToDouble<? super K, ? super V> transformer, |
4006 |
> |
(DoubleBiFunction<? super K, ? super V> transformer, |
4007 |
|
double basis, |
4008 |
< |
DoubleByDoubleToDouble reducer) { |
4008 |
> |
DoubleBinaryOperator reducer) { |
4009 |
|
return ForkJoinTasks.reduceToDouble |
4010 |
|
(this, transformer, basis, reducer).invoke(); |
4011 |
|
} |
4023 |
|
* of all (key, value) pairs |
4024 |
|
*/ |
4025 |
|
public long reduceToLongInParallel |
4026 |
< |
(ObjectByObjectToLong<? super K, ? super V> transformer, |
4026 |
> |
(LongBiFunction<? super K, ? super V> transformer, |
4027 |
|
long basis, |
4028 |
< |
LongByLongToLong reducer) { |
4028 |
> |
LongBinaryOperator reducer) { |
4029 |
|
return ForkJoinTasks.reduceToLong |
4030 |
|
(this, transformer, basis, reducer).invoke(); |
4031 |
|
} |
4043 |
|
* of all (key, value) pairs |
4044 |
|
*/ |
4045 |
|
public int reduceToIntInParallel |
4046 |
< |
(ObjectByObjectToInt<? super K, ? super V> transformer, |
4046 |
> |
(IntBiFunction<? super K, ? super V> transformer, |
4047 |
|
int basis, |
4048 |
< |
IntByIntToInt reducer) { |
4048 |
> |
IntBinaryOperator reducer) { |
4049 |
|
return ForkJoinTasks.reduceToInt |
4050 |
|
(this, transformer, basis, reducer).invoke(); |
4051 |
|
} |
4055 |
|
* |
4056 |
|
* @param action the action |
4057 |
|
*/ |
4058 |
< |
public void forEachKeyInParallel(Action<K> action) { |
4058 |
> |
public void forEachKeyInParallel(Block<? super K> action) { |
4059 |
|
ForkJoinTasks.forEachKey |
4060 |
|
(this, action).invoke(); |
4061 |
|
} |
4070 |
|
* @param action the action |
4071 |
|
*/ |
4072 |
|
public <U> void forEachKeyInParallel |
4073 |
< |
(Fun<? super K, ? extends U> transformer, |
4074 |
< |
Action<U> action) { |
4073 |
> |
(Function<? super K, ? extends U> transformer, |
4074 |
> |
Block<? super U> action) { |
4075 |
|
ForkJoinTasks.forEachKey |
4076 |
|
(this, transformer, action).invoke(); |
4077 |
|
} |
4089 |
|
* function on each key, or null if none |
4090 |
|
*/ |
4091 |
|
public <U> U searchKeysInParallel |
4092 |
< |
(Fun<? super K, ? extends U> searchFunction) { |
4092 |
> |
(Function<? super K, ? extends U> searchFunction) { |
4093 |
|
return ForkJoinTasks.searchKeys |
4094 |
|
(this, searchFunction).invoke(); |
4095 |
|
} |
4103 |
|
* reducer to combine values, or null if none |
4104 |
|
*/ |
4105 |
|
public K reduceKeysInParallel |
4106 |
< |
(BiFun<? super K, ? super K, ? extends K> reducer) { |
4106 |
> |
(BiFunction<? super K, ? super K, ? extends K> reducer) { |
4107 |
|
return ForkJoinTasks.reduceKeys |
4108 |
|
(this, reducer).invoke(); |
4109 |
|
} |
4121 |
|
* of all keys |
4122 |
|
*/ |
4123 |
|
public <U> U reduceKeysInParallel |
4124 |
< |
(Fun<? super K, ? extends U> transformer, |
4125 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4124 |
> |
(Function<? super K, ? extends U> transformer, |
4125 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
4126 |
|
return ForkJoinTasks.reduceKeys |
4127 |
|
(this, transformer, reducer).invoke(); |
4128 |
|
} |
4140 |
|
* of all keys |
4141 |
|
*/ |
4142 |
|
public double reduceKeysToDoubleInParallel |
4143 |
< |
(ObjectToDouble<? super K> transformer, |
4143 |
> |
(DoubleFunction<? super K> transformer, |
4144 |
|
double basis, |
4145 |
< |
DoubleByDoubleToDouble reducer) { |
4145 |
> |
DoubleBinaryOperator reducer) { |
4146 |
|
return ForkJoinTasks.reduceKeysToDouble |
4147 |
|
(this, transformer, basis, reducer).invoke(); |
4148 |
|
} |
4160 |
|
* of all keys |
4161 |
|
*/ |
4162 |
|
public long reduceKeysToLongInParallel |
4163 |
< |
(ObjectToLong<? super K> transformer, |
4163 |
> |
(LongFunction<? super K> transformer, |
4164 |
|
long basis, |
4165 |
< |
LongByLongToLong reducer) { |
4165 |
> |
LongBinaryOperator reducer) { |
4166 |
|
return ForkJoinTasks.reduceKeysToLong |
4167 |
|
(this, transformer, basis, reducer).invoke(); |
4168 |
|
} |
4180 |
|
* of all keys |
4181 |
|
*/ |
4182 |
|
public int reduceKeysToIntInParallel |
4183 |
< |
(ObjectToInt<? super K> transformer, |
4183 |
> |
(IntFunction<? super K> transformer, |
4184 |
|
int basis, |
4185 |
< |
IntByIntToInt reducer) { |
4185 |
> |
IntBinaryOperator reducer) { |
4186 |
|
return ForkJoinTasks.reduceKeysToInt |
4187 |
|
(this, transformer, basis, reducer).invoke(); |
4188 |
|
} |
4192 |
|
* |
4193 |
|
* @param action the action |
4194 |
|
*/ |
4195 |
< |
public void forEachValueInParallel(Action<V> action) { |
4195 |
> |
public void forEachValueInParallel(Block<? super V> action) { |
4196 |
|
ForkJoinTasks.forEachValue |
4197 |
|
(this, action).invoke(); |
4198 |
|
} |
4206 |
|
* which case the action is not applied). |
4207 |
|
*/ |
4208 |
|
public <U> void forEachValueInParallel |
4209 |
< |
(Fun<? super V, ? extends U> transformer, |
4210 |
< |
Action<U> action) { |
4209 |
> |
(Function<? super V, ? extends U> transformer, |
4210 |
> |
Block<? super U> action) { |
4211 |
|
ForkJoinTasks.forEachValue |
4212 |
|
(this, transformer, action).invoke(); |
4213 |
|
} |
4226 |
|
* |
4227 |
|
*/ |
4228 |
|
public <U> U searchValuesInParallel |
4229 |
< |
(Fun<? super V, ? extends U> searchFunction) { |
4229 |
> |
(Function<? super V, ? extends U> searchFunction) { |
4230 |
|
return ForkJoinTasks.searchValues |
4231 |
|
(this, searchFunction).invoke(); |
4232 |
|
} |
4239 |
|
* @return the result of accumulating all values |
4240 |
|
*/ |
4241 |
|
public V reduceValuesInParallel |
4242 |
< |
(BiFun<? super V, ? super V, ? extends V> reducer) { |
4242 |
> |
(BiFunction<? super V, ? super V, ? extends V> reducer) { |
4243 |
|
return ForkJoinTasks.reduceValues |
4244 |
|
(this, reducer).invoke(); |
4245 |
|
} |
4257 |
|
* of all values |
4258 |
|
*/ |
4259 |
|
public <U> U reduceValuesInParallel |
4260 |
< |
(Fun<? super V, ? extends U> transformer, |
4261 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4260 |
> |
(Function<? super V, ? extends U> transformer, |
4261 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
4262 |
|
return ForkJoinTasks.reduceValues |
4263 |
|
(this, transformer, reducer).invoke(); |
4264 |
|
} |
4276 |
|
* of all values |
4277 |
|
*/ |
4278 |
|
public double reduceValuesToDoubleInParallel |
4279 |
< |
(ObjectToDouble<? super V> transformer, |
4279 |
> |
(DoubleFunction<? super V> transformer, |
4280 |
|
double basis, |
4281 |
< |
DoubleByDoubleToDouble reducer) { |
4281 |
> |
DoubleBinaryOperator reducer) { |
4282 |
|
return ForkJoinTasks.reduceValuesToDouble |
4283 |
|
(this, transformer, basis, reducer).invoke(); |
4284 |
|
} |
4296 |
|
* of all values |
4297 |
|
*/ |
4298 |
|
public long reduceValuesToLongInParallel |
4299 |
< |
(ObjectToLong<? super V> transformer, |
4299 |
> |
(LongFunction<? super V> transformer, |
4300 |
|
long basis, |
4301 |
< |
LongByLongToLong reducer) { |
4301 |
> |
LongBinaryOperator reducer) { |
4302 |
|
return ForkJoinTasks.reduceValuesToLong |
4303 |
|
(this, transformer, basis, reducer).invoke(); |
4304 |
|
} |
4316 |
|
* of all values |
4317 |
|
*/ |
4318 |
|
public int reduceValuesToIntInParallel |
4319 |
< |
(ObjectToInt<? super V> transformer, |
4319 |
> |
(IntFunction<? super V> transformer, |
4320 |
|
int basis, |
4321 |
< |
IntByIntToInt reducer) { |
4321 |
> |
IntBinaryOperator reducer) { |
4322 |
|
return ForkJoinTasks.reduceValuesToInt |
4323 |
|
(this, transformer, basis, reducer).invoke(); |
4324 |
|
} |
4328 |
|
* |
4329 |
|
* @param action the action |
4330 |
|
*/ |
4331 |
< |
public void forEachEntryInParallel(Action<Map.Entry<K,V>> action) { |
4331 |
> |
public void forEachEntryInParallel(Block<? super Map.Entry<K,V>> action) { |
4332 |
|
ForkJoinTasks.forEachEntry |
4333 |
|
(this, action).invoke(); |
4334 |
|
} |
4343 |
|
* @param action the action |
4344 |
|
*/ |
4345 |
|
public <U> void forEachEntryInParallel |
4346 |
< |
(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4347 |
< |
Action<U> action) { |
4346 |
> |
(Function<Map.Entry<K,V>, ? extends U> transformer, |
4347 |
> |
Block<? super U> action) { |
4348 |
|
ForkJoinTasks.forEachEntry |
4349 |
|
(this, transformer, action).invoke(); |
4350 |
|
} |
4362 |
|
* function on each entry, or null if none |
4363 |
|
*/ |
4364 |
|
public <U> U searchEntriesInParallel |
4365 |
< |
(Fun<Map.Entry<K,V>, ? extends U> searchFunction) { |
4365 |
> |
(Function<Map.Entry<K,V>, ? extends U> searchFunction) { |
4366 |
|
return ForkJoinTasks.searchEntries |
4367 |
|
(this, searchFunction).invoke(); |
4368 |
|
} |
4375 |
|
* @return the result of accumulating all entries |
4376 |
|
*/ |
4377 |
|
public Map.Entry<K,V> reduceEntriesInParallel |
4378 |
< |
(BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
4378 |
> |
(BiFunction<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
4379 |
|
return ForkJoinTasks.reduceEntries |
4380 |
|
(this, reducer).invoke(); |
4381 |
|
} |
4393 |
|
* of all entries |
4394 |
|
*/ |
4395 |
|
public <U> U reduceEntriesInParallel |
4396 |
< |
(Fun<Map.Entry<K,V>, ? extends U> transformer, |
4397 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4396 |
> |
(Function<Map.Entry<K,V>, ? extends U> transformer, |
4397 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
4398 |
|
return ForkJoinTasks.reduceEntries |
4399 |
|
(this, transformer, reducer).invoke(); |
4400 |
|
} |
4412 |
|
* of all entries |
4413 |
|
*/ |
4414 |
|
public double reduceEntriesToDoubleInParallel |
4415 |
< |
(ObjectToDouble<Map.Entry<K,V>> transformer, |
4415 |
> |
(DoubleFunction<Map.Entry<K,V>> transformer, |
4416 |
|
double basis, |
4417 |
< |
DoubleByDoubleToDouble reducer) { |
4417 |
> |
DoubleBinaryOperator reducer) { |
4418 |
|
return ForkJoinTasks.reduceEntriesToDouble |
4419 |
|
(this, transformer, basis, reducer).invoke(); |
4420 |
|
} |
4432 |
|
* of all entries |
4433 |
|
*/ |
4434 |
|
public long reduceEntriesToLongInParallel |
4435 |
< |
(ObjectToLong<Map.Entry<K,V>> transformer, |
4435 |
> |
(LongFunction<Map.Entry<K,V>> transformer, |
4436 |
|
long basis, |
4437 |
< |
LongByLongToLong reducer) { |
4437 |
> |
LongBinaryOperator reducer) { |
4438 |
|
return ForkJoinTasks.reduceEntriesToLong |
4439 |
|
(this, transformer, basis, reducer).invoke(); |
4440 |
|
} |
4452 |
|
* of all entries |
4453 |
|
*/ |
4454 |
|
public int reduceEntriesToIntInParallel |
4455 |
< |
(ObjectToInt<Map.Entry<K,V>> transformer, |
4455 |
> |
(IntFunction<Map.Entry<K,V>> transformer, |
4456 |
|
int basis, |
4457 |
< |
IntByIntToInt reducer) { |
4457 |
> |
IntBinaryOperator reducer) { |
4458 |
|
return ForkJoinTasks.reduceEntriesToInt |
4459 |
|
(this, transformer, basis, reducer).invoke(); |
4460 |
|
} |
4666 |
|
((c = (Set<?>)o) == this || |
4667 |
|
(containsAll(c) && c.containsAll(this)))); |
4668 |
|
} |
4669 |
+ |
|
4670 |
+ |
public Stream<K> stream() { |
4671 |
+ |
return Streams.stream(() -> new KeyIterator<K,V>(map), 0); |
4672 |
+ |
} |
4673 |
+ |
public Stream<K> parallelStream() { |
4674 |
+ |
return Streams.parallelStream(() -> new KeyIterator<K,V>(map, null), |
4675 |
+ |
0); |
4676 |
+ |
} |
4677 |
|
} |
4678 |
|
|
4679 |
|
/** |
4724 |
|
throw new UnsupportedOperationException(); |
4725 |
|
} |
4726 |
|
|
4727 |
+ |
public Stream<V> stream() { |
4728 |
+ |
return Streams.stream(() -> new ValueIterator<K,V>(map), 0); |
4729 |
+ |
} |
4730 |
+ |
|
4731 |
+ |
public Stream<V> parallelStream() { |
4732 |
+ |
return Streams.parallelStream(() -> new ValueIterator<K,V>(map, null), |
4733 |
+ |
0); |
4734 |
+ |
} |
4735 |
+ |
|
4736 |
|
} |
4737 |
|
|
4738 |
|
/** |
4794 |
|
((c = (Set<?>)o) == this || |
4795 |
|
(containsAll(c) && c.containsAll(this)))); |
4796 |
|
} |
4797 |
+ |
|
4798 |
+ |
public Stream<Map.Entry<K,V>> stream() { |
4799 |
+ |
return Streams.stream(() -> new EntryIterator<K,V>(map), 0); |
4800 |
+ |
} |
4801 |
+ |
|
4802 |
+ |
public Stream<Map.Entry<K,V>> parallelStream() { |
4803 |
+ |
return Streams.parallelStream(() -> new EntryIterator<K,V>(map, null), |
4804 |
+ |
0); |
4805 |
+ |
} |
4806 |
|
} |
4807 |
|
|
4808 |
|
// --------------------------------------------------------------------- |
4829 |
|
*/ |
4830 |
|
public static <K,V> ForkJoinTask<Void> forEach |
4831 |
|
(ConcurrentHashMap<K,V> map, |
4832 |
< |
BiAction<K,V> action) { |
4832 |
> |
BiBlock<? super K, ? super V> action) { |
4833 |
|
if (action == null) throw new NullPointerException(); |
4834 |
|
return new ForEachMappingTask<K,V>(map, null, -1, action); |
4835 |
|
} |
4847 |
|
*/ |
4848 |
|
public static <K,V,U> ForkJoinTask<Void> forEach |
4849 |
|
(ConcurrentHashMap<K,V> map, |
4850 |
< |
BiFun<? super K, ? super V, ? extends U> transformer, |
4851 |
< |
Action<U> action) { |
4850 |
> |
BiFunction<? super K, ? super V, ? extends U> transformer, |
4851 |
> |
Block<? super U> action) { |
4852 |
|
if (transformer == null || action == null) |
4853 |
|
throw new NullPointerException(); |
4854 |
|
return new ForEachTransformedMappingTask<K,V,U> |
4869 |
|
*/ |
4870 |
|
public static <K,V,U> ForkJoinTask<U> search |
4871 |
|
(ConcurrentHashMap<K,V> map, |
4872 |
< |
BiFun<? super K, ? super V, ? extends U> searchFunction) { |
4872 |
> |
BiFunction<? super K, ? super V, ? extends U> searchFunction) { |
4873 |
|
if (searchFunction == null) throw new NullPointerException(); |
4874 |
|
return new SearchMappingsTask<K,V,U> |
4875 |
|
(map, null, -1, searchFunction, |
4890 |
|
*/ |
4891 |
|
public static <K,V,U> ForkJoinTask<U> reduce |
4892 |
|
(ConcurrentHashMap<K,V> map, |
4893 |
< |
BiFun<? super K, ? super V, ? extends U> transformer, |
4894 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
4893 |
> |
BiFunction<? super K, ? super V, ? extends U> transformer, |
4894 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
4895 |
|
if (transformer == null || reducer == null) |
4896 |
|
throw new NullPointerException(); |
4897 |
|
return new MapReduceMappingsTask<K,V,U> |
4913 |
|
*/ |
4914 |
|
public static <K,V> ForkJoinTask<Double> reduceToDouble |
4915 |
|
(ConcurrentHashMap<K,V> map, |
4916 |
< |
ObjectByObjectToDouble<? super K, ? super V> transformer, |
4916 |
> |
DoubleBiFunction<? super K, ? super V> transformer, |
4917 |
|
double basis, |
4918 |
< |
DoubleByDoubleToDouble reducer) { |
4918 |
> |
DoubleBinaryOperator reducer) { |
4919 |
|
if (transformer == null || reducer == null) |
4920 |
|
throw new NullPointerException(); |
4921 |
|
return new MapReduceMappingsToDoubleTask<K,V> |
4937 |
|
*/ |
4938 |
|
public static <K,V> ForkJoinTask<Long> reduceToLong |
4939 |
|
(ConcurrentHashMap<K,V> map, |
4940 |
< |
ObjectByObjectToLong<? super K, ? super V> transformer, |
4940 |
> |
LongBiFunction<? super K, ? super V> transformer, |
4941 |
|
long basis, |
4942 |
< |
LongByLongToLong reducer) { |
4942 |
> |
LongBinaryOperator reducer) { |
4943 |
|
if (transformer == null || reducer == null) |
4944 |
|
throw new NullPointerException(); |
4945 |
|
return new MapReduceMappingsToLongTask<K,V> |
4960 |
|
*/ |
4961 |
|
public static <K,V> ForkJoinTask<Integer> reduceToInt |
4962 |
|
(ConcurrentHashMap<K,V> map, |
4963 |
< |
ObjectByObjectToInt<? super K, ? super V> transformer, |
4963 |
> |
IntBiFunction<? super K, ? super V> transformer, |
4964 |
|
int basis, |
4965 |
< |
IntByIntToInt reducer) { |
4965 |
> |
IntBinaryOperator reducer) { |
4966 |
|
if (transformer == null || reducer == null) |
4967 |
|
throw new NullPointerException(); |
4968 |
|
return new MapReduceMappingsToIntTask<K,V> |
4979 |
|
*/ |
4980 |
|
public static <K,V> ForkJoinTask<Void> forEachKey |
4981 |
|
(ConcurrentHashMap<K,V> map, |
4982 |
< |
Action<K> action) { |
4982 |
> |
Block<? super K> action) { |
4983 |
|
if (action == null) throw new NullPointerException(); |
4984 |
|
return new ForEachKeyTask<K,V>(map, null, -1, action); |
4985 |
|
} |
4997 |
|
*/ |
4998 |
|
public static <K,V,U> ForkJoinTask<Void> forEachKey |
4999 |
|
(ConcurrentHashMap<K,V> map, |
5000 |
< |
Fun<? super K, ? extends U> transformer, |
5001 |
< |
Action<U> action) { |
5000 |
> |
Function<? super K, ? extends U> transformer, |
5001 |
> |
Block<? super U> action) { |
5002 |
|
if (transformer == null || action == null) |
5003 |
|
throw new NullPointerException(); |
5004 |
|
return new ForEachTransformedKeyTask<K,V,U> |
5019 |
|
*/ |
5020 |
|
public static <K,V,U> ForkJoinTask<U> searchKeys |
5021 |
|
(ConcurrentHashMap<K,V> map, |
5022 |
< |
Fun<? super K, ? extends U> searchFunction) { |
5022 |
> |
Function<? super K, ? extends U> searchFunction) { |
5023 |
|
if (searchFunction == null) throw new NullPointerException(); |
5024 |
|
return new SearchKeysTask<K,V,U> |
5025 |
|
(map, null, -1, searchFunction, |
5037 |
|
*/ |
5038 |
|
public static <K,V> ForkJoinTask<K> reduceKeys |
5039 |
|
(ConcurrentHashMap<K,V> map, |
5040 |
< |
BiFun<? super K, ? super K, ? extends K> reducer) { |
5040 |
> |
BiFunction<? super K, ? super K, ? extends K> reducer) { |
5041 |
|
if (reducer == null) throw new NullPointerException(); |
5042 |
|
return new ReduceKeysTask<K,V> |
5043 |
|
(map, null, -1, null, reducer); |
5057 |
|
*/ |
5058 |
|
public static <K,V,U> ForkJoinTask<U> reduceKeys |
5059 |
|
(ConcurrentHashMap<K,V> map, |
5060 |
< |
Fun<? super K, ? extends U> transformer, |
5061 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
5060 |
> |
Function<? super K, ? extends U> transformer, |
5061 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
5062 |
|
if (transformer == null || reducer == null) |
5063 |
|
throw new NullPointerException(); |
5064 |
|
return new MapReduceKeysTask<K,V,U> |
5080 |
|
*/ |
5081 |
|
public static <K,V> ForkJoinTask<Double> reduceKeysToDouble |
5082 |
|
(ConcurrentHashMap<K,V> map, |
5083 |
< |
ObjectToDouble<? super K> transformer, |
5083 |
> |
DoubleFunction<? super K> transformer, |
5084 |
|
double basis, |
5085 |
< |
DoubleByDoubleToDouble reducer) { |
5085 |
> |
DoubleBinaryOperator reducer) { |
5086 |
|
if (transformer == null || reducer == null) |
5087 |
|
throw new NullPointerException(); |
5088 |
|
return new MapReduceKeysToDoubleTask<K,V> |
5104 |
|
*/ |
5105 |
|
public static <K,V> ForkJoinTask<Long> reduceKeysToLong |
5106 |
|
(ConcurrentHashMap<K,V> map, |
5107 |
< |
ObjectToLong<? super K> transformer, |
5107 |
> |
LongFunction<? super K> transformer, |
5108 |
|
long basis, |
5109 |
< |
LongByLongToLong reducer) { |
5109 |
> |
LongBinaryOperator reducer) { |
5110 |
|
if (transformer == null || reducer == null) |
5111 |
|
throw new NullPointerException(); |
5112 |
|
return new MapReduceKeysToLongTask<K,V> |
5128 |
|
*/ |
5129 |
|
public static <K,V> ForkJoinTask<Integer> reduceKeysToInt |
5130 |
|
(ConcurrentHashMap<K,V> map, |
5131 |
< |
ObjectToInt<? super K> transformer, |
5131 |
> |
IntFunction<? super K> transformer, |
5132 |
|
int basis, |
5133 |
< |
IntByIntToInt reducer) { |
5133 |
> |
IntBinaryOperator reducer) { |
5134 |
|
if (transformer == null || reducer == null) |
5135 |
|
throw new NullPointerException(); |
5136 |
|
return new MapReduceKeysToIntTask<K,V> |
5146 |
|
*/ |
5147 |
|
public static <K,V> ForkJoinTask<Void> forEachValue |
5148 |
|
(ConcurrentHashMap<K,V> map, |
5149 |
< |
Action<V> action) { |
5149 |
> |
Block<? super V> action) { |
5150 |
|
if (action == null) throw new NullPointerException(); |
5151 |
|
return new ForEachValueTask<K,V>(map, null, -1, action); |
5152 |
|
} |
5163 |
|
*/ |
5164 |
|
public static <K,V,U> ForkJoinTask<Void> forEachValue |
5165 |
|
(ConcurrentHashMap<K,V> map, |
5166 |
< |
Fun<? super V, ? extends U> transformer, |
5167 |
< |
Action<U> action) { |
5166 |
> |
Function<? super V, ? extends U> transformer, |
5167 |
> |
Block<? super U> action) { |
5168 |
|
if (transformer == null || action == null) |
5169 |
|
throw new NullPointerException(); |
5170 |
|
return new ForEachTransformedValueTask<K,V,U> |
5185 |
|
*/ |
5186 |
|
public static <K,V,U> ForkJoinTask<U> searchValues |
5187 |
|
(ConcurrentHashMap<K,V> map, |
5188 |
< |
Fun<? super V, ? extends U> searchFunction) { |
5188 |
> |
Function<? super V, ? extends U> searchFunction) { |
5189 |
|
if (searchFunction == null) throw new NullPointerException(); |
5190 |
|
return new SearchValuesTask<K,V,U> |
5191 |
|
(map, null, -1, searchFunction, |
5203 |
|
*/ |
5204 |
|
public static <K,V> ForkJoinTask<V> reduceValues |
5205 |
|
(ConcurrentHashMap<K,V> map, |
5206 |
< |
BiFun<? super V, ? super V, ? extends V> reducer) { |
5206 |
> |
BiFunction<? super V, ? super V, ? extends V> reducer) { |
5207 |
|
if (reducer == null) throw new NullPointerException(); |
5208 |
|
return new ReduceValuesTask<K,V> |
5209 |
|
(map, null, -1, null, reducer); |
5223 |
|
*/ |
5224 |
|
public static <K,V,U> ForkJoinTask<U> reduceValues |
5225 |
|
(ConcurrentHashMap<K,V> map, |
5226 |
< |
Fun<? super V, ? extends U> transformer, |
5227 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
5226 |
> |
Function<? super V, ? extends U> transformer, |
5227 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
5228 |
|
if (transformer == null || reducer == null) |
5229 |
|
throw new NullPointerException(); |
5230 |
|
return new MapReduceValuesTask<K,V,U> |
5246 |
|
*/ |
5247 |
|
public static <K,V> ForkJoinTask<Double> reduceValuesToDouble |
5248 |
|
(ConcurrentHashMap<K,V> map, |
5249 |
< |
ObjectToDouble<? super V> transformer, |
5249 |
> |
DoubleFunction<? super V> transformer, |
5250 |
|
double basis, |
5251 |
< |
DoubleByDoubleToDouble reducer) { |
5251 |
> |
DoubleBinaryOperator reducer) { |
5252 |
|
if (transformer == null || reducer == null) |
5253 |
|
throw new NullPointerException(); |
5254 |
|
return new MapReduceValuesToDoubleTask<K,V> |
5270 |
|
*/ |
5271 |
|
public static <K,V> ForkJoinTask<Long> reduceValuesToLong |
5272 |
|
(ConcurrentHashMap<K,V> map, |
5273 |
< |
ObjectToLong<? super V> transformer, |
5273 |
> |
LongFunction<? super V> transformer, |
5274 |
|
long basis, |
5275 |
< |
LongByLongToLong reducer) { |
5275 |
> |
LongBinaryOperator reducer) { |
5276 |
|
if (transformer == null || reducer == null) |
5277 |
|
throw new NullPointerException(); |
5278 |
|
return new MapReduceValuesToLongTask<K,V> |
5294 |
|
*/ |
5295 |
|
public static <K,V> ForkJoinTask<Integer> reduceValuesToInt |
5296 |
|
(ConcurrentHashMap<K,V> map, |
5297 |
< |
ObjectToInt<? super V> transformer, |
5297 |
> |
IntFunction<? super V> transformer, |
5298 |
|
int basis, |
5299 |
< |
IntByIntToInt reducer) { |
5299 |
> |
IntBinaryOperator reducer) { |
5300 |
|
if (transformer == null || reducer == null) |
5301 |
|
throw new NullPointerException(); |
5302 |
|
return new MapReduceValuesToIntTask<K,V> |
5312 |
|
*/ |
5313 |
|
public static <K,V> ForkJoinTask<Void> forEachEntry |
5314 |
|
(ConcurrentHashMap<K,V> map, |
5315 |
< |
Action<Map.Entry<K,V>> action) { |
5315 |
> |
Block<? super Map.Entry<K,V>> action) { |
5316 |
|
if (action == null) throw new NullPointerException(); |
5317 |
|
return new ForEachEntryTask<K,V>(map, null, -1, action); |
5318 |
|
} |
5329 |
|
*/ |
5330 |
|
public static <K,V,U> ForkJoinTask<Void> forEachEntry |
5331 |
|
(ConcurrentHashMap<K,V> map, |
5332 |
< |
Fun<Map.Entry<K,V>, ? extends U> transformer, |
5333 |
< |
Action<U> action) { |
5332 |
> |
Function<Map.Entry<K,V>, ? extends U> transformer, |
5333 |
> |
Block<? super U> action) { |
5334 |
|
if (transformer == null || action == null) |
5335 |
|
throw new NullPointerException(); |
5336 |
|
return new ForEachTransformedEntryTask<K,V,U> |
5351 |
|
*/ |
5352 |
|
public static <K,V,U> ForkJoinTask<U> searchEntries |
5353 |
|
(ConcurrentHashMap<K,V> map, |
5354 |
< |
Fun<Map.Entry<K,V>, ? extends U> searchFunction) { |
5354 |
> |
Function<Map.Entry<K,V>, ? extends U> searchFunction) { |
5355 |
|
if (searchFunction == null) throw new NullPointerException(); |
5356 |
|
return new SearchEntriesTask<K,V,U> |
5357 |
|
(map, null, -1, searchFunction, |
5369 |
|
*/ |
5370 |
|
public static <K,V> ForkJoinTask<Map.Entry<K,V>> reduceEntries |
5371 |
|
(ConcurrentHashMap<K,V> map, |
5372 |
< |
BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
5372 |
> |
BiFunction<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
5373 |
|
if (reducer == null) throw new NullPointerException(); |
5374 |
|
return new ReduceEntriesTask<K,V> |
5375 |
|
(map, null, -1, null, reducer); |
5389 |
|
*/ |
5390 |
|
public static <K,V,U> ForkJoinTask<U> reduceEntries |
5391 |
|
(ConcurrentHashMap<K,V> map, |
5392 |
< |
Fun<Map.Entry<K,V>, ? extends U> transformer, |
5393 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
5392 |
> |
Function<Map.Entry<K,V>, ? extends U> transformer, |
5393 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
5394 |
|
if (transformer == null || reducer == null) |
5395 |
|
throw new NullPointerException(); |
5396 |
|
return new MapReduceEntriesTask<K,V,U> |
5412 |
|
*/ |
5413 |
|
public static <K,V> ForkJoinTask<Double> reduceEntriesToDouble |
5414 |
|
(ConcurrentHashMap<K,V> map, |
5415 |
< |
ObjectToDouble<Map.Entry<K,V>> transformer, |
5415 |
> |
DoubleFunction<Map.Entry<K,V>> transformer, |
5416 |
|
double basis, |
5417 |
< |
DoubleByDoubleToDouble reducer) { |
5417 |
> |
DoubleBinaryOperator reducer) { |
5418 |
|
if (transformer == null || reducer == null) |
5419 |
|
throw new NullPointerException(); |
5420 |
|
return new MapReduceEntriesToDoubleTask<K,V> |
5436 |
|
*/ |
5437 |
|
public static <K,V> ForkJoinTask<Long> reduceEntriesToLong |
5438 |
|
(ConcurrentHashMap<K,V> map, |
5439 |
< |
ObjectToLong<Map.Entry<K,V>> transformer, |
5439 |
> |
LongFunction<Map.Entry<K,V>> transformer, |
5440 |
|
long basis, |
5441 |
< |
LongByLongToLong reducer) { |
5441 |
> |
LongBinaryOperator reducer) { |
5442 |
|
if (transformer == null || reducer == null) |
5443 |
|
throw new NullPointerException(); |
5444 |
|
return new MapReduceEntriesToLongTask<K,V> |
5460 |
|
*/ |
5461 |
|
public static <K,V> ForkJoinTask<Integer> reduceEntriesToInt |
5462 |
|
(ConcurrentHashMap<K,V> map, |
5463 |
< |
ObjectToInt<Map.Entry<K,V>> transformer, |
5463 |
> |
IntFunction<Map.Entry<K,V>> transformer, |
5464 |
|
int basis, |
5465 |
< |
IntByIntToInt reducer) { |
5465 |
> |
IntBinaryOperator reducer) { |
5466 |
|
if (transformer == null || reducer == null) |
5467 |
|
throw new NullPointerException(); |
5468 |
|
return new MapReduceEntriesToIntTask<K,V> |
5482 |
|
|
5483 |
|
@SuppressWarnings("serial") static final class ForEachKeyTask<K,V> |
5484 |
|
extends Traverser<K,V,Void> { |
5485 |
< |
final Action<K> action; |
5485 |
> |
final Block<? super K> action; |
5486 |
|
ForEachKeyTask |
5487 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5488 |
< |
Action<K> action) { |
5488 |
> |
Block<? super K> action) { |
5489 |
|
super(m, p, b); |
5490 |
|
this.action = action; |
5491 |
|
} |
5492 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5493 |
< |
final Action<K> action; |
5493 |
> |
final Block<? super K> action; |
5494 |
|
if ((action = this.action) != null) { |
5495 |
|
for (int b; (b = preSplit()) > 0;) |
5496 |
|
new ForEachKeyTask<K,V>(map, this, b, action).fork(); |
5497 |
|
while (advance() != null) |
5498 |
< |
action.apply((K)nextKey); |
5498 |
> |
action.accept((K)nextKey); |
5499 |
|
propagateCompletion(); |
5500 |
|
} |
5501 |
|
} |
5503 |
|
|
5504 |
|
@SuppressWarnings("serial") static final class ForEachValueTask<K,V> |
5505 |
|
extends Traverser<K,V,Void> { |
5506 |
< |
final Action<V> action; |
5506 |
> |
final Block<? super V> action; |
5507 |
|
ForEachValueTask |
5508 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5509 |
< |
Action<V> action) { |
5509 |
> |
Block<? super V> action) { |
5510 |
|
super(m, p, b); |
5511 |
|
this.action = action; |
5512 |
|
} |
5513 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5514 |
< |
final Action<V> action; |
5514 |
> |
final Block<? super V> action; |
5515 |
|
if ((action = this.action) != null) { |
5516 |
|
for (int b; (b = preSplit()) > 0;) |
5517 |
|
new ForEachValueTask<K,V>(map, this, b, action).fork(); |
5518 |
|
V v; |
5519 |
|
while ((v = advance()) != null) |
5520 |
< |
action.apply(v); |
5520 |
> |
action.accept(v); |
5521 |
|
propagateCompletion(); |
5522 |
|
} |
5523 |
|
} |
5525 |
|
|
5526 |
|
@SuppressWarnings("serial") static final class ForEachEntryTask<K,V> |
5527 |
|
extends Traverser<K,V,Void> { |
5528 |
< |
final Action<Entry<K,V>> action; |
5528 |
> |
final Block<? super Entry<K,V>> action; |
5529 |
|
ForEachEntryTask |
5530 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5531 |
< |
Action<Entry<K,V>> action) { |
5531 |
> |
Block<? super Entry<K,V>> action) { |
5532 |
|
super(m, p, b); |
5533 |
|
this.action = action; |
5534 |
|
} |
5535 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5536 |
< |
final Action<Entry<K,V>> action; |
5536 |
> |
final Block<? super Entry<K,V>> action; |
5537 |
|
if ((action = this.action) != null) { |
5538 |
|
for (int b; (b = preSplit()) > 0;) |
5539 |
|
new ForEachEntryTask<K,V>(map, this, b, action).fork(); |
5540 |
|
V v; |
5541 |
|
while ((v = advance()) != null) |
5542 |
< |
action.apply(entryFor((K)nextKey, v)); |
5542 |
> |
action.accept(entryFor((K)nextKey, v)); |
5543 |
|
propagateCompletion(); |
5544 |
|
} |
5545 |
|
} |
5547 |
|
|
5548 |
|
@SuppressWarnings("serial") static final class ForEachMappingTask<K,V> |
5549 |
|
extends Traverser<K,V,Void> { |
5550 |
< |
final BiAction<K,V> action; |
5550 |
> |
final BiBlock<? super K, ? super V> action; |
5551 |
|
ForEachMappingTask |
5552 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5553 |
< |
BiAction<K,V> action) { |
5553 |
> |
BiBlock<? super K,? super V> action) { |
5554 |
|
super(m, p, b); |
5555 |
|
this.action = action; |
5556 |
|
} |
5557 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5558 |
< |
final BiAction<K,V> action; |
5558 |
> |
final BiBlock<? super K, ? super V> action; |
5559 |
|
if ((action = this.action) != null) { |
5560 |
|
for (int b; (b = preSplit()) > 0;) |
5561 |
|
new ForEachMappingTask<K,V>(map, this, b, action).fork(); |
5562 |
|
V v; |
5563 |
|
while ((v = advance()) != null) |
5564 |
< |
action.apply((K)nextKey, v); |
5564 |
> |
action.accept((K)nextKey, v); |
5565 |
|
propagateCompletion(); |
5566 |
|
} |
5567 |
|
} |
5569 |
|
|
5570 |
|
@SuppressWarnings("serial") static final class ForEachTransformedKeyTask<K,V,U> |
5571 |
|
extends Traverser<K,V,Void> { |
5572 |
< |
final Fun<? super K, ? extends U> transformer; |
5573 |
< |
final Action<U> action; |
5572 |
> |
final Function<? super K, ? extends U> transformer; |
5573 |
> |
final Block<? super U> action; |
5574 |
|
ForEachTransformedKeyTask |
5575 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5576 |
< |
Fun<? super K, ? extends U> transformer, Action<U> action) { |
5576 |
> |
Function<? super K, ? extends U> transformer, Block<? super U> action) { |
5577 |
|
super(m, p, b); |
5578 |
|
this.transformer = transformer; this.action = action; |
5579 |
|
} |
5580 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5581 |
< |
final Fun<? super K, ? extends U> transformer; |
5582 |
< |
final Action<U> action; |
5581 |
> |
final Function<? super K, ? extends U> transformer; |
5582 |
> |
final Block<? super U> action; |
5583 |
|
if ((transformer = this.transformer) != null && |
5584 |
|
(action = this.action) != null) { |
5585 |
|
for (int b; (b = preSplit()) > 0;) |
5588 |
|
U u; |
5589 |
|
while (advance() != null) { |
5590 |
|
if ((u = transformer.apply((K)nextKey)) != null) |
5591 |
< |
action.apply(u); |
5591 |
> |
action.accept(u); |
5592 |
|
} |
5593 |
|
propagateCompletion(); |
5594 |
|
} |
5597 |
|
|
5598 |
|
@SuppressWarnings("serial") static final class ForEachTransformedValueTask<K,V,U> |
5599 |
|
extends Traverser<K,V,Void> { |
5600 |
< |
final Fun<? super V, ? extends U> transformer; |
5601 |
< |
final Action<U> action; |
5600 |
> |
final Function<? super V, ? extends U> transformer; |
5601 |
> |
final Block<? super U> action; |
5602 |
|
ForEachTransformedValueTask |
5603 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5604 |
< |
Fun<? super V, ? extends U> transformer, Action<U> action) { |
5604 |
> |
Function<? super V, ? extends U> transformer, Block<? super U> action) { |
5605 |
|
super(m, p, b); |
5606 |
|
this.transformer = transformer; this.action = action; |
5607 |
|
} |
5608 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5609 |
< |
final Fun<? super V, ? extends U> transformer; |
5610 |
< |
final Action<U> action; |
5609 |
> |
final Function<? super V, ? extends U> transformer; |
5610 |
> |
final Block<? super U> action; |
5611 |
|
if ((transformer = this.transformer) != null && |
5612 |
|
(action = this.action) != null) { |
5613 |
|
for (int b; (b = preSplit()) > 0;) |
5616 |
|
V v; U u; |
5617 |
|
while ((v = advance()) != null) { |
5618 |
|
if ((u = transformer.apply(v)) != null) |
5619 |
< |
action.apply(u); |
5619 |
> |
action.accept(u); |
5620 |
|
} |
5621 |
|
propagateCompletion(); |
5622 |
|
} |
5625 |
|
|
5626 |
|
@SuppressWarnings("serial") static final class ForEachTransformedEntryTask<K,V,U> |
5627 |
|
extends Traverser<K,V,Void> { |
5628 |
< |
final Fun<Map.Entry<K,V>, ? extends U> transformer; |
5629 |
< |
final Action<U> action; |
5628 |
> |
final Function<Map.Entry<K,V>, ? extends U> transformer; |
5629 |
> |
final Block<? super U> action; |
5630 |
|
ForEachTransformedEntryTask |
5631 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5632 |
< |
Fun<Map.Entry<K,V>, ? extends U> transformer, Action<U> action) { |
5632 |
> |
Function<Map.Entry<K,V>, ? extends U> transformer, Block<? super U> action) { |
5633 |
|
super(m, p, b); |
5634 |
|
this.transformer = transformer; this.action = action; |
5635 |
|
} |
5636 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5637 |
< |
final Fun<Map.Entry<K,V>, ? extends U> transformer; |
5638 |
< |
final Action<U> action; |
5637 |
> |
final Function<Map.Entry<K,V>, ? extends U> transformer; |
5638 |
> |
final Block<? super U> action; |
5639 |
|
if ((transformer = this.transformer) != null && |
5640 |
|
(action = this.action) != null) { |
5641 |
|
for (int b; (b = preSplit()) > 0;) |
5645 |
|
while ((v = advance()) != null) { |
5646 |
|
if ((u = transformer.apply(entryFor((K)nextKey, |
5647 |
|
v))) != null) |
5648 |
< |
action.apply(u); |
5648 |
> |
action.accept(u); |
5649 |
|
} |
5650 |
|
propagateCompletion(); |
5651 |
|
} |
5654 |
|
|
5655 |
|
@SuppressWarnings("serial") static final class ForEachTransformedMappingTask<K,V,U> |
5656 |
|
extends Traverser<K,V,Void> { |
5657 |
< |
final BiFun<? super K, ? super V, ? extends U> transformer; |
5658 |
< |
final Action<U> action; |
5657 |
> |
final BiFunction<? super K, ? super V, ? extends U> transformer; |
5658 |
> |
final Block<? super U> action; |
5659 |
|
ForEachTransformedMappingTask |
5660 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5661 |
< |
BiFun<? super K, ? super V, ? extends U> transformer, |
5662 |
< |
Action<U> action) { |
5661 |
> |
BiFunction<? super K, ? super V, ? extends U> transformer, |
5662 |
> |
Block<? super U> action) { |
5663 |
|
super(m, p, b); |
5664 |
|
this.transformer = transformer; this.action = action; |
5665 |
|
} |
5666 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5667 |
< |
final BiFun<? super K, ? super V, ? extends U> transformer; |
5668 |
< |
final Action<U> action; |
5667 |
> |
final BiFunction<? super K, ? super V, ? extends U> transformer; |
5668 |
> |
final Block<? super U> action; |
5669 |
|
if ((transformer = this.transformer) != null && |
5670 |
|
(action = this.action) != null) { |
5671 |
|
for (int b; (b = preSplit()) > 0;) |
5674 |
|
V v; U u; |
5675 |
|
while ((v = advance()) != null) { |
5676 |
|
if ((u = transformer.apply((K)nextKey, v)) != null) |
5677 |
< |
action.apply(u); |
5677 |
> |
action.accept(u); |
5678 |
|
} |
5679 |
|
propagateCompletion(); |
5680 |
|
} |
5683 |
|
|
5684 |
|
@SuppressWarnings("serial") static final class SearchKeysTask<K,V,U> |
5685 |
|
extends Traverser<K,V,U> { |
5686 |
< |
final Fun<? super K, ? extends U> searchFunction; |
5686 |
> |
final Function<? super K, ? extends U> searchFunction; |
5687 |
|
final AtomicReference<U> result; |
5688 |
|
SearchKeysTask |
5689 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5690 |
< |
Fun<? super K, ? extends U> searchFunction, |
5690 |
> |
Function<? super K, ? extends U> searchFunction, |
5691 |
|
AtomicReference<U> result) { |
5692 |
|
super(m, p, b); |
5693 |
|
this.searchFunction = searchFunction; this.result = result; |
5694 |
|
} |
5695 |
|
public final U getRawResult() { return result.get(); } |
5696 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5697 |
< |
final Fun<? super K, ? extends U> searchFunction; |
5697 |
> |
final Function<? super K, ? extends U> searchFunction; |
5698 |
|
final AtomicReference<U> result; |
5699 |
|
if ((searchFunction = this.searchFunction) != null && |
5700 |
|
(result = this.result) != null) { |
5724 |
|
|
5725 |
|
@SuppressWarnings("serial") static final class SearchValuesTask<K,V,U> |
5726 |
|
extends Traverser<K,V,U> { |
5727 |
< |
final Fun<? super V, ? extends U> searchFunction; |
5727 |
> |
final Function<? super V, ? extends U> searchFunction; |
5728 |
|
final AtomicReference<U> result; |
5729 |
|
SearchValuesTask |
5730 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5731 |
< |
Fun<? super V, ? extends U> searchFunction, |
5731 |
> |
Function<? super V, ? extends U> searchFunction, |
5732 |
|
AtomicReference<U> result) { |
5733 |
|
super(m, p, b); |
5734 |
|
this.searchFunction = searchFunction; this.result = result; |
5735 |
|
} |
5736 |
|
public final U getRawResult() { return result.get(); } |
5737 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5738 |
< |
final Fun<? super V, ? extends U> searchFunction; |
5738 |
> |
final Function<? super V, ? extends U> searchFunction; |
5739 |
|
final AtomicReference<U> result; |
5740 |
|
if ((searchFunction = this.searchFunction) != null && |
5741 |
|
(result = this.result) != null) { |
5765 |
|
|
5766 |
|
@SuppressWarnings("serial") static final class SearchEntriesTask<K,V,U> |
5767 |
|
extends Traverser<K,V,U> { |
5768 |
< |
final Fun<Entry<K,V>, ? extends U> searchFunction; |
5768 |
> |
final Function<Entry<K,V>, ? extends U> searchFunction; |
5769 |
|
final AtomicReference<U> result; |
5770 |
|
SearchEntriesTask |
5771 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5772 |
< |
Fun<Entry<K,V>, ? extends U> searchFunction, |
5772 |
> |
Function<Entry<K,V>, ? extends U> searchFunction, |
5773 |
|
AtomicReference<U> result) { |
5774 |
|
super(m, p, b); |
5775 |
|
this.searchFunction = searchFunction; this.result = result; |
5776 |
|
} |
5777 |
|
public final U getRawResult() { return result.get(); } |
5778 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5779 |
< |
final Fun<Entry<K,V>, ? extends U> searchFunction; |
5779 |
> |
final Function<Entry<K,V>, ? extends U> searchFunction; |
5780 |
|
final AtomicReference<U> result; |
5781 |
|
if ((searchFunction = this.searchFunction) != null && |
5782 |
|
(result = this.result) != null) { |
5807 |
|
|
5808 |
|
@SuppressWarnings("serial") static final class SearchMappingsTask<K,V,U> |
5809 |
|
extends Traverser<K,V,U> { |
5810 |
< |
final BiFun<? super K, ? super V, ? extends U> searchFunction; |
5810 |
> |
final BiFunction<? super K, ? super V, ? extends U> searchFunction; |
5811 |
|
final AtomicReference<U> result; |
5812 |
|
SearchMappingsTask |
5813 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5814 |
< |
BiFun<? super K, ? super V, ? extends U> searchFunction, |
5814 |
> |
BiFunction<? super K, ? super V, ? extends U> searchFunction, |
5815 |
|
AtomicReference<U> result) { |
5816 |
|
super(m, p, b); |
5817 |
|
this.searchFunction = searchFunction; this.result = result; |
5818 |
|
} |
5819 |
|
public final U getRawResult() { return result.get(); } |
5820 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5821 |
< |
final BiFun<? super K, ? super V, ? extends U> searchFunction; |
5821 |
> |
final BiFunction<? super K, ? super V, ? extends U> searchFunction; |
5822 |
|
final AtomicReference<U> result; |
5823 |
|
if ((searchFunction = this.searchFunction) != null && |
5824 |
|
(result = this.result) != null) { |
5848 |
|
|
5849 |
|
@SuppressWarnings("serial") static final class ReduceKeysTask<K,V> |
5850 |
|
extends Traverser<K,V,K> { |
5851 |
< |
final BiFun<? super K, ? super K, ? extends K> reducer; |
5851 |
> |
final BiFunction<? super K, ? super K, ? extends K> reducer; |
5852 |
|
K result; |
5853 |
|
ReduceKeysTask<K,V> rights, nextRight; |
5854 |
|
ReduceKeysTask |
5855 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5856 |
|
ReduceKeysTask<K,V> nextRight, |
5857 |
< |
BiFun<? super K, ? super K, ? extends K> reducer) { |
5857 |
> |
BiFunction<? super K, ? super K, ? extends K> reducer) { |
5858 |
|
super(m, p, b); this.nextRight = nextRight; |
5859 |
|
this.reducer = reducer; |
5860 |
|
} |
5861 |
|
public final K getRawResult() { return result; } |
5862 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5863 |
< |
final BiFun<? super K, ? super K, ? extends K> reducer; |
5863 |
> |
final BiFunction<? super K, ? super K, ? extends K> reducer; |
5864 |
|
if ((reducer = this.reducer) != null) { |
5865 |
|
for (int b; (b = preSplit()) > 0;) |
5866 |
|
(rights = new ReduceKeysTask<K,V> |
5868 |
|
K r = null; |
5869 |
|
while (advance() != null) { |
5870 |
|
K u = (K)nextKey; |
5871 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
5871 |
> |
r = (r == null) ? u : u == null? r : reducer.apply(r, u); |
5872 |
|
} |
5873 |
|
result = r; |
5874 |
|
CountedCompleter<?> c; |
5890 |
|
|
5891 |
|
@SuppressWarnings("serial") static final class ReduceValuesTask<K,V> |
5892 |
|
extends Traverser<K,V,V> { |
5893 |
< |
final BiFun<? super V, ? super V, ? extends V> reducer; |
5893 |
> |
final BiFunction<? super V, ? super V, ? extends V> reducer; |
5894 |
|
V result; |
5895 |
|
ReduceValuesTask<K,V> rights, nextRight; |
5896 |
|
ReduceValuesTask |
5897 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5898 |
|
ReduceValuesTask<K,V> nextRight, |
5899 |
< |
BiFun<? super V, ? super V, ? extends V> reducer) { |
5899 |
> |
BiFunction<? super V, ? super V, ? extends V> reducer) { |
5900 |
|
super(m, p, b); this.nextRight = nextRight; |
5901 |
|
this.reducer = reducer; |
5902 |
|
} |
5903 |
|
public final V getRawResult() { return result; } |
5904 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5905 |
< |
final BiFun<? super V, ? super V, ? extends V> reducer; |
5905 |
> |
final BiFunction<? super V, ? super V, ? extends V> reducer; |
5906 |
|
if ((reducer = this.reducer) != null) { |
5907 |
|
for (int b; (b = preSplit()) > 0;) |
5908 |
|
(rights = new ReduceValuesTask<K,V> |
5909 |
|
(map, this, b, rights, reducer)).fork(); |
5910 |
< |
V r = null; |
5911 |
< |
V v; |
5912 |
< |
while ((v = advance()) != null) { |
6003 |
< |
V u = v; |
6004 |
< |
r = (r == null) ? u : reducer.apply(r, u); |
6005 |
< |
} |
5910 |
> |
V r = null, v; |
5911 |
> |
while ((v = advance()) != null) |
5912 |
> |
r = (r == null) ? v : v == null? r : reducer.apply(r, v); |
5913 |
|
result = r; |
5914 |
|
CountedCompleter<?> c; |
5915 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
5930 |
|
|
5931 |
|
@SuppressWarnings("serial") static final class ReduceEntriesTask<K,V> |
5932 |
|
extends Traverser<K,V,Map.Entry<K,V>> { |
5933 |
< |
final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer; |
5933 |
> |
final BiFunction<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer; |
5934 |
|
Map.Entry<K,V> result; |
5935 |
|
ReduceEntriesTask<K,V> rights, nextRight; |
5936 |
|
ReduceEntriesTask |
5937 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5938 |
|
ReduceEntriesTask<K,V> nextRight, |
5939 |
< |
BiFun<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
5939 |
> |
BiFunction<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) { |
5940 |
|
super(m, p, b); this.nextRight = nextRight; |
5941 |
|
this.reducer = reducer; |
5942 |
|
} |
5943 |
|
public final Map.Entry<K,V> getRawResult() { return result; } |
5944 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5945 |
< |
final BiFun<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer; |
5945 |
> |
final BiFunction<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer; |
5946 |
|
if ((reducer = this.reducer) != null) { |
5947 |
|
for (int b; (b = preSplit()) > 0;) |
5948 |
|
(rights = new ReduceEntriesTask<K,V> |
5973 |
|
|
5974 |
|
@SuppressWarnings("serial") static final class MapReduceKeysTask<K,V,U> |
5975 |
|
extends Traverser<K,V,U> { |
5976 |
< |
final Fun<? super K, ? extends U> transformer; |
5977 |
< |
final BiFun<? super U, ? super U, ? extends U> reducer; |
5976 |
> |
final Function<? super K, ? extends U> transformer; |
5977 |
> |
final BiFunction<? super U, ? super U, ? extends U> reducer; |
5978 |
|
U result; |
5979 |
|
MapReduceKeysTask<K,V,U> rights, nextRight; |
5980 |
|
MapReduceKeysTask |
5981 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
5982 |
|
MapReduceKeysTask<K,V,U> nextRight, |
5983 |
< |
Fun<? super K, ? extends U> transformer, |
5984 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
5983 |
> |
Function<? super K, ? extends U> transformer, |
5984 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
5985 |
|
super(m, p, b); this.nextRight = nextRight; |
5986 |
|
this.transformer = transformer; |
5987 |
|
this.reducer = reducer; |
5988 |
|
} |
5989 |
|
public final U getRawResult() { return result; } |
5990 |
|
@SuppressWarnings("unchecked") public final void compute() { |
5991 |
< |
final Fun<? super K, ? extends U> transformer; |
5992 |
< |
final BiFun<? super U, ? super U, ? extends U> reducer; |
5991 |
> |
final Function<? super K, ? extends U> transformer; |
5992 |
> |
final BiFunction<? super U, ? super U, ? extends U> reducer; |
5993 |
|
if ((transformer = this.transformer) != null && |
5994 |
|
(reducer = this.reducer) != null) { |
5995 |
|
for (int b; (b = preSplit()) > 0;) |
6020 |
|
|
6021 |
|
@SuppressWarnings("serial") static final class MapReduceValuesTask<K,V,U> |
6022 |
|
extends Traverser<K,V,U> { |
6023 |
< |
final Fun<? super V, ? extends U> transformer; |
6024 |
< |
final BiFun<? super U, ? super U, ? extends U> reducer; |
6023 |
> |
final Function<? super V, ? extends U> transformer; |
6024 |
> |
final BiFunction<? super U, ? super U, ? extends U> reducer; |
6025 |
|
U result; |
6026 |
|
MapReduceValuesTask<K,V,U> rights, nextRight; |
6027 |
|
MapReduceValuesTask |
6028 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6029 |
|
MapReduceValuesTask<K,V,U> nextRight, |
6030 |
< |
Fun<? super V, ? extends U> transformer, |
6031 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
6030 |
> |
Function<? super V, ? extends U> transformer, |
6031 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
6032 |
|
super(m, p, b); this.nextRight = nextRight; |
6033 |
|
this.transformer = transformer; |
6034 |
|
this.reducer = reducer; |
6035 |
|
} |
6036 |
|
public final U getRawResult() { return result; } |
6037 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6038 |
< |
final Fun<? super V, ? extends U> transformer; |
6039 |
< |
final BiFun<? super U, ? super U, ? extends U> reducer; |
6038 |
> |
final Function<? super V, ? extends U> transformer; |
6039 |
> |
final BiFunction<? super U, ? super U, ? extends U> reducer; |
6040 |
|
if ((transformer = this.transformer) != null && |
6041 |
|
(reducer = this.reducer) != null) { |
6042 |
|
for (int b; (b = preSplit()) > 0;) |
6068 |
|
|
6069 |
|
@SuppressWarnings("serial") static final class MapReduceEntriesTask<K,V,U> |
6070 |
|
extends Traverser<K,V,U> { |
6071 |
< |
final Fun<Map.Entry<K,V>, ? extends U> transformer; |
6072 |
< |
final BiFun<? super U, ? super U, ? extends U> reducer; |
6071 |
> |
final Function<Map.Entry<K,V>, ? extends U> transformer; |
6072 |
> |
final BiFunction<? super U, ? super U, ? extends U> reducer; |
6073 |
|
U result; |
6074 |
|
MapReduceEntriesTask<K,V,U> rights, nextRight; |
6075 |
|
MapReduceEntriesTask |
6076 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6077 |
|
MapReduceEntriesTask<K,V,U> nextRight, |
6078 |
< |
Fun<Map.Entry<K,V>, ? extends U> transformer, |
6079 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
6078 |
> |
Function<Map.Entry<K,V>, ? extends U> transformer, |
6079 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
6080 |
|
super(m, p, b); this.nextRight = nextRight; |
6081 |
|
this.transformer = transformer; |
6082 |
|
this.reducer = reducer; |
6083 |
|
} |
6084 |
|
public final U getRawResult() { return result; } |
6085 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6086 |
< |
final Fun<Map.Entry<K,V>, ? extends U> transformer; |
6087 |
< |
final BiFun<? super U, ? super U, ? extends U> reducer; |
6086 |
> |
final Function<Map.Entry<K,V>, ? extends U> transformer; |
6087 |
> |
final BiFunction<? super U, ? super U, ? extends U> reducer; |
6088 |
|
if ((transformer = this.transformer) != null && |
6089 |
|
(reducer = this.reducer) != null) { |
6090 |
|
for (int b; (b = preSplit()) > 0;) |
6117 |
|
|
6118 |
|
@SuppressWarnings("serial") static final class MapReduceMappingsTask<K,V,U> |
6119 |
|
extends Traverser<K,V,U> { |
6120 |
< |
final BiFun<? super K, ? super V, ? extends U> transformer; |
6121 |
< |
final BiFun<? super U, ? super U, ? extends U> reducer; |
6120 |
> |
final BiFunction<? super K, ? super V, ? extends U> transformer; |
6121 |
> |
final BiFunction<? super U, ? super U, ? extends U> reducer; |
6122 |
|
U result; |
6123 |
|
MapReduceMappingsTask<K,V,U> rights, nextRight; |
6124 |
|
MapReduceMappingsTask |
6125 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6126 |
|
MapReduceMappingsTask<K,V,U> nextRight, |
6127 |
< |
BiFun<? super K, ? super V, ? extends U> transformer, |
6128 |
< |
BiFun<? super U, ? super U, ? extends U> reducer) { |
6127 |
> |
BiFunction<? super K, ? super V, ? extends U> transformer, |
6128 |
> |
BiFunction<? super U, ? super U, ? extends U> reducer) { |
6129 |
|
super(m, p, b); this.nextRight = nextRight; |
6130 |
|
this.transformer = transformer; |
6131 |
|
this.reducer = reducer; |
6132 |
|
} |
6133 |
|
public final U getRawResult() { return result; } |
6134 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6135 |
< |
final BiFun<? super K, ? super V, ? extends U> transformer; |
6136 |
< |
final BiFun<? super U, ? super U, ? extends U> reducer; |
6135 |
> |
final BiFunction<? super K, ? super V, ? extends U> transformer; |
6136 |
> |
final BiFunction<? super U, ? super U, ? extends U> reducer; |
6137 |
|
if ((transformer = this.transformer) != null && |
6138 |
|
(reducer = this.reducer) != null) { |
6139 |
|
for (int b; (b = preSplit()) > 0;) |
6165 |
|
|
6166 |
|
@SuppressWarnings("serial") static final class MapReduceKeysToDoubleTask<K,V> |
6167 |
|
extends Traverser<K,V,Double> { |
6168 |
< |
final ObjectToDouble<? super K> transformer; |
6169 |
< |
final DoubleByDoubleToDouble reducer; |
6168 |
> |
final DoubleFunction<? super K> transformer; |
6169 |
> |
final DoubleBinaryOperator reducer; |
6170 |
|
final double basis; |
6171 |
|
double result; |
6172 |
|
MapReduceKeysToDoubleTask<K,V> rights, nextRight; |
6173 |
|
MapReduceKeysToDoubleTask |
6174 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6175 |
|
MapReduceKeysToDoubleTask<K,V> nextRight, |
6176 |
< |
ObjectToDouble<? super K> transformer, |
6176 |
> |
DoubleFunction<? super K> transformer, |
6177 |
|
double basis, |
6178 |
< |
DoubleByDoubleToDouble reducer) { |
6178 |
> |
DoubleBinaryOperator reducer) { |
6179 |
|
super(m, p, b); this.nextRight = nextRight; |
6180 |
|
this.transformer = transformer; |
6181 |
|
this.basis = basis; this.reducer = reducer; |
6182 |
|
} |
6183 |
|
public final Double getRawResult() { return result; } |
6184 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6185 |
< |
final ObjectToDouble<? super K> transformer; |
6186 |
< |
final DoubleByDoubleToDouble reducer; |
6185 |
> |
final DoubleFunction<? super K> transformer; |
6186 |
> |
final DoubleBinaryOperator reducer; |
6187 |
|
if ((transformer = this.transformer) != null && |
6188 |
|
(reducer = this.reducer) != null) { |
6189 |
|
double r = this.basis; |
6191 |
|
(rights = new MapReduceKeysToDoubleTask<K,V> |
6192 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6193 |
|
while (advance() != null) |
6194 |
< |
r = reducer.apply(r, transformer.apply((K)nextKey)); |
6194 |
> |
r = reducer.applyAsDouble(r, transformer.applyAsDouble((K)nextKey)); |
6195 |
|
result = r; |
6196 |
|
CountedCompleter<?> c; |
6197 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6199 |
|
t = (MapReduceKeysToDoubleTask<K,V>)c, |
6200 |
|
s = t.rights; |
6201 |
|
while (s != null) { |
6202 |
< |
t.result = reducer.apply(t.result, s.result); |
6202 |
> |
t.result = reducer.applyAsDouble(t.result, s.result); |
6203 |
|
s = t.rights = s.nextRight; |
6204 |
|
} |
6205 |
|
} |
6209 |
|
|
6210 |
|
@SuppressWarnings("serial") static final class MapReduceValuesToDoubleTask<K,V> |
6211 |
|
extends Traverser<K,V,Double> { |
6212 |
< |
final ObjectToDouble<? super V> transformer; |
6213 |
< |
final DoubleByDoubleToDouble reducer; |
6212 |
> |
final DoubleFunction<? super V> transformer; |
6213 |
> |
final DoubleBinaryOperator reducer; |
6214 |
|
final double basis; |
6215 |
|
double result; |
6216 |
|
MapReduceValuesToDoubleTask<K,V> rights, nextRight; |
6217 |
|
MapReduceValuesToDoubleTask |
6218 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6219 |
|
MapReduceValuesToDoubleTask<K,V> nextRight, |
6220 |
< |
ObjectToDouble<? super V> transformer, |
6220 |
> |
DoubleFunction<? super V> transformer, |
6221 |
|
double basis, |
6222 |
< |
DoubleByDoubleToDouble reducer) { |
6222 |
> |
DoubleBinaryOperator reducer) { |
6223 |
|
super(m, p, b); this.nextRight = nextRight; |
6224 |
|
this.transformer = transformer; |
6225 |
|
this.basis = basis; this.reducer = reducer; |
6226 |
|
} |
6227 |
|
public final Double getRawResult() { return result; } |
6228 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6229 |
< |
final ObjectToDouble<? super V> transformer; |
6230 |
< |
final DoubleByDoubleToDouble reducer; |
6229 |
> |
final DoubleFunction<? super V> transformer; |
6230 |
> |
final DoubleBinaryOperator reducer; |
6231 |
|
if ((transformer = this.transformer) != null && |
6232 |
|
(reducer = this.reducer) != null) { |
6233 |
|
double r = this.basis; |
6236 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6237 |
|
V v; |
6238 |
|
while ((v = advance()) != null) |
6239 |
< |
r = reducer.apply(r, transformer.apply(v)); |
6239 |
> |
r = reducer.applyAsDouble(r, transformer.applyAsDouble(v)); |
6240 |
|
result = r; |
6241 |
|
CountedCompleter<?> c; |
6242 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6244 |
|
t = (MapReduceValuesToDoubleTask<K,V>)c, |
6245 |
|
s = t.rights; |
6246 |
|
while (s != null) { |
6247 |
< |
t.result = reducer.apply(t.result, s.result); |
6247 |
> |
t.result = reducer.applyAsDouble(t.result, s.result); |
6248 |
|
s = t.rights = s.nextRight; |
6249 |
|
} |
6250 |
|
} |
6254 |
|
|
6255 |
|
@SuppressWarnings("serial") static final class MapReduceEntriesToDoubleTask<K,V> |
6256 |
|
extends Traverser<K,V,Double> { |
6257 |
< |
final ObjectToDouble<Map.Entry<K,V>> transformer; |
6258 |
< |
final DoubleByDoubleToDouble reducer; |
6257 |
> |
final DoubleFunction<Map.Entry<K,V>> transformer; |
6258 |
> |
final DoubleBinaryOperator reducer; |
6259 |
|
final double basis; |
6260 |
|
double result; |
6261 |
|
MapReduceEntriesToDoubleTask<K,V> rights, nextRight; |
6262 |
|
MapReduceEntriesToDoubleTask |
6263 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6264 |
|
MapReduceEntriesToDoubleTask<K,V> nextRight, |
6265 |
< |
ObjectToDouble<Map.Entry<K,V>> transformer, |
6265 |
> |
DoubleFunction<Map.Entry<K,V>> transformer, |
6266 |
|
double basis, |
6267 |
< |
DoubleByDoubleToDouble reducer) { |
6267 |
> |
DoubleBinaryOperator reducer) { |
6268 |
|
super(m, p, b); this.nextRight = nextRight; |
6269 |
|
this.transformer = transformer; |
6270 |
|
this.basis = basis; this.reducer = reducer; |
6271 |
|
} |
6272 |
|
public final Double getRawResult() { return result; } |
6273 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6274 |
< |
final ObjectToDouble<Map.Entry<K,V>> transformer; |
6275 |
< |
final DoubleByDoubleToDouble reducer; |
6274 |
> |
final DoubleFunction<Map.Entry<K,V>> transformer; |
6275 |
> |
final DoubleBinaryOperator reducer; |
6276 |
|
if ((transformer = this.transformer) != null && |
6277 |
|
(reducer = this.reducer) != null) { |
6278 |
|
double r = this.basis; |
6281 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6282 |
|
V v; |
6283 |
|
while ((v = advance()) != null) |
6284 |
< |
r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, |
6284 |
> |
r = reducer.applyAsDouble(r, transformer.applyAsDouble(entryFor((K)nextKey, |
6285 |
|
v))); |
6286 |
|
result = r; |
6287 |
|
CountedCompleter<?> c; |
6290 |
|
t = (MapReduceEntriesToDoubleTask<K,V>)c, |
6291 |
|
s = t.rights; |
6292 |
|
while (s != null) { |
6293 |
< |
t.result = reducer.apply(t.result, s.result); |
6293 |
> |
t.result = reducer.applyAsDouble(t.result, s.result); |
6294 |
|
s = t.rights = s.nextRight; |
6295 |
|
} |
6296 |
|
} |
6300 |
|
|
6301 |
|
@SuppressWarnings("serial") static final class MapReduceMappingsToDoubleTask<K,V> |
6302 |
|
extends Traverser<K,V,Double> { |
6303 |
< |
final ObjectByObjectToDouble<? super K, ? super V> transformer; |
6304 |
< |
final DoubleByDoubleToDouble reducer; |
6303 |
> |
final DoubleBiFunction<? super K, ? super V> transformer; |
6304 |
> |
final DoubleBinaryOperator reducer; |
6305 |
|
final double basis; |
6306 |
|
double result; |
6307 |
|
MapReduceMappingsToDoubleTask<K,V> rights, nextRight; |
6308 |
|
MapReduceMappingsToDoubleTask |
6309 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6310 |
|
MapReduceMappingsToDoubleTask<K,V> nextRight, |
6311 |
< |
ObjectByObjectToDouble<? super K, ? super V> transformer, |
6311 |
> |
DoubleBiFunction<? super K, ? super V> transformer, |
6312 |
|
double basis, |
6313 |
< |
DoubleByDoubleToDouble reducer) { |
6313 |
> |
DoubleBinaryOperator reducer) { |
6314 |
|
super(m, p, b); this.nextRight = nextRight; |
6315 |
|
this.transformer = transformer; |
6316 |
|
this.basis = basis; this.reducer = reducer; |
6317 |
|
} |
6318 |
|
public final Double getRawResult() { return result; } |
6319 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6320 |
< |
final ObjectByObjectToDouble<? super K, ? super V> transformer; |
6321 |
< |
final DoubleByDoubleToDouble reducer; |
6320 |
> |
final DoubleBiFunction<? super K, ? super V> transformer; |
6321 |
> |
final DoubleBinaryOperator reducer; |
6322 |
|
if ((transformer = this.transformer) != null && |
6323 |
|
(reducer = this.reducer) != null) { |
6324 |
|
double r = this.basis; |
6327 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6328 |
|
V v; |
6329 |
|
while ((v = advance()) != null) |
6330 |
< |
r = reducer.apply(r, transformer.apply((K)nextKey, v)); |
6330 |
> |
r = reducer.applyAsDouble(r, transformer.applyAsDouble((K)nextKey, v)); |
6331 |
|
result = r; |
6332 |
|
CountedCompleter<?> c; |
6333 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6335 |
|
t = (MapReduceMappingsToDoubleTask<K,V>)c, |
6336 |
|
s = t.rights; |
6337 |
|
while (s != null) { |
6338 |
< |
t.result = reducer.apply(t.result, s.result); |
6338 |
> |
t.result = reducer.applyAsDouble(t.result, s.result); |
6339 |
|
s = t.rights = s.nextRight; |
6340 |
|
} |
6341 |
|
} |
6345 |
|
|
6346 |
|
@SuppressWarnings("serial") static final class MapReduceKeysToLongTask<K,V> |
6347 |
|
extends Traverser<K,V,Long> { |
6348 |
< |
final ObjectToLong<? super K> transformer; |
6349 |
< |
final LongByLongToLong reducer; |
6348 |
> |
final LongFunction<? super K> transformer; |
6349 |
> |
final LongBinaryOperator reducer; |
6350 |
|
final long basis; |
6351 |
|
long result; |
6352 |
|
MapReduceKeysToLongTask<K,V> rights, nextRight; |
6353 |
|
MapReduceKeysToLongTask |
6354 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6355 |
|
MapReduceKeysToLongTask<K,V> nextRight, |
6356 |
< |
ObjectToLong<? super K> transformer, |
6356 |
> |
LongFunction<? super K> transformer, |
6357 |
|
long basis, |
6358 |
< |
LongByLongToLong reducer) { |
6358 |
> |
LongBinaryOperator reducer) { |
6359 |
|
super(m, p, b); this.nextRight = nextRight; |
6360 |
|
this.transformer = transformer; |
6361 |
|
this.basis = basis; this.reducer = reducer; |
6362 |
|
} |
6363 |
|
public final Long getRawResult() { return result; } |
6364 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6365 |
< |
final ObjectToLong<? super K> transformer; |
6366 |
< |
final LongByLongToLong reducer; |
6365 |
> |
final LongFunction<? super K> transformer; |
6366 |
> |
final LongBinaryOperator reducer; |
6367 |
|
if ((transformer = this.transformer) != null && |
6368 |
|
(reducer = this.reducer) != null) { |
6369 |
|
long r = this.basis; |
6371 |
|
(rights = new MapReduceKeysToLongTask<K,V> |
6372 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6373 |
|
while (advance() != null) |
6374 |
< |
r = reducer.apply(r, transformer.apply((K)nextKey)); |
6374 |
> |
r = reducer.applyAsLong(r, transformer.applyAsLong((K)nextKey)); |
6375 |
|
result = r; |
6376 |
|
CountedCompleter<?> c; |
6377 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6379 |
|
t = (MapReduceKeysToLongTask<K,V>)c, |
6380 |
|
s = t.rights; |
6381 |
|
while (s != null) { |
6382 |
< |
t.result = reducer.apply(t.result, s.result); |
6382 |
> |
t.result = reducer.applyAsLong(t.result, s.result); |
6383 |
|
s = t.rights = s.nextRight; |
6384 |
|
} |
6385 |
|
} |
6389 |
|
|
6390 |
|
@SuppressWarnings("serial") static final class MapReduceValuesToLongTask<K,V> |
6391 |
|
extends Traverser<K,V,Long> { |
6392 |
< |
final ObjectToLong<? super V> transformer; |
6393 |
< |
final LongByLongToLong reducer; |
6392 |
> |
final LongFunction<? super V> transformer; |
6393 |
> |
final LongBinaryOperator reducer; |
6394 |
|
final long basis; |
6395 |
|
long result; |
6396 |
|
MapReduceValuesToLongTask<K,V> rights, nextRight; |
6397 |
|
MapReduceValuesToLongTask |
6398 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6399 |
|
MapReduceValuesToLongTask<K,V> nextRight, |
6400 |
< |
ObjectToLong<? super V> transformer, |
6400 |
> |
LongFunction<? super V> transformer, |
6401 |
|
long basis, |
6402 |
< |
LongByLongToLong reducer) { |
6402 |
> |
LongBinaryOperator reducer) { |
6403 |
|
super(m, p, b); this.nextRight = nextRight; |
6404 |
|
this.transformer = transformer; |
6405 |
|
this.basis = basis; this.reducer = reducer; |
6406 |
|
} |
6407 |
|
public final Long getRawResult() { return result; } |
6408 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6409 |
< |
final ObjectToLong<? super V> transformer; |
6410 |
< |
final LongByLongToLong reducer; |
6409 |
> |
final LongFunction<? super V> transformer; |
6410 |
> |
final LongBinaryOperator reducer; |
6411 |
|
if ((transformer = this.transformer) != null && |
6412 |
|
(reducer = this.reducer) != null) { |
6413 |
|
long r = this.basis; |
6416 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6417 |
|
V v; |
6418 |
|
while ((v = advance()) != null) |
6419 |
< |
r = reducer.apply(r, transformer.apply(v)); |
6419 |
> |
r = reducer.applyAsLong(r, transformer.applyAsLong(v)); |
6420 |
|
result = r; |
6421 |
|
CountedCompleter<?> c; |
6422 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6424 |
|
t = (MapReduceValuesToLongTask<K,V>)c, |
6425 |
|
s = t.rights; |
6426 |
|
while (s != null) { |
6427 |
< |
t.result = reducer.apply(t.result, s.result); |
6427 |
> |
t.result = reducer.applyAsLong(t.result, s.result); |
6428 |
|
s = t.rights = s.nextRight; |
6429 |
|
} |
6430 |
|
} |
6434 |
|
|
6435 |
|
@SuppressWarnings("serial") static final class MapReduceEntriesToLongTask<K,V> |
6436 |
|
extends Traverser<K,V,Long> { |
6437 |
< |
final ObjectToLong<Map.Entry<K,V>> transformer; |
6438 |
< |
final LongByLongToLong reducer; |
6437 |
> |
final LongFunction<Map.Entry<K,V>> transformer; |
6438 |
> |
final LongBinaryOperator reducer; |
6439 |
|
final long basis; |
6440 |
|
long result; |
6441 |
|
MapReduceEntriesToLongTask<K,V> rights, nextRight; |
6442 |
|
MapReduceEntriesToLongTask |
6443 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6444 |
|
MapReduceEntriesToLongTask<K,V> nextRight, |
6445 |
< |
ObjectToLong<Map.Entry<K,V>> transformer, |
6445 |
> |
LongFunction<Map.Entry<K,V>> transformer, |
6446 |
|
long basis, |
6447 |
< |
LongByLongToLong reducer) { |
6447 |
> |
LongBinaryOperator reducer) { |
6448 |
|
super(m, p, b); this.nextRight = nextRight; |
6449 |
|
this.transformer = transformer; |
6450 |
|
this.basis = basis; this.reducer = reducer; |
6451 |
|
} |
6452 |
|
public final Long getRawResult() { return result; } |
6453 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6454 |
< |
final ObjectToLong<Map.Entry<K,V>> transformer; |
6455 |
< |
final LongByLongToLong reducer; |
6454 |
> |
final LongFunction<Map.Entry<K,V>> transformer; |
6455 |
> |
final LongBinaryOperator reducer; |
6456 |
|
if ((transformer = this.transformer) != null && |
6457 |
|
(reducer = this.reducer) != null) { |
6458 |
|
long r = this.basis; |
6461 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6462 |
|
V v; |
6463 |
|
while ((v = advance()) != null) |
6464 |
< |
r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, |
6558 |
< |
v))); |
6464 |
> |
r = reducer.applyAsLong(r, transformer.applyAsLong(entryFor((K)nextKey, v))); |
6465 |
|
result = r; |
6466 |
|
CountedCompleter<?> c; |
6467 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6469 |
|
t = (MapReduceEntriesToLongTask<K,V>)c, |
6470 |
|
s = t.rights; |
6471 |
|
while (s != null) { |
6472 |
< |
t.result = reducer.apply(t.result, s.result); |
6472 |
> |
t.result = reducer.applyAsLong(t.result, s.result); |
6473 |
|
s = t.rights = s.nextRight; |
6474 |
|
} |
6475 |
|
} |
6479 |
|
|
6480 |
|
@SuppressWarnings("serial") static final class MapReduceMappingsToLongTask<K,V> |
6481 |
|
extends Traverser<K,V,Long> { |
6482 |
< |
final ObjectByObjectToLong<? super K, ? super V> transformer; |
6483 |
< |
final LongByLongToLong reducer; |
6482 |
> |
final LongBiFunction<? super K, ? super V> transformer; |
6483 |
> |
final LongBinaryOperator reducer; |
6484 |
|
final long basis; |
6485 |
|
long result; |
6486 |
|
MapReduceMappingsToLongTask<K,V> rights, nextRight; |
6487 |
|
MapReduceMappingsToLongTask |
6488 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6489 |
|
MapReduceMappingsToLongTask<K,V> nextRight, |
6490 |
< |
ObjectByObjectToLong<? super K, ? super V> transformer, |
6490 |
> |
LongBiFunction<? super K, ? super V> transformer, |
6491 |
|
long basis, |
6492 |
< |
LongByLongToLong reducer) { |
6492 |
> |
LongBinaryOperator reducer) { |
6493 |
|
super(m, p, b); this.nextRight = nextRight; |
6494 |
|
this.transformer = transformer; |
6495 |
|
this.basis = basis; this.reducer = reducer; |
6496 |
|
} |
6497 |
|
public final Long getRawResult() { return result; } |
6498 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6499 |
< |
final ObjectByObjectToLong<? super K, ? super V> transformer; |
6500 |
< |
final LongByLongToLong reducer; |
6499 |
> |
final LongBiFunction<? super K, ? super V> transformer; |
6500 |
> |
final LongBinaryOperator reducer; |
6501 |
|
if ((transformer = this.transformer) != null && |
6502 |
|
(reducer = this.reducer) != null) { |
6503 |
|
long r = this.basis; |
6506 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6507 |
|
V v; |
6508 |
|
while ((v = advance()) != null) |
6509 |
< |
r = reducer.apply(r, transformer.apply((K)nextKey, v)); |
6509 |
> |
r = reducer.applyAsLong(r, transformer.applyAsLong((K)nextKey, v)); |
6510 |
|
result = r; |
6511 |
|
CountedCompleter<?> c; |
6512 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6514 |
|
t = (MapReduceMappingsToLongTask<K,V>)c, |
6515 |
|
s = t.rights; |
6516 |
|
while (s != null) { |
6517 |
< |
t.result = reducer.apply(t.result, s.result); |
6517 |
> |
t.result = reducer.applyAsLong(t.result, s.result); |
6518 |
|
s = t.rights = s.nextRight; |
6519 |
|
} |
6520 |
|
} |
6524 |
|
|
6525 |
|
@SuppressWarnings("serial") static final class MapReduceKeysToIntTask<K,V> |
6526 |
|
extends Traverser<K,V,Integer> { |
6527 |
< |
final ObjectToInt<? super K> transformer; |
6528 |
< |
final IntByIntToInt reducer; |
6527 |
> |
final IntFunction<? super K> transformer; |
6528 |
> |
final IntBinaryOperator reducer; |
6529 |
|
final int basis; |
6530 |
|
int result; |
6531 |
|
MapReduceKeysToIntTask<K,V> rights, nextRight; |
6532 |
|
MapReduceKeysToIntTask |
6533 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6534 |
|
MapReduceKeysToIntTask<K,V> nextRight, |
6535 |
< |
ObjectToInt<? super K> transformer, |
6535 |
> |
IntFunction<? super K> transformer, |
6536 |
|
int basis, |
6537 |
< |
IntByIntToInt reducer) { |
6537 |
> |
IntBinaryOperator reducer) { |
6538 |
|
super(m, p, b); this.nextRight = nextRight; |
6539 |
|
this.transformer = transformer; |
6540 |
|
this.basis = basis; this.reducer = reducer; |
6541 |
|
} |
6542 |
|
public final Integer getRawResult() { return result; } |
6543 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6544 |
< |
final ObjectToInt<? super K> transformer; |
6545 |
< |
final IntByIntToInt reducer; |
6544 |
> |
final IntFunction<? super K> transformer; |
6545 |
> |
final IntBinaryOperator reducer; |
6546 |
|
if ((transformer = this.transformer) != null && |
6547 |
|
(reducer = this.reducer) != null) { |
6548 |
|
int r = this.basis; |
6550 |
|
(rights = new MapReduceKeysToIntTask<K,V> |
6551 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6552 |
|
while (advance() != null) |
6553 |
< |
r = reducer.apply(r, transformer.apply((K)nextKey)); |
6553 |
> |
r = reducer.applyAsInt(r, transformer.applyAsInt((K)nextKey)); |
6554 |
|
result = r; |
6555 |
|
CountedCompleter<?> c; |
6556 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6558 |
|
t = (MapReduceKeysToIntTask<K,V>)c, |
6559 |
|
s = t.rights; |
6560 |
|
while (s != null) { |
6561 |
< |
t.result = reducer.apply(t.result, s.result); |
6561 |
> |
t.result = reducer.applyAsInt(t.result, s.result); |
6562 |
|
s = t.rights = s.nextRight; |
6563 |
|
} |
6564 |
|
} |
6568 |
|
|
6569 |
|
@SuppressWarnings("serial") static final class MapReduceValuesToIntTask<K,V> |
6570 |
|
extends Traverser<K,V,Integer> { |
6571 |
< |
final ObjectToInt<? super V> transformer; |
6572 |
< |
final IntByIntToInt reducer; |
6571 |
> |
final IntFunction<? super V> transformer; |
6572 |
> |
final IntBinaryOperator reducer; |
6573 |
|
final int basis; |
6574 |
|
int result; |
6575 |
|
MapReduceValuesToIntTask<K,V> rights, nextRight; |
6576 |
|
MapReduceValuesToIntTask |
6577 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6578 |
|
MapReduceValuesToIntTask<K,V> nextRight, |
6579 |
< |
ObjectToInt<? super V> transformer, |
6579 |
> |
IntFunction<? super V> transformer, |
6580 |
|
int basis, |
6581 |
< |
IntByIntToInt reducer) { |
6581 |
> |
IntBinaryOperator reducer) { |
6582 |
|
super(m, p, b); this.nextRight = nextRight; |
6583 |
|
this.transformer = transformer; |
6584 |
|
this.basis = basis; this.reducer = reducer; |
6585 |
|
} |
6586 |
|
public final Integer getRawResult() { return result; } |
6587 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6588 |
< |
final ObjectToInt<? super V> transformer; |
6589 |
< |
final IntByIntToInt reducer; |
6588 |
> |
final IntFunction<? super V> transformer; |
6589 |
> |
final IntBinaryOperator reducer; |
6590 |
|
if ((transformer = this.transformer) != null && |
6591 |
|
(reducer = this.reducer) != null) { |
6592 |
|
int r = this.basis; |
6595 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6596 |
|
V v; |
6597 |
|
while ((v = advance()) != null) |
6598 |
< |
r = reducer.apply(r, transformer.apply(v)); |
6598 |
> |
r = reducer.applyAsInt(r, transformer.applyAsInt(v)); |
6599 |
|
result = r; |
6600 |
|
CountedCompleter<?> c; |
6601 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6603 |
|
t = (MapReduceValuesToIntTask<K,V>)c, |
6604 |
|
s = t.rights; |
6605 |
|
while (s != null) { |
6606 |
< |
t.result = reducer.apply(t.result, s.result); |
6606 |
> |
t.result = reducer.applyAsInt(t.result, s.result); |
6607 |
|
s = t.rights = s.nextRight; |
6608 |
|
} |
6609 |
|
} |
6613 |
|
|
6614 |
|
@SuppressWarnings("serial") static final class MapReduceEntriesToIntTask<K,V> |
6615 |
|
extends Traverser<K,V,Integer> { |
6616 |
< |
final ObjectToInt<Map.Entry<K,V>> transformer; |
6617 |
< |
final IntByIntToInt reducer; |
6616 |
> |
final IntFunction<Map.Entry<K,V>> transformer; |
6617 |
> |
final IntBinaryOperator reducer; |
6618 |
|
final int basis; |
6619 |
|
int result; |
6620 |
|
MapReduceEntriesToIntTask<K,V> rights, nextRight; |
6621 |
|
MapReduceEntriesToIntTask |
6622 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6623 |
|
MapReduceEntriesToIntTask<K,V> nextRight, |
6624 |
< |
ObjectToInt<Map.Entry<K,V>> transformer, |
6624 |
> |
IntFunction<Map.Entry<K,V>> transformer, |
6625 |
|
int basis, |
6626 |
< |
IntByIntToInt reducer) { |
6626 |
> |
IntBinaryOperator reducer) { |
6627 |
|
super(m, p, b); this.nextRight = nextRight; |
6628 |
|
this.transformer = transformer; |
6629 |
|
this.basis = basis; this.reducer = reducer; |
6630 |
|
} |
6631 |
|
public final Integer getRawResult() { return result; } |
6632 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6633 |
< |
final ObjectToInt<Map.Entry<K,V>> transformer; |
6634 |
< |
final IntByIntToInt reducer; |
6633 |
> |
final IntFunction<Map.Entry<K,V>> transformer; |
6634 |
> |
final IntBinaryOperator reducer; |
6635 |
|
if ((transformer = this.transformer) != null && |
6636 |
|
(reducer = this.reducer) != null) { |
6637 |
|
int r = this.basis; |
6640 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6641 |
|
V v; |
6642 |
|
while ((v = advance()) != null) |
6643 |
< |
r = reducer.apply(r, transformer.apply(entryFor((K)nextKey, |
6643 |
> |
r = reducer.applyAsInt(r, transformer.applyAsInt(entryFor((K)nextKey, |
6644 |
|
v))); |
6645 |
|
result = r; |
6646 |
|
CountedCompleter<?> c; |
6649 |
|
t = (MapReduceEntriesToIntTask<K,V>)c, |
6650 |
|
s = t.rights; |
6651 |
|
while (s != null) { |
6652 |
< |
t.result = reducer.apply(t.result, s.result); |
6652 |
> |
t.result = reducer.applyAsInt(t.result, s.result); |
6653 |
|
s = t.rights = s.nextRight; |
6654 |
|
} |
6655 |
|
} |
6659 |
|
|
6660 |
|
@SuppressWarnings("serial") static final class MapReduceMappingsToIntTask<K,V> |
6661 |
|
extends Traverser<K,V,Integer> { |
6662 |
< |
final ObjectByObjectToInt<? super K, ? super V> transformer; |
6663 |
< |
final IntByIntToInt reducer; |
6662 |
> |
final IntBiFunction<? super K, ? super V> transformer; |
6663 |
> |
final IntBinaryOperator reducer; |
6664 |
|
final int basis; |
6665 |
|
int result; |
6666 |
|
MapReduceMappingsToIntTask<K,V> rights, nextRight; |
6667 |
|
MapReduceMappingsToIntTask |
6668 |
|
(ConcurrentHashMap<K,V> m, Traverser<K,V,?> p, int b, |
6669 |
|
MapReduceMappingsToIntTask<K,V> nextRight, |
6670 |
< |
ObjectByObjectToInt<? super K, ? super V> transformer, |
6670 |
> |
IntBiFunction<? super K, ? super V> transformer, |
6671 |
|
int basis, |
6672 |
< |
IntByIntToInt reducer) { |
6672 |
> |
IntBinaryOperator reducer) { |
6673 |
|
super(m, p, b); this.nextRight = nextRight; |
6674 |
|
this.transformer = transformer; |
6675 |
|
this.basis = basis; this.reducer = reducer; |
6676 |
|
} |
6677 |
|
public final Integer getRawResult() { return result; } |
6678 |
|
@SuppressWarnings("unchecked") public final void compute() { |
6679 |
< |
final ObjectByObjectToInt<? super K, ? super V> transformer; |
6680 |
< |
final IntByIntToInt reducer; |
6679 |
> |
final IntBiFunction<? super K, ? super V> transformer; |
6680 |
> |
final IntBinaryOperator reducer; |
6681 |
|
if ((transformer = this.transformer) != null && |
6682 |
|
(reducer = this.reducer) != null) { |
6683 |
|
int r = this.basis; |
6686 |
|
(map, this, b, rights, transformer, r, reducer)).fork(); |
6687 |
|
V v; |
6688 |
|
while ((v = advance()) != null) |
6689 |
< |
r = reducer.apply(r, transformer.apply((K)nextKey, v)); |
6689 |
> |
r = reducer.applyAsInt(r, transformer.applyAsInt((K)nextKey, v)); |
6690 |
|
result = r; |
6691 |
|
CountedCompleter<?> c; |
6692 |
|
for (c = firstComplete(); c != null; c = c.nextComplete()) { |
6694 |
|
t = (MapReduceMappingsToIntTask<K,V>)c, |
6695 |
|
s = t.rights; |
6696 |
|
while (s != null) { |
6697 |
< |
t.result = reducer.apply(t.result, s.result); |
6697 |
> |
t.result = reducer.applyAsInt(t.result, s.result); |
6698 |
|
s = t.rights = s.nextRight; |
6699 |
|
} |
6700 |
|
} |
6708 |
|
private static final long TRANSFERINDEX; |
6709 |
|
private static final long TRANSFERORIGIN; |
6710 |
|
private static final long BASECOUNT; |
6711 |
< |
private static final long COUNTERBUSY; |
6711 |
> |
private static final long CELLSBUSY; |
6712 |
|
private static final long CELLVALUE; |
6713 |
|
private static final long ABASE; |
6714 |
|
private static final int ASHIFT; |
6726 |
|
(k.getDeclaredField("transferOrigin")); |
6727 |
|
BASECOUNT = U.objectFieldOffset |
6728 |
|
(k.getDeclaredField("baseCount")); |
6729 |
< |
COUNTERBUSY = U.objectFieldOffset |
6730 |
< |
(k.getDeclaredField("counterBusy")); |
6731 |
< |
Class<?> ck = CounterCell.class; |
6729 |
> |
CELLSBUSY = U.objectFieldOffset |
6730 |
> |
(k.getDeclaredField("cellsBusy")); |
6731 |
> |
Class<?> ck = Cell.class; |
6732 |
|
CELLVALUE = U.objectFieldOffset |
6733 |
|
(ck.getDeclaredField("value")); |
6734 |
|
Class<?> sc = Node[].class; |