1 |
/* |
2 |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
* Expert Group and released to the public domain, as explained at |
4 |
* http://creativecommons.org/licenses/publicdomain |
5 |
*/ |
6 |
|
7 |
package jsr166y.forkjoin; |
8 |
import static jsr166y.forkjoin.Ops.*; |
9 |
import java.util.*; |
10 |
import java.util.concurrent.atomic.*; |
11 |
import java.lang.reflect.Array; |
12 |
|
13 |
/** |
14 |
* Abstract class serving as the basis of parallel |
15 |
* array classes across types. |
16 |
*/ |
17 |
public abstract class AbstractParallelAnyArray { |
18 |
/* |
19 |
* This class and its subclasses (most of which are defined here |
20 |
* as nested static classes) maintain the execution parameters for |
21 |
* ParallelArray, ParallelDoubleArray, and ParallelLongArray |
22 |
* tasks. Pap instances hold the non-operation-specific control |
23 |
* and data accessors needed for a task as a whole (as opposed to |
24 |
* subtasks), and also house some of the leaf methods that perform |
25 |
* the actual array processing. The leaf methods are for the most |
26 |
* part just plain array operations. They are boringly repetitive |
27 |
* in order to flatten out and minimize inner-loop overhead, as |
28 |
* well as to minimize call-chain depth. This makes it more likely |
29 |
* that dynamic compilers can go the rest of the way, and hoist |
30 |
* per-element method call dispatch, so we have a good chance to |
31 |
* speed up processing via parallelism rather than lose due to |
32 |
* dispatch and indirection overhead. The dispatching from Pap to |
33 |
* FJ and back is otherwise Visitor-pattern-like, allowing the |
34 |
* basic parallelism control for most FJ tasks to be centralized. |
35 |
* |
36 |
* Note the extensive use of raw types. Arrays and generics do not |
37 |
* work together very well. It is more manageable to avoid them here, |
38 |
* and let the public classes perform casts in and out to the |
39 |
* processing here. Also note that the majority of code in concrete |
40 |
* classes is just for managing the various flavors created using |
41 |
* with* methods. |
42 |
* |
43 |
* Internal concrete classes are named using an |
44 |
* abbreviation scheme to avoid mile-long class names: |
45 |
* O, D, L for Object, Double, Long, for underlying Parallel array |
46 |
* U - unfiltered |
47 |
* F - filtered |
48 |
* R - relation-filtered (aka index-filtered) |
49 |
* OM, DM, LM - Mapped |
50 |
* OC, DC, LC - combiner-mapped (aka index-mapped) |
51 |
*/ |
52 |
|
53 |
final ForkJoinExecutor ex; |
54 |
final int origin; |
55 |
int fence; |
56 |
int threshold; |
57 |
|
58 |
AbstractParallelAnyArray(ForkJoinExecutor ex, int origin, int fence) { |
59 |
this.ex = ex; |
60 |
this.origin = origin; |
61 |
this.fence = fence; |
62 |
} |
63 |
|
64 |
// A few public methods exported across all subclasses |
65 |
|
66 |
/** |
67 |
* Return the number of elements selected using bound or |
68 |
* filter restrictions. Note that this method must evaluate |
69 |
* all selectors to return its result. |
70 |
* @return the number of elements |
71 |
*/ |
72 |
public int size() { |
73 |
if (!hasFilter()) |
74 |
return fence - origin; |
75 |
PAS.FJCountSelected f = new PAS.FJCountSelected |
76 |
(this, origin, fence, null); |
77 |
ex.invoke(f); |
78 |
return f.count; |
79 |
} |
80 |
|
81 |
/** |
82 |
* Returns the index of some element matching bound and filter |
83 |
* constraints, or -1 if none. |
84 |
* @return index of matching element, or -1 if none. |
85 |
*/ |
86 |
public int anyIndex() { |
87 |
if (!hasFilter()) |
88 |
return (origin < fence)? origin : -1; |
89 |
AtomicInteger result = new AtomicInteger(-1); |
90 |
PAS.FJSelectAny f = new PAS.FJSelectAny |
91 |
(this, origin, fence, null, result); |
92 |
ex.invoke(f); |
93 |
return result.get(); |
94 |
} |
95 |
|
96 |
/** |
97 |
* Returns true if there are no elements |
98 |
* @return true if there are no elements |
99 |
*/ |
100 |
public boolean isEmpty() { |
101 |
return anyIndex() < 0; |
102 |
} |
103 |
|
104 |
|
105 |
/** |
106 |
* Returns size threshold for splitting into subtask. By |
107 |
* default, uses about 8 times as many tasks as threads |
108 |
*/ |
109 |
final int computeThreshold() { |
110 |
int n = fence - origin; |
111 |
int p = ex.getParallelismLevel(); |
112 |
return threshold = (p > 1) ? (1 + n / (p << 3)) : n; |
113 |
} |
114 |
|
115 |
/** |
116 |
* Returns lazily computed threshold. |
117 |
*/ |
118 |
final int getThreshold() { |
119 |
int t = threshold; |
120 |
if (t == 0) |
121 |
t = computeThreshold(); |
122 |
return t; |
123 |
} |
124 |
|
125 |
/** |
126 |
* Access methods for ref, double, long. Checking for |
127 |
* null/false return is used as a sort of type test. These |
128 |
* are used to avoid duplication in non-performance-critical |
129 |
* aspects of control, as well as to provide a simple default |
130 |
* mechanism for extensions. |
131 |
*/ |
132 |
Object[] ogetArray() { return null; } |
133 |
double[] dgetArray() { return null; } |
134 |
long[] lgetArray() { return null; } |
135 |
abstract Object oget(int index); |
136 |
abstract double dget(int index); |
137 |
abstract long lget(int index); |
138 |
boolean hasMap() { return false; } |
139 |
boolean hasFilter() { return false; } |
140 |
boolean isSelected(int index) { return true; } |
141 |
|
142 |
/* |
143 |
* Leaf methods for FJ tasks. Default versions use isSelected, |
144 |
* oget, dget, etc. But most are overridden in most concrete |
145 |
* classes to avoid per-element dispatching. |
146 |
*/ |
147 |
void leafApply(int lo, int hi, Procedure procedure) { |
148 |
for (int i = lo; i < hi; ++i) |
149 |
if (isSelected(i)) |
150 |
procedure.op(oget(i)); |
151 |
} |
152 |
|
153 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
154 |
for (int i = lo; i < hi; ++i) |
155 |
if (isSelected(i)) |
156 |
procedure.op(dget(i)); |
157 |
} |
158 |
|
159 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
160 |
for (int i = lo; i < hi; ++i) |
161 |
if (isSelected(i)) |
162 |
procedure.op(lget(i)); |
163 |
} |
164 |
|
165 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
166 |
boolean gotFirst = false; |
167 |
Object r = base; |
168 |
for (int i = lo; i < hi; ++i) { |
169 |
if (isSelected(i)) { |
170 |
Object x = oget(i); |
171 |
if (!gotFirst) { |
172 |
gotFirst = true; |
173 |
r = x; |
174 |
} |
175 |
else |
176 |
r = reducer.op(r, x); |
177 |
} |
178 |
} |
179 |
return r; |
180 |
} |
181 |
|
182 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
183 |
boolean gotFirst = false; |
184 |
double r = base; |
185 |
for (int i = lo; i < hi; ++i) { |
186 |
if (isSelected(i)) { |
187 |
double x = dget(i); |
188 |
if (!gotFirst) { |
189 |
gotFirst = true; |
190 |
r = x; |
191 |
} |
192 |
else |
193 |
r = reducer.op(r, x); |
194 |
} |
195 |
} |
196 |
return r; |
197 |
} |
198 |
|
199 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
200 |
boolean gotFirst = false; |
201 |
long r = base; |
202 |
for (int i = lo; i < hi; ++i) { |
203 |
if (isSelected(i)) { |
204 |
long x = lget(i); |
205 |
if (!gotFirst) { |
206 |
gotFirst = true; |
207 |
r = x; |
208 |
} |
209 |
else |
210 |
r = reducer.op(r, x); |
211 |
} |
212 |
} |
213 |
return r; |
214 |
} |
215 |
|
216 |
// copy elements, ignoring selector, but applying mapping |
217 |
void leafTransfer(int lo, int hi, Object[] dest, int offset) { |
218 |
for (int i = lo; i < hi; ++i) |
219 |
dest[offset++] = oget(i); |
220 |
} |
221 |
|
222 |
void leafTransfer(int lo, int hi, double[] dest, int offset) { |
223 |
for (int i = lo; i < hi; ++i) |
224 |
dest[offset++] = dget(i); |
225 |
} |
226 |
|
227 |
void leafTransfer(int lo, int hi, long[] dest, int offset) { |
228 |
for (int i = lo; i < hi; ++i) |
229 |
dest[offset++] = lget(i); |
230 |
} |
231 |
|
232 |
// copy elements indexed in indices[loIdx..hiIdx], ignoring |
233 |
// selector, but applying mapping |
234 |
void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
235 |
Object[] dest, int offset) { |
236 |
for (int i = loIdx; i < hiIdx; ++i) |
237 |
dest[offset++] = oget(indices[i]); |
238 |
} |
239 |
|
240 |
void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
241 |
double[] dest, int offset) { |
242 |
for (int i = loIdx; i < hiIdx; ++i) |
243 |
dest[offset++] = dget(indices[i]); |
244 |
} |
245 |
|
246 |
void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
247 |
long[] dest, int offset) { |
248 |
for (int i = loIdx; i < hiIdx; ++i) |
249 |
dest[offset++] = lget(indices[i]); |
250 |
} |
251 |
|
252 |
// add indices of selected elements to index array; return #added |
253 |
final int leafIndexSelected(int lo, int hi, boolean positive, |
254 |
int[] indices) { |
255 |
int k = 0; |
256 |
for (int i = lo; i < hi; ++i) { |
257 |
if (isSelected(i) == positive) |
258 |
indices[lo + k++] = i; |
259 |
} |
260 |
return k; |
261 |
} |
262 |
|
263 |
// move selected elements to indices starting at offset, |
264 |
// return final offset |
265 |
abstract int leafMoveSelected(int lo, int hi, int offset, |
266 |
boolean positive); |
267 |
|
268 |
// move elements indexed by indices[loIdx...hiIdx] starting |
269 |
// at given offset |
270 |
abstract void leafMoveByIndex(int[] indices, int loIdx, |
271 |
int hiIdx, int offset); |
272 |
|
273 |
/** |
274 |
* Shared support for select/map all -- probe filter, map, and |
275 |
* type to start selection driver, or do parallel mapping, or |
276 |
* just copy, |
277 |
*/ |
278 |
final Object[] allObjects(Class elementType) { |
279 |
if (hasFilter()) { |
280 |
if (elementType == null) { |
281 |
if (!hasMap()) |
282 |
elementType = ogetArray().getClass().getComponentType(); |
283 |
else |
284 |
elementType = Object.class; |
285 |
} |
286 |
PAS.FJOSelectAllDriver r = new PAS.FJOSelectAllDriver |
287 |
(this, elementType); |
288 |
ex.invoke(r); |
289 |
return r.results; |
290 |
} |
291 |
else { |
292 |
int n = fence - origin; |
293 |
Object[] dest; |
294 |
if (hasMap()) { |
295 |
if (elementType == null) |
296 |
dest = new Object[n]; |
297 |
else |
298 |
dest = (Object[])Array.newInstance(elementType, n); |
299 |
ex.invoke(new PAS.FJOMap(this, origin, fence, |
300 |
null, dest, -origin)); |
301 |
} |
302 |
else { |
303 |
Object[] array = ogetArray(); |
304 |
if (elementType == null) |
305 |
elementType = array.getClass().getComponentType(); |
306 |
dest = (Object[])Array.newInstance(elementType, n); |
307 |
System.arraycopy(array, origin, dest, 0, n); |
308 |
} |
309 |
return dest; |
310 |
} |
311 |
} |
312 |
|
313 |
final double[] allDoubles() { |
314 |
if (hasFilter()) { |
315 |
PAS.FJDSelectAllDriver r = new PAS.FJDSelectAllDriver(this); |
316 |
ex.invoke(r); |
317 |
return r.results; |
318 |
} |
319 |
else { |
320 |
int n = fence - origin; |
321 |
double[] dest = new double[n]; |
322 |
if (hasMap()) { |
323 |
ex.invoke(new PAS.FJDMap(this, origin, fence, |
324 |
null, dest, -origin)); |
325 |
} |
326 |
else { |
327 |
double[] array = dgetArray(); |
328 |
System.arraycopy(array, origin, dest, 0, n); |
329 |
} |
330 |
return dest; |
331 |
} |
332 |
} |
333 |
|
334 |
final long[] allLongs() { |
335 |
if (hasFilter()) { |
336 |
PAS.FJLSelectAllDriver r = new PAS.FJLSelectAllDriver(this); |
337 |
ex.invoke(r); |
338 |
return r.results; |
339 |
} |
340 |
else { |
341 |
int n = fence - origin; |
342 |
long[] dest = new long[n]; |
343 |
if (hasMap()) { |
344 |
ex.invoke(new PAS.FJLMap(this, origin, fence, |
345 |
null, dest, -origin)); |
346 |
} |
347 |
else { |
348 |
long[] array = lgetArray(); |
349 |
System.arraycopy(array, origin, dest, 0, n); |
350 |
} |
351 |
return dest; |
352 |
} |
353 |
} |
354 |
|
355 |
// Bounds check a range |
356 |
void boundsCheck(int lo, int hi) { |
357 |
if (lo > hi) |
358 |
throw new IllegalArgumentException(origin + " > " + fence); |
359 |
if (lo < 0) |
360 |
throw new ArrayIndexOutOfBoundsException(origin); |
361 |
if (hi - lo > this.fence - this.origin) |
362 |
throw new ArrayIndexOutOfBoundsException(fence); |
363 |
} |
364 |
|
365 |
/* |
366 |
* The following methods can be called only for classes |
367 |
* supporting in-place replacements (currently, those classes |
368 |
* without mappings). They are declared as no-ops here, and |
369 |
* overridden only where applicable. |
370 |
*/ |
371 |
|
372 |
void leafTransform(int l, int h, Op op) {} |
373 |
void leafIndexMap(int l, int h, IntToObject op) {} |
374 |
void leafBinaryIndexMap(int l, int h, IntAndObjectToObject op) {} |
375 |
void leafGenerate(int l, int h, Generator generator) {} |
376 |
void leafFill(int l, int h, Object value) {} |
377 |
void leafCombineInPlace(int lo, int hi, Object[] other, |
378 |
int otherOffset, BinaryOp combiner) {} |
379 |
void leafCombineInPlace(int lo, int hi, ParallelArrayWithMapping other, |
380 |
int otherOffset, BinaryOp combiner) {} |
381 |
|
382 |
void leafTransform(int l, int h, DoubleOp op) {} |
383 |
void leafIndexMap(int l, int h, IntToDouble array) {} |
384 |
void leafBinaryIndexMap(int l, int h, IntAndDoubleToDouble op) {} |
385 |
void leafGenerate(int l, int h, DoubleGenerator generator) {} |
386 |
void leafFill(int l, int h, double value) {} |
387 |
void leafCombineInPlace(int lo, int hi, double[] other, |
388 |
int otherOffset, BinaryDoubleOp combiner) {} |
389 |
void leafCombineInPlace(int lo, int hi, |
390 |
ParallelDoubleArrayWithDoubleMapping other, |
391 |
int otherOffset, BinaryDoubleOp combiner) {} |
392 |
|
393 |
void leafTransform(int l, int h, LongOp op) {} |
394 |
void leafIndexMap(int l, int h, IntToLong array) {} |
395 |
void leafBinaryIndexMap(int l, int h, IntAndLongToLong op) {} |
396 |
void leafGenerate(int l, int h, LongGenerator generator) {} |
397 |
void leafFill(int l, int h, long value) {} |
398 |
void leafCombineInPlace(int lo, int hi, long[] other, |
399 |
int otherOffset, BinaryLongOp combiner) {} |
400 |
void leafCombineInPlace(int lo, int hi, |
401 |
ParallelLongArrayWithLongMapping other, |
402 |
int otherOffset, BinaryLongOp combiner) {} |
403 |
|
404 |
// Base of object ref array classes |
405 |
static abstract class OPap<T> extends AbstractParallelAnyArray { |
406 |
T[] array; |
407 |
OPap(ForkJoinExecutor ex, int origin, int fence, T[] array) { |
408 |
super(ex, origin, fence); |
409 |
this.array = array; |
410 |
} |
411 |
|
412 |
final Object[] ogetArray() { return this.array; } |
413 |
double dget(int i) { return ((Number)oget(i)).doubleValue(); } |
414 |
long lget(int i) { return ((Number)oget(i)).longValue(); } |
415 |
|
416 |
final void leafMoveByIndex(int[] indices, int loIdx, |
417 |
int hiIdx, int offset) { |
418 |
final Object[] array = this.array; |
419 |
for (int i = loIdx; i < hiIdx; ++i) |
420 |
array[offset++] = array[indices[i]]; |
421 |
} |
422 |
|
423 |
final int leafMoveSelected(int lo, int hi, int offset, |
424 |
boolean positive) { |
425 |
final Object[] array = this.array; |
426 |
for (int i = lo; i < hi; ++i) { |
427 |
if (isSelected(i) == positive) |
428 |
array[offset++] = array[i]; |
429 |
} |
430 |
return offset; |
431 |
} |
432 |
} |
433 |
|
434 |
// Base of double array classes |
435 |
static abstract class DPap extends AbstractParallelAnyArray { |
436 |
double[] array; |
437 |
DPap(ForkJoinExecutor ex, int origin, int fence, double[] array) { |
438 |
super(ex, origin, fence); |
439 |
this.array = array; |
440 |
} |
441 |
|
442 |
final double[] dgetArray() { return this.array; } |
443 |
Object oget(int i) { return Double.valueOf(dget(i)); } |
444 |
long lget(int i) { return (long)(dget(i)); } |
445 |
|
446 |
final void leafMoveByIndex(int[] indices, int loIdx, |
447 |
int hiIdx, int offset) { |
448 |
final double[] array = this.array; |
449 |
for (int i = loIdx; i < hiIdx; ++i) |
450 |
array[offset++] = array[indices[i]]; |
451 |
} |
452 |
|
453 |
final int leafMoveSelected(int lo, int hi, int offset, |
454 |
boolean positive) { |
455 |
final double[] array = this.array; |
456 |
for (int i = lo; i < hi; ++i) { |
457 |
if (isSelected(i) == positive) |
458 |
array[offset++] = array[i]; |
459 |
} |
460 |
return offset; |
461 |
} |
462 |
} |
463 |
|
464 |
// Base of long array classes |
465 |
static abstract class LPap extends AbstractParallelAnyArray { |
466 |
long[] array; |
467 |
LPap(ForkJoinExecutor ex, int origin, int fence, long[] array) { |
468 |
super(ex, origin, fence); |
469 |
this.array = array; |
470 |
} |
471 |
|
472 |
final long[] lgetArray() { return this.array; } |
473 |
Object oget(int i) { return Long.valueOf(lget(i)); } |
474 |
double dget(int i) { return (double)(lget(i)); } |
475 |
|
476 |
final void leafMoveByIndex(int[] indices, int loIdx, |
477 |
int hiIdx, int offset) { |
478 |
final long[] array = this.array; |
479 |
for (int i = loIdx; i < hiIdx; ++i) |
480 |
array[offset++] = array[indices[i]]; |
481 |
} |
482 |
|
483 |
final int leafMoveSelected(int lo, int hi, int offset, |
484 |
boolean positive) { |
485 |
final long[] array = this.array; |
486 |
for (int i = lo; i < hi; ++i) { |
487 |
if (isSelected(i) == positive) |
488 |
array[offset++] = array[i]; |
489 |
} |
490 |
return offset; |
491 |
} |
492 |
} |
493 |
|
494 |
// Plain (unfiltered, unmapped) classes |
495 |
static class OUPap<T> extends ParallelArrayWithBounds<T> { |
496 |
OUPap(ForkJoinExecutor ex, int origin, int fence, T[] array) { |
497 |
super(ex, origin, fence, array); |
498 |
} |
499 |
|
500 |
public ParallelArrayWithBounds<T> withBounds(int lo, int hi) { |
501 |
boundsCheck(lo, hi); |
502 |
return new OUPap<T>(ex, origin + lo, origin + hi, array); |
503 |
} |
504 |
|
505 |
public ParallelArrayWithFilter<T> withFilter |
506 |
(Predicate<? super T> selector) { |
507 |
return new OFPap<T>(ex, origin, fence, array, selector); |
508 |
} |
509 |
|
510 |
public ParallelArrayWithFilter<T> withIndexedFilter |
511 |
(IntAndObjectPredicate<? super T> selector) { |
512 |
return new ORPap<T>(ex, origin, fence, array, selector); |
513 |
} |
514 |
|
515 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
516 |
(Op<? super T, ? extends U> op) { |
517 |
return new OUOMPap<T,U>(ex, origin, fence, array, op); |
518 |
} |
519 |
|
520 |
public ParallelArrayWithDoubleMapping<T> withMapping |
521 |
(ObjectToDouble<? super T> op) { |
522 |
return new OUDMPap<T>(ex, origin, fence, array, op); |
523 |
} |
524 |
|
525 |
public ParallelArrayWithLongMapping<T> withMapping |
526 |
(ObjectToLong<? super T> op) { |
527 |
return new OULMPap<T>(ex, origin, fence, array, op); |
528 |
} |
529 |
|
530 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
531 |
(IntAndObjectToObject<? super T, ? extends V> mapper) { |
532 |
return new OUOCPap<T,V>(ex, origin, fence, array, mapper); |
533 |
} |
534 |
|
535 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
536 |
(IntAndObjectToDouble<? super T> mapper) { |
537 |
return new OUDCPap<T>(ex, origin, fence, array, mapper); |
538 |
} |
539 |
|
540 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
541 |
(IntAndObjectToLong<? super T> mapper) { |
542 |
return new OULCPap<T>(ex, origin, fence, array, mapper); |
543 |
} |
544 |
|
545 |
public int indexOf(T target) { |
546 |
AtomicInteger result = new AtomicInteger(-1); |
547 |
PAS.FJOIndexOf f = new PAS.FJOIndexOf |
548 |
(this, origin, fence, null, result, target); |
549 |
ex.invoke(f); |
550 |
return result.get(); |
551 |
} |
552 |
|
553 |
public int binarySearch(T target) { |
554 |
final Object[] a = this.array; |
555 |
int lo = origin; |
556 |
int hi = fence - 1; |
557 |
while (lo <= hi) { |
558 |
int mid = (lo + hi) >>> 1; |
559 |
int c = ((Comparable)target).compareTo((Comparable)a[mid]); |
560 |
if (c == 0) |
561 |
return mid; |
562 |
else if (c < 0) |
563 |
hi = mid - 1; |
564 |
else |
565 |
lo = mid + 1; |
566 |
} |
567 |
return -1; |
568 |
} |
569 |
|
570 |
public int binarySearch(T target, Comparator<? super T> comparator) { |
571 |
Comparator cmp = comparator; |
572 |
final Object[] a = this.array; |
573 |
int lo = origin; |
574 |
int hi = fence - 1; |
575 |
while (lo <= hi) { |
576 |
int mid = (lo + hi) >>> 1; |
577 |
int c = cmp.compare(target, a[mid]); |
578 |
if (c == 0) |
579 |
return mid; |
580 |
else if (c < 0) |
581 |
hi = mid - 1; |
582 |
else |
583 |
lo = mid + 1; |
584 |
} |
585 |
return -1; |
586 |
} |
587 |
|
588 |
public ParallelArrayWithBounds<T> cumulate(Reducer<T> reducer, T base) { |
589 |
PAS.FJOCumulateOp op = new PAS.FJOCumulateOp(this, reducer, base); |
590 |
PAS.FJOScan r = new PAS.FJOScan(null, op, origin, fence); |
591 |
ex.invoke(r); |
592 |
return this; |
593 |
} |
594 |
|
595 |
public T precumulate(Reducer<T> reducer, T base) { |
596 |
PAS.FJOPrecumulateOp op = new PAS.FJOPrecumulateOp |
597 |
(this, reducer, base); |
598 |
PAS.FJOScan r = new PAS.FJOScan(null, op, origin, fence); |
599 |
ex.invoke(r); |
600 |
return (T)(r.out); |
601 |
} |
602 |
|
603 |
public ParallelArrayWithBounds<T> sort |
604 |
(Comparator<? super T> cmp) { |
605 |
final Object[] a = this.array; |
606 |
Class tc = array.getClass().getComponentType(); |
607 |
T[] ws = (T[])Array.newInstance(tc, fence); |
608 |
ex.invoke(new PAS.FJOSorter |
609 |
(cmp, array, ws, origin, |
610 |
fence - origin, getThreshold())); |
611 |
return this; |
612 |
} |
613 |
|
614 |
public ParallelArrayWithBounds<T> sort() { |
615 |
final Object[] a = this.array; |
616 |
Class tc = array.getClass().getComponentType(); |
617 |
if (!Comparable.class.isAssignableFrom(tc)) { |
618 |
sort(CommonOps.castedComparator()); |
619 |
} |
620 |
else { |
621 |
Comparable[] ca = (Comparable[])array; |
622 |
Comparable[] ws = (Comparable[])Array.newInstance(tc, fence); |
623 |
ex.invoke(new PAS.FJOCSorter |
624 |
(ca, ws, origin, |
625 |
fence - origin, getThreshold())); |
626 |
} |
627 |
return this; |
628 |
} |
629 |
|
630 |
final void leafApply(int lo, int hi, Procedure procedure) { |
631 |
final Object[] a = this.array; |
632 |
for (int i = lo; i < hi; ++i) |
633 |
procedure.op(a[i]); |
634 |
} |
635 |
|
636 |
final Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
637 |
if (lo >= hi) |
638 |
return base; |
639 |
final Object[] a = this.array; |
640 |
Object r = a[lo]; |
641 |
for (int i = lo+1; i < hi; ++i) |
642 |
r = reducer.op(r, a[i]); |
643 |
return r; |
644 |
} |
645 |
|
646 |
final void leafTransform(int l, int h, Op op) { |
647 |
final Object[] a = this.array; |
648 |
for (int i = l; i < h; ++i) |
649 |
a[i] = op.op(a[i]); |
650 |
} |
651 |
|
652 |
final void leafIndexMap(int l, int h, IntToObject op) { |
653 |
final Object[] a = this.array; |
654 |
for (int i = l; i < h; ++i) |
655 |
a[i] = op.op(i); |
656 |
} |
657 |
|
658 |
final void leafBinaryIndexMap(int l, int h, IntAndObjectToObject op) { |
659 |
final Object[] a = this.array; |
660 |
for (int i = l; i < h; ++i) |
661 |
a[i] = op.op(i, a[i]); |
662 |
} |
663 |
|
664 |
final void leafGenerate(int l, int h, Generator generator) { |
665 |
final Object[] a = this.array; |
666 |
for (int i = l; i < h; ++i) |
667 |
a[i] = generator.op(); |
668 |
} |
669 |
|
670 |
final void leafFill(int l, int h, Object value) { |
671 |
final Object[] a = this.array; |
672 |
for (int i = l; i < h; ++i) |
673 |
a[i] = value; |
674 |
} |
675 |
|
676 |
final void leafCombineInPlace(int l, int h, Object[] other, |
677 |
int otherOffset, BinaryOp combiner) { |
678 |
final Object[] a = this.array; |
679 |
int k = l + otherOffset; |
680 |
for (int i = l; i < h; ++i) |
681 |
a[i] = combiner.op(a[i], other[k++]); |
682 |
} |
683 |
|
684 |
final void leafCombineInPlace(int l, int h, |
685 |
ParallelArrayWithMapping other, |
686 |
int otherOffset, BinaryOp combiner) { |
687 |
final Object[] a = this.array; |
688 |
int k = l + otherOffset; |
689 |
if (other.hasFilter()) { |
690 |
for (int i = l; i < h; ++i) { |
691 |
if (other.isSelected(k)) |
692 |
a[i] = combiner.op(a[i], other.oget(k)); |
693 |
k++; |
694 |
} |
695 |
} |
696 |
else if (other.hasMap()) { |
697 |
for (int i = l; i < h; ++i) |
698 |
a[i] = combiner.op(a[i], other.oget(k++)); |
699 |
} |
700 |
else { |
701 |
Object[] b = other.array; |
702 |
for (int i = l; i < h; ++i) |
703 |
a[i] = combiner.op(a[i], b[k++]); |
704 |
} |
705 |
} |
706 |
} |
707 |
|
708 |
static class DUPap extends ParallelDoubleArrayWithBounds { |
709 |
DUPap(ForkJoinExecutor ex, int origin, int fence, double[] array) { |
710 |
super(ex, origin, fence, array); |
711 |
} |
712 |
|
713 |
public ParallelDoubleArrayWithBounds withBounds(int lo, int hi) { |
714 |
boundsCheck(lo, hi); |
715 |
return new DUPap(ex, origin + lo, origin + hi, array); |
716 |
} |
717 |
|
718 |
public ParallelDoubleArrayWithFilter withFilter(DoublePredicate selector) { |
719 |
return new DFPap(ex, origin, fence, array, selector); |
720 |
} |
721 |
|
722 |
public ParallelDoubleArrayWithFilter withIndexedFilter |
723 |
(IntAndDoublePredicate selector) { |
724 |
return new DRPap(ex, origin, fence, array, selector); |
725 |
} |
726 |
|
727 |
public <U> ParallelDoubleArrayWithMapping<U> withMapping |
728 |
(DoubleToObject<? extends U> op) { |
729 |
return new DUOMPap<U>(ex, origin, fence, array, op); |
730 |
} |
731 |
|
732 |
public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { |
733 |
return new DUDMPap(ex, origin, fence, array, op); |
734 |
} |
735 |
|
736 |
public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { |
737 |
return new DULMPap(ex, origin, fence, array, op); |
738 |
} |
739 |
|
740 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
741 |
(IntAndDoubleToObject<? extends V> mapper) { |
742 |
return new DUOCPap<V>(ex, origin, fence, array, mapper); |
743 |
} |
744 |
|
745 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
746 |
(IntAndDoubleToDouble mapper) { |
747 |
return new DUDCPap(ex, origin, fence, array, mapper); |
748 |
} |
749 |
|
750 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
751 |
(IntAndDoubleToLong mapper) { |
752 |
return new DULCPap(ex, origin, fence, array, mapper); |
753 |
} |
754 |
|
755 |
public int indexOf(double target) { |
756 |
AtomicInteger result = new AtomicInteger(-1); |
757 |
PAS.FJDIndexOf f = new PAS.FJDIndexOf |
758 |
(this, origin, fence, null, result, target); |
759 |
ex.invoke(f); |
760 |
return result.get(); |
761 |
} |
762 |
|
763 |
public int binarySearch(double target) { |
764 |
final double[] a = this.array; |
765 |
int lo = origin; |
766 |
int hi = fence - 1; |
767 |
while (lo <= hi) { |
768 |
int mid = (lo + hi) >>> 1; |
769 |
double m = a[mid]; |
770 |
if (target == m) |
771 |
return mid; |
772 |
else if (target < m) |
773 |
hi = mid - 1; |
774 |
else |
775 |
lo = mid + 1; |
776 |
} |
777 |
return -1; |
778 |
} |
779 |
|
780 |
public int binarySearch(double target, DoubleComparator comparator) { |
781 |
final double[] a = this.array; |
782 |
int lo = origin; |
783 |
int hi = fence - 1; |
784 |
while (lo <= hi) { |
785 |
int mid = (lo + hi) >>> 1; |
786 |
int c = comparator.compare(target, a[mid]); |
787 |
if (c == 0) |
788 |
return mid; |
789 |
else if (c < 0) |
790 |
hi = mid - 1; |
791 |
else |
792 |
lo = mid + 1; |
793 |
} |
794 |
return -1; |
795 |
} |
796 |
|
797 |
public ParallelDoubleArrayWithBounds cumulate(DoubleReducer reducer, |
798 |
double base) { |
799 |
PAS.FJDCumulateOp op = new PAS.FJDCumulateOp(this, reducer, base); |
800 |
PAS.FJDScan r = new PAS.FJDScan(null, op, origin, fence); |
801 |
ex.invoke(r); |
802 |
return this; |
803 |
} |
804 |
|
805 |
public ParallelDoubleArrayWithBounds cumulateSum() { |
806 |
PAS.FJDCumulatePlusOp op = new PAS.FJDCumulatePlusOp(this); |
807 |
PAS.FJDScan r = new PAS.FJDScan(null, op, origin, fence); |
808 |
ex.invoke(r); |
809 |
return this; |
810 |
} |
811 |
|
812 |
public double precumulate(DoubleReducer reducer, double base) { |
813 |
PAS.FJDPrecumulateOp op = new PAS.FJDPrecumulateOp(this, reducer, base); |
814 |
PAS.FJDScan r = new PAS.FJDScan(null, op, origin, fence); |
815 |
ex.invoke(r); |
816 |
return r.out; |
817 |
} |
818 |
|
819 |
public double precumulateSum() { |
820 |
PAS.FJDPrecumulatePlusOp op = new PAS.FJDPrecumulatePlusOp(this); |
821 |
PAS.FJDScan r = new PAS.FJDScan(null, op, origin, fence); |
822 |
ex.invoke(r); |
823 |
return r.out; |
824 |
} |
825 |
|
826 |
public ParallelDoubleArrayWithBounds sort(DoubleComparator cmp) { |
827 |
ex.invoke(new PAS.FJDSorter |
828 |
(cmp, this.array, new double[fence], |
829 |
origin, fence - origin, getThreshold())); |
830 |
return this; |
831 |
} |
832 |
|
833 |
public ParallelDoubleArrayWithBounds sort() { |
834 |
ex.invoke(new PAS.FJDCSorter |
835 |
(this.array, new double[fence], |
836 |
origin, fence - origin, getThreshold())); |
837 |
return this; |
838 |
} |
839 |
|
840 |
final void leafApply(int lo, int hi, DoubleProcedure procedure) { |
841 |
final double[] a = this.array; |
842 |
for (int i = lo; i < hi; ++i) |
843 |
procedure.op(a[i]); |
844 |
} |
845 |
|
846 |
final double leafReduce(int lo, int hi, DoubleReducer reducer, |
847 |
double base) { |
848 |
if (lo >= hi) |
849 |
return base; |
850 |
final double[] a = this.array; |
851 |
double r = a[lo]; |
852 |
for (int i = lo+1; i < hi; ++i) |
853 |
r = reducer.op(r, a[i]); |
854 |
return r; |
855 |
} |
856 |
|
857 |
final void leafTransform(int l, int h, DoubleOp op) { |
858 |
final double[] a = this.array; |
859 |
for (int i = l; i < h; ++i) |
860 |
a[i] = op.op(a[i]); |
861 |
} |
862 |
|
863 |
final void leafIndexMap(int l, int h, IntToDouble op) { |
864 |
final double[] a = this.array; |
865 |
for (int i = l; i < h; ++i) |
866 |
a[i] = op.op(i); |
867 |
} |
868 |
|
869 |
final void leafBinaryIndexMap(int l, int h, IntAndDoubleToDouble op) { |
870 |
final double[] a = this.array; |
871 |
for (int i = l; i < h; ++i) |
872 |
a[i] = op.op(i, a[i]); |
873 |
} |
874 |
|
875 |
final void leafGenerate(int l, int h, DoubleGenerator generator) { |
876 |
final double[] a = this.array; |
877 |
for (int i = l; i < h; ++i) |
878 |
a[i] = generator.op(); |
879 |
} |
880 |
|
881 |
final void leafFill(int l, int h, double value) { |
882 |
final double[] a = this.array; |
883 |
for (int i = l; i < h; ++i) |
884 |
a[i] = value; |
885 |
} |
886 |
|
887 |
final void leafCombineInPlace |
888 |
(int l, int h, double[] other, |
889 |
int otherOffset, BinaryDoubleOp combiner) { |
890 |
final double[] a = this.array; |
891 |
int k = l + otherOffset; |
892 |
for (int i = l; i < h; ++i) |
893 |
a[i] = combiner.op(a[i], other[k++]); |
894 |
} |
895 |
|
896 |
final void leafCombineInPlace |
897 |
(int l, int h, |
898 |
ParallelDoubleArrayWithDoubleMapping other, |
899 |
int otherOffset, BinaryDoubleOp combiner) { |
900 |
final double[] a = this.array; |
901 |
int k = l + otherOffset; |
902 |
if (other.hasFilter()) { |
903 |
for (int i = l; i < h; ++i) { |
904 |
if (other.isSelected(k)) |
905 |
a[i] = combiner.op(a[i], other.dget(k)); |
906 |
k++; |
907 |
} |
908 |
} |
909 |
else if (other.hasMap()) { |
910 |
for (int i = l; i < h; ++i) |
911 |
a[i] = combiner.op(a[i], other.dget(k++)); |
912 |
} |
913 |
else { |
914 |
double[] b = other.array; |
915 |
for (int i = l; i < h; ++i) |
916 |
a[i] = combiner.op(a[i], b[k++]); |
917 |
} |
918 |
|
919 |
} |
920 |
} |
921 |
|
922 |
static class LUPap extends ParallelLongArrayWithBounds { |
923 |
LUPap(ForkJoinExecutor ex, int origin, int fence, |
924 |
long[] array) { |
925 |
super(ex, origin, fence, array); |
926 |
} |
927 |
|
928 |
public ParallelLongArrayWithBounds withBounds(int lo, int hi) { |
929 |
boundsCheck(lo, hi); |
930 |
return new LUPap(ex, origin + lo, origin + hi, array); |
931 |
} |
932 |
|
933 |
public ParallelLongArrayWithFilter withFilter(LongPredicate selector) { |
934 |
return new LFPap(ex, origin, fence, array, selector); |
935 |
} |
936 |
|
937 |
public ParallelLongArrayWithFilter withIndexedFilter |
938 |
(IntAndLongPredicate selector) { |
939 |
return new LRPap(ex, origin, fence, array, selector); |
940 |
} |
941 |
|
942 |
public <U> ParallelLongArrayWithMapping<U> withMapping |
943 |
(LongToObject<? extends U> op) { |
944 |
return new LUOMPap<U>(ex, origin, fence, array, op); |
945 |
} |
946 |
|
947 |
public ParallelLongArrayWithLongMapping withMapping(LongOp op) { |
948 |
return new LULMPap(ex, origin, fence, array, op); |
949 |
} |
950 |
|
951 |
public ParallelLongArrayWithDoubleMapping withMapping(LongToDouble op) { |
952 |
return new LUDMPap(ex, origin, fence, array, op); |
953 |
} |
954 |
|
955 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
956 |
(IntAndLongToObject<? extends V> mapper) { |
957 |
return new LUOCPap<V>(ex, origin, fence, array, mapper); |
958 |
} |
959 |
|
960 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
961 |
(IntAndLongToDouble mapper) { |
962 |
return new LUDCPap(ex, origin, fence, array, mapper); |
963 |
} |
964 |
|
965 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
966 |
(IntAndLongToLong mapper) { |
967 |
return new LULCPap(ex, origin, fence, array, mapper); |
968 |
} |
969 |
|
970 |
public int indexOf(long target) { |
971 |
AtomicInteger result = new AtomicInteger(-1); |
972 |
PAS.FJLIndexOf f = new PAS.FJLIndexOf |
973 |
(this, origin, fence, null, result, target); |
974 |
ex.invoke(f); |
975 |
return result.get(); |
976 |
} |
977 |
|
978 |
public int binarySearch(long target) { |
979 |
final long[] a = this.array; |
980 |
int lo = origin; |
981 |
int hi = fence - 1; |
982 |
while (lo <= hi) { |
983 |
int mid = (lo + hi) >>> 1; |
984 |
long m = a[mid]; |
985 |
if (target == m) |
986 |
return mid; |
987 |
else if (target < m) |
988 |
hi = mid - 1; |
989 |
else |
990 |
lo = mid + 1; |
991 |
} |
992 |
return -1; |
993 |
} |
994 |
|
995 |
public int binarySearch(long target, LongComparator comparator) { |
996 |
final long[] a = this.array; |
997 |
int lo = origin; |
998 |
int hi = fence - 1; |
999 |
while (lo <= hi) { |
1000 |
int mid = (lo + hi) >>> 1; |
1001 |
int c = comparator.compare(target, a[mid]); |
1002 |
if (c == 0) |
1003 |
return mid; |
1004 |
else if (c < 0) |
1005 |
hi = mid - 1; |
1006 |
else |
1007 |
lo = mid + 1; |
1008 |
} |
1009 |
return -1; |
1010 |
} |
1011 |
|
1012 |
public ParallelLongArrayWithBounds cumulate(LongReducer reducer, long base) { |
1013 |
PAS.FJLCumulateOp op = new PAS.FJLCumulateOp(this, reducer, base); |
1014 |
PAS.FJLScan r = new PAS.FJLScan(null, op, origin, fence); |
1015 |
ex.invoke(r); |
1016 |
return this; |
1017 |
} |
1018 |
|
1019 |
public ParallelLongArrayWithBounds cumulateSum() { |
1020 |
PAS.FJLCumulatePlusOp op = new PAS.FJLCumulatePlusOp(this); |
1021 |
PAS.FJLScan r = new PAS.FJLScan(null, op, origin, fence); |
1022 |
ex.invoke(r); |
1023 |
return this; |
1024 |
} |
1025 |
|
1026 |
public long precumulate(LongReducer reducer, long base) { |
1027 |
PAS.FJLPrecumulateOp op = new PAS.FJLPrecumulateOp |
1028 |
(this, reducer, base); |
1029 |
PAS.FJLScan r = new PAS.FJLScan(null, op, origin, fence); |
1030 |
ex.invoke(r); |
1031 |
return r.out; |
1032 |
} |
1033 |
|
1034 |
public long precumulateSum() { |
1035 |
PAS.FJLPrecumulatePlusOp op = new PAS.FJLPrecumulatePlusOp(this); |
1036 |
PAS.FJLScan r = new PAS.FJLScan(null, op, origin, fence); |
1037 |
ex.invoke(r); |
1038 |
return r.out; |
1039 |
} |
1040 |
|
1041 |
public ParallelLongArrayWithBounds sort(LongComparator cmp) { |
1042 |
ex.invoke(new PAS.FJLSorter |
1043 |
(cmp, this.array, new long[fence], |
1044 |
origin, fence - origin, getThreshold())); |
1045 |
return this; |
1046 |
} |
1047 |
|
1048 |
public ParallelLongArrayWithBounds sort() { |
1049 |
ex.invoke(new PAS.FJLCSorter |
1050 |
(this.array, new long[fence], |
1051 |
origin, fence - origin, getThreshold())); |
1052 |
return this; |
1053 |
} |
1054 |
|
1055 |
final void leafApply(int lo, int hi, LongProcedure procedure) { |
1056 |
final long[] a = this.array; |
1057 |
for (int i = lo; i < hi; ++i) |
1058 |
procedure.op(a[i]); |
1059 |
} |
1060 |
|
1061 |
final long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
1062 |
if (lo >= hi) |
1063 |
return base; |
1064 |
final long[] a = this.array; |
1065 |
long r = a[lo]; |
1066 |
for (int i = lo+1; i < hi; ++i) |
1067 |
r = reducer.op(r, a[i]); |
1068 |
return r; |
1069 |
} |
1070 |
|
1071 |
final void leafTransform(int l, int h, LongOp op) { |
1072 |
final long[] a = this.array; |
1073 |
for (int i = l; i < h; ++i) |
1074 |
a[i] = op.op(a[i]); |
1075 |
} |
1076 |
|
1077 |
final void leafIndexMap(int l, int h, IntToLong op) { |
1078 |
final long[] a = this.array; |
1079 |
for (int i = l; i < h; ++i) |
1080 |
a[i] = op.op(i); |
1081 |
} |
1082 |
|
1083 |
final void leafBinaryIndexMap(int l, int h, IntAndLongToLong op) { |
1084 |
final long[] a = this.array; |
1085 |
for (int i = l; i < h; ++i) |
1086 |
a[i] = op.op(i, a[i]); |
1087 |
} |
1088 |
|
1089 |
final void leafGenerate(int l, int h, LongGenerator generator) { |
1090 |
final long[] a = this.array; |
1091 |
for (int i = l; i < h; ++i) |
1092 |
a[i] = generator.op(); |
1093 |
} |
1094 |
|
1095 |
final void leafFill(int l, int h, long value) { |
1096 |
final long[] a = this.array; |
1097 |
for (int i = l; i < h; ++i) |
1098 |
a[i] = value; |
1099 |
} |
1100 |
|
1101 |
final void leafCombineInPlace |
1102 |
(int l, int h, long[] other, |
1103 |
int otherOffset, BinaryLongOp combiner) { |
1104 |
final long[] a = this.array; |
1105 |
int k = l + otherOffset; |
1106 |
for (int i = l; i < h; ++i) |
1107 |
a[i] = combiner.op(a[i], other[k++]); |
1108 |
} |
1109 |
|
1110 |
final void leafCombineInPlace |
1111 |
(int l, int h, |
1112 |
ParallelLongArrayWithLongMapping other, |
1113 |
int otherOffset, BinaryLongOp combiner) { |
1114 |
final long[] a = this.array; |
1115 |
int k = l + otherOffset; |
1116 |
if (other.hasFilter()) { |
1117 |
for (int i = l; i < h; ++i) { |
1118 |
if (other.isSelected(k)) |
1119 |
a[i] = combiner.op(a[i], other.lget(k)); |
1120 |
k++; |
1121 |
} |
1122 |
} |
1123 |
else if (other.hasMap()) { |
1124 |
for (int i = l; i < h; ++i) |
1125 |
a[i] = combiner.op(a[i], other.lget(k++)); |
1126 |
} |
1127 |
else { |
1128 |
long[] b = other.array; |
1129 |
for (int i = l; i < h; ++i) |
1130 |
a[i] = combiner.op(a[i], b[k++]); |
1131 |
} |
1132 |
} |
1133 |
} |
1134 |
|
1135 |
// Filtered (but unmapped) classes |
1136 |
static final class OFPap<T> extends ParallelArrayWithFilter<T> { |
1137 |
final Predicate<? super T> selector; |
1138 |
OFPap(ForkJoinExecutor ex, int origin, int fence, |
1139 |
T[] array, |
1140 |
Predicate<? super T> selector) { |
1141 |
super(ex, origin, fence, array); |
1142 |
this.selector = selector; |
1143 |
} |
1144 |
|
1145 |
boolean hasFilter() { return true; } |
1146 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
1147 |
|
1148 |
public ParallelArrayWithFilter<T> withFilter |
1149 |
(Predicate<? super T> selector) { |
1150 |
return new OFPap<T>(ex, origin, fence, array, |
1151 |
CommonOps.andPredicate(this.selector, selector)); |
1152 |
} |
1153 |
|
1154 |
public ParallelArrayWithFilter<T> withIndexedFilter |
1155 |
(IntAndObjectPredicate<? super T> selector) { |
1156 |
return new ORPap<T> |
1157 |
(ex, origin, fence, array, |
1158 |
compoundIndexedSelector(this.selector, selector)); |
1159 |
} |
1160 |
|
1161 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
1162 |
(Op<? super T, ? extends U> op) { |
1163 |
return new OFOMPap<T,U>(ex, origin, fence, array, selector, op); |
1164 |
} |
1165 |
|
1166 |
public ParallelArrayWithDoubleMapping<T> withMapping |
1167 |
(ObjectToDouble<? super T> op) { |
1168 |
return new OFDMPap<T>(ex, origin, fence, array, selector, op); |
1169 |
} |
1170 |
|
1171 |
public ParallelArrayWithLongMapping<T> withMapping |
1172 |
(ObjectToLong<? super T> op) { |
1173 |
return new OFLMPap<T>(ex, origin, fence, array, selector, op); |
1174 |
} |
1175 |
|
1176 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
1177 |
(IntAndObjectToObject<? super T, ? extends V> mapper) { |
1178 |
return new OFOCPap<T,V>(ex, origin, fence, array, selector, mapper); |
1179 |
} |
1180 |
|
1181 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
1182 |
(IntAndObjectToDouble<? super T> mapper) { |
1183 |
return new OFDCPap<T>(ex, origin, fence, array, selector, mapper); |
1184 |
} |
1185 |
|
1186 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
1187 |
(IntAndObjectToLong<? super T> mapper) { |
1188 |
return new OFLCPap<T>(ex, origin, fence, array, selector, mapper); |
1189 |
} |
1190 |
|
1191 |
void leafApply(int lo, int hi, Procedure procedure) { |
1192 |
final Predicate s = selector; |
1193 |
final Object[] a = this.array; |
1194 |
for (int i = lo; i < hi; ++i) { |
1195 |
Object x = a[i]; |
1196 |
if (s.op(x)) |
1197 |
procedure.op(x); |
1198 |
} |
1199 |
} |
1200 |
|
1201 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
1202 |
final Predicate s = selector; |
1203 |
boolean gotFirst = false; |
1204 |
Object r = base; |
1205 |
final Object[] a = this.array; |
1206 |
for (int i = lo; i < hi; ++i) { |
1207 |
Object x = a[i]; |
1208 |
if (s.op(x)) { |
1209 |
if (!gotFirst) { |
1210 |
gotFirst = true; |
1211 |
r = x; |
1212 |
} |
1213 |
else |
1214 |
r = reducer.op(r, x); |
1215 |
} |
1216 |
} |
1217 |
return r; |
1218 |
} |
1219 |
|
1220 |
final void leafTransform(int l, int h, Op op) { |
1221 |
final Object[] a = this.array; |
1222 |
final Predicate s = selector; |
1223 |
for (int i = l; i < h; ++i) { |
1224 |
Object x = a[i]; |
1225 |
if (s.op(x)) |
1226 |
a[i] = op.op(x); |
1227 |
} |
1228 |
} |
1229 |
|
1230 |
final void leafIndexMap(int l, int h, IntToObject op) { |
1231 |
final Object[] a = this.array; |
1232 |
final Predicate s = selector; |
1233 |
for (int i = l; i < h; ++i) { |
1234 |
Object x = a[i]; |
1235 |
if (s.op(x)) |
1236 |
a[i] = op.op(i); |
1237 |
} |
1238 |
} |
1239 |
|
1240 |
final void leafBinaryIndexMap(int l, int h, IntAndObjectToObject op) { |
1241 |
final Object[] a = this.array; |
1242 |
final Predicate s = selector; |
1243 |
for (int i = l; i < h; ++i) { |
1244 |
Object x = a[i]; |
1245 |
if (s.op(x)) |
1246 |
a[i] = op.op(i, x); |
1247 |
} |
1248 |
} |
1249 |
|
1250 |
final void leafGenerate(int l, int h, Generator generator) { |
1251 |
final Object[] a = this.array; |
1252 |
final Predicate s = selector; |
1253 |
for (int i = l; i < h; ++i) { |
1254 |
if (s.op(a[i])) |
1255 |
a[i] = generator.op(); |
1256 |
} |
1257 |
} |
1258 |
|
1259 |
final void leafFill(int l, int h, Object value) { |
1260 |
final Object[] a = this.array; |
1261 |
final Predicate s = selector; |
1262 |
for (int i = l; i < h; ++i) { |
1263 |
if (s.op(a[i])) |
1264 |
a[i] = value; |
1265 |
} |
1266 |
} |
1267 |
|
1268 |
final void leafCombineInPlace |
1269 |
(int l, int h, Object[] other, |
1270 |
int otherOffset, BinaryOp combiner) { |
1271 |
final Object[] a = this.array; |
1272 |
final Predicate s = selector; |
1273 |
int k = l + otherOffset; |
1274 |
for (int i = l; i < h; ++i) { |
1275 |
Object x = a[i]; |
1276 |
if (s.op(x)) |
1277 |
a[i] = combiner.op(x, other[k]); |
1278 |
k++; |
1279 |
} |
1280 |
} |
1281 |
|
1282 |
final void leafCombineInPlace |
1283 |
(int l, int h, |
1284 |
ParallelArrayWithMapping other, |
1285 |
int otherOffset, BinaryOp combiner) { |
1286 |
final Object[] a = this.array; |
1287 |
final Predicate s = selector; |
1288 |
int k = l + otherOffset; |
1289 |
if (other.hasFilter()) { |
1290 |
for (int i = l; i < h; ++i) { |
1291 |
Object x = a[i]; |
1292 |
if (s.op(x) && other.isSelected(k)) |
1293 |
a[i] = combiner.op(x, other.oget(k)); |
1294 |
k++; |
1295 |
} |
1296 |
} |
1297 |
else if (other.hasMap()) { |
1298 |
for (int i = l; i < h; ++i) { |
1299 |
Object x = a[i]; |
1300 |
if (s.op(x)) |
1301 |
a[i] = combiner.op(x, other.oget(k)); |
1302 |
k++; |
1303 |
} |
1304 |
} |
1305 |
else { |
1306 |
Object[] b = other.array; |
1307 |
for (int i = l; i < h; ++i) { |
1308 |
Object x = a[i]; |
1309 |
if (s.op(x)) |
1310 |
a[i] = combiner.op(x, b[k]); |
1311 |
k++; |
1312 |
} |
1313 |
} |
1314 |
} |
1315 |
} |
1316 |
|
1317 |
static final class DFPap extends ParallelDoubleArrayWithFilter { |
1318 |
final DoublePredicate selector; |
1319 |
DFPap(ForkJoinExecutor ex, int origin, int fence, |
1320 |
double[] array, |
1321 |
DoublePredicate selector) { |
1322 |
super(ex, origin, fence, array); |
1323 |
this.selector = selector; |
1324 |
} |
1325 |
|
1326 |
boolean hasFilter() { return true; } |
1327 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
1328 |
|
1329 |
public ParallelDoubleArrayWithFilter withFilter(DoublePredicate selector) { |
1330 |
return new DFPap(ex, origin, fence, array, |
1331 |
CommonOps.andPredicate(this.selector, selector)); |
1332 |
} |
1333 |
|
1334 |
public ParallelDoubleArrayWithFilter withIndexedFilter |
1335 |
(IntAndDoublePredicate selector) { |
1336 |
return new DRPap |
1337 |
(ex, origin, fence, array, |
1338 |
compoundIndexedSelector(this.selector, selector)); |
1339 |
} |
1340 |
|
1341 |
public <U> ParallelDoubleArrayWithMapping<U> withMapping |
1342 |
(DoubleToObject<? extends U> op) { |
1343 |
return new DFOMPap<U>(ex, origin, fence, array, selector, op); |
1344 |
} |
1345 |
|
1346 |
public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { |
1347 |
return new DFDMPap(ex, origin, fence, array, selector, op); |
1348 |
} |
1349 |
|
1350 |
public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { |
1351 |
return new DFLMPap(ex, origin, fence, array, selector, op); |
1352 |
} |
1353 |
|
1354 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
1355 |
(IntAndDoubleToObject<? extends V> mapper) { |
1356 |
return new DFOCPap<V>(ex, origin, fence, array, selector, mapper); |
1357 |
} |
1358 |
|
1359 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
1360 |
(IntAndDoubleToDouble mapper) { |
1361 |
return new DFDCPap(ex, origin, fence, array, selector, mapper); |
1362 |
} |
1363 |
|
1364 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
1365 |
(IntAndDoubleToLong mapper) { |
1366 |
return new DFLCPap(ex, origin, fence, array, selector, mapper); |
1367 |
} |
1368 |
|
1369 |
final void leafApply(int lo, int hi, DoubleProcedure procedure) { |
1370 |
final DoublePredicate s = selector; |
1371 |
final double[] a = this.array; |
1372 |
for (int i = lo; i < hi; ++i) { |
1373 |
double x = a[i]; |
1374 |
if (s.op(x)) |
1375 |
procedure.op(x); |
1376 |
} |
1377 |
} |
1378 |
|
1379 |
final double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
1380 |
final DoublePredicate s = selector; |
1381 |
boolean gotFirst = false; |
1382 |
double r = base; |
1383 |
final double[] a = this.array; |
1384 |
for (int i = lo; i < hi; ++i) { |
1385 |
double x = a[i]; |
1386 |
if (s.op(x)) { |
1387 |
if (!gotFirst) { |
1388 |
gotFirst = true; |
1389 |
r = x; |
1390 |
} |
1391 |
else |
1392 |
r = reducer.op(r, x); |
1393 |
} |
1394 |
} |
1395 |
return r; |
1396 |
} |
1397 |
|
1398 |
final void leafTransform(int l, int h, DoubleOp op) { |
1399 |
final double[] a = this.array; |
1400 |
final DoublePredicate s = selector; |
1401 |
for (int i = l; i < h; ++i) { |
1402 |
double x = a[i]; |
1403 |
if (s.op(x)) |
1404 |
a[i] = op.op(x); |
1405 |
} |
1406 |
} |
1407 |
|
1408 |
final void leafIndexMap(int l, int h, IntToDouble op) { |
1409 |
final double[] a = this.array; |
1410 |
final DoublePredicate s = selector; |
1411 |
for (int i = l; i < h; ++i) { |
1412 |
double x = a[i]; |
1413 |
if (s.op(x)) |
1414 |
a[i] = op.op(i); |
1415 |
} |
1416 |
} |
1417 |
|
1418 |
final void leafBinaryIndexMap(int l, int h, IntAndDoubleToDouble op) { |
1419 |
final double[] a = this.array; |
1420 |
final DoublePredicate s = selector; |
1421 |
for (int i = l; i < h; ++i) { |
1422 |
double x = a[i]; |
1423 |
if (s.op(x)) |
1424 |
a[i] = op.op(i, x); |
1425 |
} |
1426 |
} |
1427 |
|
1428 |
final void leafGenerate(int l, int h, DoubleGenerator generator) { |
1429 |
final double[] a = this.array; |
1430 |
final DoublePredicate s = selector; |
1431 |
for (int i = l; i < h; ++i) { |
1432 |
if (s.op(a[i])) |
1433 |
a[i] = generator.op(); |
1434 |
} |
1435 |
} |
1436 |
|
1437 |
final void leafFill(int l, int h, double value) { |
1438 |
final double[] a = this.array; |
1439 |
final DoublePredicate s = selector; |
1440 |
for (int i = l; i < h; ++i) { |
1441 |
if (s.op(a[i])) |
1442 |
a[i] = value; |
1443 |
} |
1444 |
} |
1445 |
|
1446 |
final void leafCombineInPlace |
1447 |
(int l, int h, double[] other, |
1448 |
int otherOffset, BinaryDoubleOp combiner) { |
1449 |
final double[] a = this.array; |
1450 |
final DoublePredicate s = selector; |
1451 |
int k = l + otherOffset; |
1452 |
for (int i = l; i < h; ++i) { |
1453 |
double x = a[i]; |
1454 |
if (s.op(x)) |
1455 |
a[i] = combiner.op(x, other[k]); |
1456 |
k++; |
1457 |
} |
1458 |
} |
1459 |
|
1460 |
final void leafCombineInPlace |
1461 |
(int l, int h, |
1462 |
ParallelDoubleArrayWithDoubleMapping other, |
1463 |
int otherOffset, BinaryDoubleOp combiner) { |
1464 |
final double[] a = this.array; |
1465 |
final DoublePredicate s = selector; |
1466 |
int k = l + otherOffset; |
1467 |
if (other.hasFilter()) { |
1468 |
for (int i = l; i < h; ++i) { |
1469 |
double x = a[i]; |
1470 |
if (s.op(x) && other.isSelected(k)) |
1471 |
a[i] = combiner.op(x, other.dget(k)); |
1472 |
k++; |
1473 |
} |
1474 |
} |
1475 |
else if (other.hasMap()) { |
1476 |
for (int i = l; i < h; ++i) { |
1477 |
double x = a[i]; |
1478 |
if (s.op(x)) |
1479 |
a[i] = combiner.op(x, other.dget(k)); |
1480 |
k++; |
1481 |
} |
1482 |
} |
1483 |
else { |
1484 |
double[] b = other.array; |
1485 |
for (int i = l; i < h; ++i) { |
1486 |
double x = a[i]; |
1487 |
if (s.op(x)) |
1488 |
a[i] = combiner.op(x, b[k]); |
1489 |
k++; |
1490 |
} |
1491 |
} |
1492 |
} |
1493 |
} |
1494 |
|
1495 |
static final class LFPap extends ParallelLongArrayWithFilter { |
1496 |
final LongPredicate selector; |
1497 |
LFPap(ForkJoinExecutor ex, int origin, int fence, |
1498 |
long[] array, |
1499 |
LongPredicate selector) { |
1500 |
super(ex, origin, fence, array); |
1501 |
this.selector = selector; |
1502 |
} |
1503 |
|
1504 |
boolean hasFilter() { return true; } |
1505 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
1506 |
|
1507 |
public ParallelLongArrayWithFilter withFilter(LongPredicate selector) { |
1508 |
return new LFPap(ex, origin, fence, array, |
1509 |
CommonOps.andPredicate(this.selector, selector)); |
1510 |
} |
1511 |
|
1512 |
public ParallelLongArrayWithFilter withIndexedFilter |
1513 |
(IntAndLongPredicate selector) { |
1514 |
return new LRPap |
1515 |
(ex, origin, fence, array, |
1516 |
compoundIndexedSelector(this.selector, selector)); |
1517 |
} |
1518 |
|
1519 |
public <U> ParallelLongArrayWithMapping<U> withMapping |
1520 |
(LongToObject<? extends U> op) { |
1521 |
return new LFOMPap<U>(ex, origin, fence, array, selector, op); |
1522 |
} |
1523 |
|
1524 |
public ParallelLongArrayWithLongMapping withMapping |
1525 |
(LongOp op) { |
1526 |
return new LFLMPap(ex, origin, fence, array, selector, op); |
1527 |
} |
1528 |
|
1529 |
public ParallelLongArrayWithDoubleMapping withMapping |
1530 |
(LongToDouble op) { |
1531 |
return new LFDMPap(ex, origin, fence, array, selector, op); |
1532 |
} |
1533 |
|
1534 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
1535 |
(IntAndLongToObject<? extends V> mapper) { |
1536 |
return new LFOCPap<V>(ex, origin, fence, array, selector, mapper); |
1537 |
} |
1538 |
|
1539 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
1540 |
(IntAndLongToDouble mapper) { |
1541 |
return new LFDCPap(ex, origin, fence, array, selector, mapper); |
1542 |
} |
1543 |
|
1544 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
1545 |
(IntAndLongToLong mapper) { |
1546 |
return new LFLCPap(ex, origin, fence, array, selector, mapper); |
1547 |
} |
1548 |
|
1549 |
final void leafApply(int lo, int hi, LongProcedure procedure) { |
1550 |
final LongPredicate s = selector; |
1551 |
final long[] a = this.array; |
1552 |
for (int i = lo; i < hi; ++i) { |
1553 |
long x = a[i]; |
1554 |
if (s.op(x)) |
1555 |
procedure.op(x); |
1556 |
} |
1557 |
} |
1558 |
|
1559 |
final long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
1560 |
final LongPredicate s = selector; |
1561 |
boolean gotFirst = false; |
1562 |
long r = base; |
1563 |
final long[] a = this.array; |
1564 |
for (int i = lo; i < hi; ++i) { |
1565 |
long x = a[i]; |
1566 |
if (s.op(x)) { |
1567 |
if (!gotFirst) { |
1568 |
gotFirst = true; |
1569 |
r = x; |
1570 |
} |
1571 |
else |
1572 |
r = reducer.op(r, x); |
1573 |
} |
1574 |
} |
1575 |
return r; |
1576 |
} |
1577 |
|
1578 |
final void leafTransform(int l, int h, LongOp op) { |
1579 |
final long[] a = this.array; |
1580 |
final LongPredicate s = selector; |
1581 |
for (int i = l; i < h; ++i) { |
1582 |
long x = a[i]; |
1583 |
if (s.op(x)) |
1584 |
a[i] = op.op(x); |
1585 |
} |
1586 |
} |
1587 |
|
1588 |
final void leafIndexMap(int l, int h, IntToLong op) { |
1589 |
final long[] a = this.array; |
1590 |
final LongPredicate s = selector; |
1591 |
for (int i = l; i < h; ++i) { |
1592 |
long x = a[i]; |
1593 |
if (s.op(x)) |
1594 |
a[i] = op.op(i); |
1595 |
} |
1596 |
} |
1597 |
|
1598 |
final void leafBinaryIndexMap(int l, int h, IntAndLongToLong op) { |
1599 |
final long[] a = this.array; |
1600 |
final LongPredicate s = selector; |
1601 |
for (int i = l; i < h; ++i) { |
1602 |
long x = a[i]; |
1603 |
if (s.op(x)) |
1604 |
a[i] = op.op(i, x); |
1605 |
} |
1606 |
} |
1607 |
|
1608 |
final void leafGenerate(int l, int h, LongGenerator generator) { |
1609 |
final long[] a = this.array; |
1610 |
final LongPredicate s = selector; |
1611 |
for (int i = l; i < h; ++i) { |
1612 |
if (s.op(a[i])) |
1613 |
a[i] = generator.op(); |
1614 |
} |
1615 |
} |
1616 |
|
1617 |
final void leafFill(int l, int h, long value) { |
1618 |
final long[] a = this.array; |
1619 |
final LongPredicate s = selector; |
1620 |
for (int i = l; i < h; ++i) { |
1621 |
if (s.op(a[i])) |
1622 |
a[i] = value; |
1623 |
} |
1624 |
} |
1625 |
|
1626 |
final void leafCombineInPlace |
1627 |
(int l, int h, long[] other, |
1628 |
int otherOffset, BinaryLongOp combiner) { |
1629 |
final long[] a = this.array; |
1630 |
final LongPredicate s = selector; |
1631 |
int k = l + otherOffset; |
1632 |
for (int i = l; i < h; ++i) { |
1633 |
long x = a[i]; |
1634 |
if (s.op(x)) |
1635 |
a[i] = combiner.op(x, other[k]); |
1636 |
k++; |
1637 |
} |
1638 |
} |
1639 |
|
1640 |
final void leafCombineInPlace |
1641 |
(int l, int h, |
1642 |
ParallelLongArrayWithLongMapping other, |
1643 |
int otherOffset, BinaryLongOp combiner) { |
1644 |
final long[] a = this.array; |
1645 |
final LongPredicate s = selector; |
1646 |
int k = l + otherOffset; |
1647 |
if (other.hasFilter()) { |
1648 |
for (int i = l; i < h; ++i) { |
1649 |
long x = a[i]; |
1650 |
if (s.op(x) && other.isSelected(k)) |
1651 |
a[i] = combiner.op(x, other.lget(k)); |
1652 |
k++; |
1653 |
} |
1654 |
} |
1655 |
else if (other.hasMap()) { |
1656 |
for (int i = l; i < h; ++i) { |
1657 |
long x = a[i]; |
1658 |
if (s.op(x)) |
1659 |
a[i] = combiner.op(x, other.lget(k)); |
1660 |
k++; |
1661 |
} |
1662 |
} |
1663 |
else { |
1664 |
long[] b = other.array; |
1665 |
for (int i = l; i < h; ++i) { |
1666 |
long x = a[i]; |
1667 |
if (s.op(x)) |
1668 |
a[i] = combiner.op(x, b[k]); |
1669 |
k++; |
1670 |
} |
1671 |
} |
1672 |
} |
1673 |
} |
1674 |
|
1675 |
// Relationally Filtered (but unmapped) classes |
1676 |
static final class ORPap<T> extends ParallelArrayWithFilter<T> { |
1677 |
final IntAndObjectPredicate<? super T> selector; |
1678 |
ORPap(ForkJoinExecutor ex, int origin, int fence, |
1679 |
T[] array, |
1680 |
IntAndObjectPredicate<? super T> selector) { |
1681 |
super(ex, origin, fence, array); |
1682 |
this.selector = selector; |
1683 |
} |
1684 |
|
1685 |
boolean hasFilter() { return true; } |
1686 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
1687 |
|
1688 |
public ParallelArrayWithFilter<T> withFilter |
1689 |
(Predicate<? super T> selector) { |
1690 |
return new ORPap<T> |
1691 |
(ex, origin, fence, array, |
1692 |
compoundIndexedSelector(this.selector, selector)); |
1693 |
} |
1694 |
|
1695 |
public ParallelArrayWithFilter<T> withIndexedFilter |
1696 |
(IntAndObjectPredicate<? super T> selector) { |
1697 |
return new ORPap<T> |
1698 |
(ex, origin, fence, array, |
1699 |
compoundIndexedSelector(this.selector, selector)); |
1700 |
} |
1701 |
|
1702 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
1703 |
(Op<? super T, ? extends U> op) { |
1704 |
return new OROMPap<T,U>(ex, origin, fence, array, selector, op); |
1705 |
} |
1706 |
|
1707 |
public ParallelArrayWithDoubleMapping<T> withMapping |
1708 |
(ObjectToDouble<? super T> op) { |
1709 |
return new ORDMPap<T>(ex, origin, fence, array, selector, op); |
1710 |
} |
1711 |
|
1712 |
public ParallelArrayWithLongMapping<T> withMapping |
1713 |
(ObjectToLong<? super T> op) { |
1714 |
return new ORLMPap<T>(ex, origin, fence, array, selector, op); |
1715 |
} |
1716 |
|
1717 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
1718 |
(IntAndObjectToObject<? super T, ? extends V> mapper) { |
1719 |
return new OROCPap<T,V>(ex, origin, fence, array, selector, mapper); |
1720 |
} |
1721 |
|
1722 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
1723 |
(IntAndObjectToDouble<? super T> mapper) { |
1724 |
return new ORDCPap<T>(ex, origin, fence, array, selector, mapper); |
1725 |
} |
1726 |
|
1727 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
1728 |
(IntAndObjectToLong<? super T> mapper) { |
1729 |
return new ORLCPap<T>(ex, origin, fence, array, selector, mapper); |
1730 |
} |
1731 |
|
1732 |
void leafApply(int lo, int hi, Procedure procedure) { |
1733 |
final IntAndObjectPredicate s = selector; |
1734 |
final Object[] a = this.array; |
1735 |
for (int i = lo; i < hi; ++i) { |
1736 |
Object x = a[i]; |
1737 |
if (s.op(i, x)) |
1738 |
procedure.op(x); |
1739 |
} |
1740 |
} |
1741 |
|
1742 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
1743 |
final IntAndObjectPredicate s = selector; |
1744 |
boolean gotFirst = false; |
1745 |
Object r = base; |
1746 |
final Object[] a = this.array; |
1747 |
for (int i = lo; i < hi; ++i) { |
1748 |
Object x = a[i]; |
1749 |
if (s.op(i, x)) { |
1750 |
if (!gotFirst) { |
1751 |
gotFirst = true; |
1752 |
r = x; |
1753 |
} |
1754 |
else |
1755 |
r = reducer.op(r, x); |
1756 |
} |
1757 |
} |
1758 |
return r; |
1759 |
} |
1760 |
|
1761 |
final void leafTransform(int l, int h, Op op) { |
1762 |
final Object[] a = this.array; |
1763 |
final IntAndObjectPredicate s = selector; |
1764 |
for (int i = l; i < h; ++i) { |
1765 |
Object x = a[i]; |
1766 |
if (s.op(i, x)) |
1767 |
a[i] = op.op(x); |
1768 |
} |
1769 |
} |
1770 |
|
1771 |
final void leafIndexMap(int l, int h, IntToObject op) { |
1772 |
final Object[] a = this.array; |
1773 |
final IntAndObjectPredicate s = selector; |
1774 |
for (int i = l; i < h; ++i) { |
1775 |
Object x = a[i]; |
1776 |
if (s.op(i, x)) |
1777 |
a[i] = op.op(i); |
1778 |
} |
1779 |
} |
1780 |
|
1781 |
final void leafBinaryIndexMap(int l, int h, IntAndObjectToObject op) { |
1782 |
final Object[] a = this.array; |
1783 |
final IntAndObjectPredicate s = selector; |
1784 |
for (int i = l; i < h; ++i) { |
1785 |
Object x = a[i]; |
1786 |
if (s.op(i, x)) |
1787 |
a[i] = op.op(i, x); |
1788 |
} |
1789 |
} |
1790 |
|
1791 |
final void leafGenerate(int l, int h, Generator generator) { |
1792 |
final Object[] a = this.array; |
1793 |
final IntAndObjectPredicate s = selector; |
1794 |
for (int i = l; i < h; ++i) { |
1795 |
if (s.op(i, a[i])) |
1796 |
a[i] = generator.op(); |
1797 |
} |
1798 |
} |
1799 |
|
1800 |
final void leafFill(int l, int h, Object value) { |
1801 |
final Object[] a = this.array; |
1802 |
final IntAndObjectPredicate s = selector; |
1803 |
for (int i = l; i < h; ++i) { |
1804 |
if (s.op(i, a[i])) |
1805 |
a[i] = value; |
1806 |
} |
1807 |
} |
1808 |
|
1809 |
final void leafCombineInPlace |
1810 |
(int l, int h, Object[] other, |
1811 |
int otherOffset, BinaryOp combiner) { |
1812 |
final Object[] a = this.array; |
1813 |
final IntAndObjectPredicate s = selector; |
1814 |
int k = l + otherOffset; |
1815 |
for (int i = l; i < h; ++i) { |
1816 |
Object x = a[i]; |
1817 |
if (s.op(i, x)) |
1818 |
a[i] = combiner.op(x, other[k]); |
1819 |
k++; |
1820 |
} |
1821 |
} |
1822 |
|
1823 |
final void leafCombineInPlace |
1824 |
(int l, int h, |
1825 |
ParallelArrayWithMapping other, |
1826 |
int otherOffset, BinaryOp combiner) { |
1827 |
final Object[] a = this.array; |
1828 |
final IntAndObjectPredicate s = selector; |
1829 |
int k = l + otherOffset; |
1830 |
if (other.hasFilter()) { |
1831 |
for (int i = l; i < h; ++i) { |
1832 |
Object x = a[i]; |
1833 |
if (s.op(i, x) && other.isSelected(k)) |
1834 |
a[i] = combiner.op(x, other.oget(k)); |
1835 |
k++; |
1836 |
} |
1837 |
} |
1838 |
else if (other.hasMap()) { |
1839 |
for (int i = l; i < h; ++i) { |
1840 |
Object x = a[i]; |
1841 |
if (s.op(i, x)) |
1842 |
a[i] = combiner.op(x, other.oget(k)); |
1843 |
k++; |
1844 |
} |
1845 |
} |
1846 |
else { |
1847 |
Object[] b = other.array; |
1848 |
for (int i = l; i < h; ++i) { |
1849 |
Object x = a[i]; |
1850 |
if (s.op(i, x)) |
1851 |
a[i] = combiner.op(x, b[k]); |
1852 |
k++; |
1853 |
} |
1854 |
} |
1855 |
} |
1856 |
} |
1857 |
|
1858 |
static final class DRPap extends ParallelDoubleArrayWithFilter { |
1859 |
final IntAndDoublePredicate selector; |
1860 |
DRPap(ForkJoinExecutor ex, int origin, int fence, |
1861 |
double[] array, |
1862 |
IntAndDoublePredicate selector) { |
1863 |
super(ex, origin, fence, array); |
1864 |
this.selector = selector; |
1865 |
} |
1866 |
|
1867 |
boolean hasFilter() { return true; } |
1868 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
1869 |
|
1870 |
public ParallelDoubleArrayWithFilter withFilter |
1871 |
(DoublePredicate selector) { |
1872 |
return new DRPap |
1873 |
(ex, origin, fence, array, |
1874 |
compoundIndexedSelector(this.selector, selector)); |
1875 |
} |
1876 |
|
1877 |
public ParallelDoubleArrayWithFilter withIndexedFilter |
1878 |
(IntAndDoublePredicate selector) { |
1879 |
return new DRPap |
1880 |
(ex, origin, fence, array, |
1881 |
compoundIndexedSelector(this.selector, selector)); |
1882 |
} |
1883 |
|
1884 |
public <U> ParallelDoubleArrayWithMapping<U> withMapping |
1885 |
(DoubleToObject<? extends U> op) { |
1886 |
return new DROMPap<U>(ex, origin, fence, array, selector, op); |
1887 |
} |
1888 |
|
1889 |
public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { |
1890 |
return new DRDMPap(ex, origin, fence, array, selector, op); |
1891 |
} |
1892 |
|
1893 |
public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { |
1894 |
return new DRLMPap(ex, origin, fence, array, selector, op); |
1895 |
} |
1896 |
|
1897 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
1898 |
(IntAndDoubleToObject<? extends V> mapper) { |
1899 |
return new DROCPap<V>(ex, origin, fence, array, selector, mapper); |
1900 |
} |
1901 |
|
1902 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
1903 |
(IntAndDoubleToDouble mapper) { |
1904 |
return new DRDCPap(ex, origin, fence, array, selector, mapper); |
1905 |
} |
1906 |
|
1907 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
1908 |
(IntAndDoubleToLong mapper) { |
1909 |
return new DRLCPap(ex, origin, fence, array, selector, mapper); |
1910 |
} |
1911 |
|
1912 |
final void leafApply(int lo, int hi, DoubleProcedure procedure) { |
1913 |
final IntAndDoublePredicate s = selector; |
1914 |
final double[] a = this.array; |
1915 |
for (int i = lo; i < hi; ++i) { |
1916 |
double x = a[i]; |
1917 |
if (s.op(i, x)) |
1918 |
procedure.op(x); |
1919 |
} |
1920 |
} |
1921 |
|
1922 |
final double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
1923 |
final IntAndDoublePredicate s = selector; |
1924 |
boolean gotFirst = false; |
1925 |
double r = base; |
1926 |
final double[] a = this.array; |
1927 |
for (int i = lo; i < hi; ++i) { |
1928 |
double x = a[i]; |
1929 |
if (s.op(i, x)) { |
1930 |
if (!gotFirst) { |
1931 |
gotFirst = true; |
1932 |
r = x; |
1933 |
} |
1934 |
else |
1935 |
r = reducer.op(r, x); |
1936 |
} |
1937 |
} |
1938 |
return r; |
1939 |
} |
1940 |
|
1941 |
final void leafTransform(int l, int h, DoubleOp op) { |
1942 |
final double[] a = this.array; |
1943 |
final IntAndDoublePredicate s = selector; |
1944 |
for (int i = l; i < h; ++i) { |
1945 |
double x = a[i]; |
1946 |
if (s.op(i, x)) |
1947 |
a[i] = op.op(x); |
1948 |
} |
1949 |
} |
1950 |
|
1951 |
final void leafIndexMap(int l, int h, IntToDouble op) { |
1952 |
final double[] a = this.array; |
1953 |
final IntAndDoublePredicate s = selector; |
1954 |
for (int i = l; i < h; ++i) { |
1955 |
double x = a[i]; |
1956 |
if (s.op(i, x)) |
1957 |
a[i] = op.op(i); |
1958 |
} |
1959 |
} |
1960 |
|
1961 |
final void leafBinaryIndexMap(int l, int h, IntAndDoubleToDouble op) { |
1962 |
final double[] a = this.array; |
1963 |
final IntAndDoublePredicate s = selector; |
1964 |
for (int i = l; i < h; ++i) { |
1965 |
double x = a[i]; |
1966 |
if (s.op(i, x)) |
1967 |
a[i] = op.op(i, x); |
1968 |
} |
1969 |
} |
1970 |
|
1971 |
final void leafGenerate(int l, int h, DoubleGenerator generator) { |
1972 |
final double[] a = this.array; |
1973 |
final IntAndDoublePredicate s = selector; |
1974 |
for (int i = l; i < h; ++i) { |
1975 |
if (s.op(i, a[i])) |
1976 |
a[i] = generator.op(); |
1977 |
} |
1978 |
} |
1979 |
|
1980 |
final void leafFill(int l, int h, double value) { |
1981 |
final double[] a = this.array; |
1982 |
final IntAndDoublePredicate s = selector; |
1983 |
for (int i = l; i < h; ++i) { |
1984 |
if (s.op(i, a[i])) |
1985 |
a[i] = value; |
1986 |
} |
1987 |
} |
1988 |
|
1989 |
final void leafCombineInPlace |
1990 |
(int l, int h, double[] other, |
1991 |
int otherOffset, BinaryDoubleOp combiner) { |
1992 |
final double[] a = this.array; |
1993 |
final IntAndDoublePredicate s = selector; |
1994 |
int k = l + otherOffset; |
1995 |
for (int i = l; i < h; ++i) { |
1996 |
double x = a[i]; |
1997 |
if (s.op(i, x)) |
1998 |
a[i] = combiner.op(x, other[k]); |
1999 |
k++; |
2000 |
} |
2001 |
} |
2002 |
|
2003 |
final void leafCombineInPlace |
2004 |
(int l, int h, |
2005 |
ParallelDoubleArrayWithDoubleMapping other, |
2006 |
int otherOffset, BinaryDoubleOp combiner) { |
2007 |
final double[] a = this.array; |
2008 |
final IntAndDoublePredicate s = selector; |
2009 |
int k = l + otherOffset; |
2010 |
if (other.hasFilter()) { |
2011 |
for (int i = l; i < h; ++i) { |
2012 |
double x = a[i]; |
2013 |
if (s.op(i, x) && other.isSelected(k)) |
2014 |
a[i] = combiner.op(x, other.dget(k)); |
2015 |
k++; |
2016 |
} |
2017 |
} |
2018 |
else if (other.hasMap()) { |
2019 |
for (int i = l; i < h; ++i) { |
2020 |
double x = a[i]; |
2021 |
if (s.op(i, x)) |
2022 |
a[i] = combiner.op(x, other.dget(k)); |
2023 |
k++; |
2024 |
} |
2025 |
} |
2026 |
else { |
2027 |
double[] b = other.array; |
2028 |
for (int i = l; i < h; ++i) { |
2029 |
double x = a[i]; |
2030 |
if (s.op(i, x)) |
2031 |
a[i] = combiner.op(x, b[k]); |
2032 |
k++; |
2033 |
} |
2034 |
} |
2035 |
} |
2036 |
} |
2037 |
|
2038 |
static final class LRPap extends ParallelLongArrayWithFilter { |
2039 |
final IntAndLongPredicate selector; |
2040 |
LRPap(ForkJoinExecutor ex, int origin, int fence, |
2041 |
long[] array, |
2042 |
IntAndLongPredicate selector) { |
2043 |
super(ex, origin, fence, array); |
2044 |
this.selector = selector; |
2045 |
} |
2046 |
|
2047 |
boolean hasFilter() { return true; } |
2048 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
2049 |
|
2050 |
public ParallelLongArrayWithFilter withFilter(LongPredicate selector) { |
2051 |
return new LRPap(ex, origin, fence, array, |
2052 |
compoundIndexedSelector(this.selector, selector)); |
2053 |
} |
2054 |
|
2055 |
public ParallelLongArrayWithFilter withIndexedFilter |
2056 |
(IntAndLongPredicate selector) { |
2057 |
return new LRPap |
2058 |
(ex, origin, fence, array, |
2059 |
compoundIndexedSelector(this.selector, selector)); |
2060 |
} |
2061 |
|
2062 |
public <U> ParallelLongArrayWithMapping<U> withMapping |
2063 |
(LongToObject<? extends U> op) { |
2064 |
return new LROMPap<U>(ex, origin, fence, array, selector, op); |
2065 |
} |
2066 |
|
2067 |
public ParallelLongArrayWithLongMapping withMapping |
2068 |
(LongOp op) { |
2069 |
return new LRLMPap(ex, origin, fence, array, selector, op); |
2070 |
} |
2071 |
|
2072 |
public ParallelLongArrayWithDoubleMapping withMapping |
2073 |
(LongToDouble op) { |
2074 |
return new LRDMPap(ex, origin, fence, array, selector, op); |
2075 |
} |
2076 |
|
2077 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
2078 |
(IntAndLongToObject<? extends V> mapper) { |
2079 |
return new LROCPap<V>(ex, origin, fence, array, selector, mapper); |
2080 |
} |
2081 |
|
2082 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
2083 |
(IntAndLongToDouble mapper) { |
2084 |
return new LRDCPap(ex, origin, fence, array, selector, mapper); |
2085 |
} |
2086 |
|
2087 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
2088 |
(IntAndLongToLong mapper) { |
2089 |
return new LRLCPap(ex, origin, fence, array, selector, mapper); |
2090 |
} |
2091 |
|
2092 |
final void leafApply(int lo, int hi, LongProcedure procedure) { |
2093 |
final IntAndLongPredicate s = selector; |
2094 |
final long[] a = this.array; |
2095 |
for (int i = lo; i < hi; ++i) { |
2096 |
long x = a[i]; |
2097 |
if (s.op(i, x)) |
2098 |
procedure.op(x); |
2099 |
} |
2100 |
} |
2101 |
|
2102 |
final long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
2103 |
final IntAndLongPredicate s = selector; |
2104 |
boolean gotFirst = false; |
2105 |
long r = base; |
2106 |
final long[] a = this.array; |
2107 |
for (int i = lo; i < hi; ++i) { |
2108 |
long x = a[i]; |
2109 |
if (s.op(i, x)) { |
2110 |
if (!gotFirst) { |
2111 |
gotFirst = true; |
2112 |
r = x; |
2113 |
} |
2114 |
else |
2115 |
r = reducer.op(r, x); |
2116 |
} |
2117 |
} |
2118 |
return r; |
2119 |
} |
2120 |
|
2121 |
final void leafTransform(int l, int h, LongOp op) { |
2122 |
final long[] a = this.array; |
2123 |
final IntAndLongPredicate s = selector; |
2124 |
for (int i = l; i < h; ++i) { |
2125 |
long x = a[i]; |
2126 |
if (s.op(i, x)) |
2127 |
a[i] = op.op(x); |
2128 |
} |
2129 |
} |
2130 |
|
2131 |
final void leafIndexMap(int l, int h, IntToLong op) { |
2132 |
final long[] a = this.array; |
2133 |
final IntAndLongPredicate s = selector; |
2134 |
for (int i = l; i < h; ++i) { |
2135 |
long x = a[i]; |
2136 |
if (s.op(i, x)) |
2137 |
a[i] = op.op(i); |
2138 |
} |
2139 |
} |
2140 |
|
2141 |
final void leafBinaryIndexMap(int l, int h, IntAndLongToLong op) { |
2142 |
final long[] a = this.array; |
2143 |
final IntAndLongPredicate s = selector; |
2144 |
for (int i = l; i < h; ++i) { |
2145 |
long x = a[i]; |
2146 |
if (s.op(i, x)) |
2147 |
a[i] = op.op(i, x); |
2148 |
} |
2149 |
} |
2150 |
|
2151 |
final void leafGenerate(int l, int h, LongGenerator generator) { |
2152 |
final long[] a = this.array; |
2153 |
final IntAndLongPredicate s = selector; |
2154 |
for (int i = l; i < h; ++i) { |
2155 |
if (s.op(i, a[i])) |
2156 |
a[i] = generator.op(); |
2157 |
} |
2158 |
} |
2159 |
|
2160 |
final void leafFill(int l, int h, long value) { |
2161 |
final long[] a = this.array; |
2162 |
final IntAndLongPredicate s = selector; |
2163 |
for (int i = l; i < h; ++i) { |
2164 |
if (s.op(i, a[i])) |
2165 |
a[i] = value; |
2166 |
} |
2167 |
} |
2168 |
|
2169 |
final void leafCombineInPlace |
2170 |
(int l, int h, long[] other, |
2171 |
int otherOffset, BinaryLongOp combiner) { |
2172 |
final long[] a = this.array; |
2173 |
final IntAndLongPredicate s = selector; |
2174 |
int k = l + otherOffset; |
2175 |
for (int i = l; i < h; ++i) { |
2176 |
long x = a[i]; |
2177 |
if (s.op(i, x)) |
2178 |
a[i] = combiner.op(x, other[k]); |
2179 |
k++; |
2180 |
} |
2181 |
} |
2182 |
|
2183 |
final void leafCombineInPlace |
2184 |
(int l, int h, |
2185 |
ParallelLongArrayWithLongMapping other, |
2186 |
int otherOffset, BinaryLongOp combiner) { |
2187 |
final long[] a = this.array; |
2188 |
final IntAndLongPredicate s = selector; |
2189 |
int k = l + otherOffset; |
2190 |
if (other.hasFilter()) { |
2191 |
for (int i = l; i < h; ++i) { |
2192 |
long x = a[i]; |
2193 |
if (s.op(i, x) && other.isSelected(k)) |
2194 |
a[i] = combiner.op(x, other.lget(k)); |
2195 |
k++; |
2196 |
} |
2197 |
} |
2198 |
else if (other.hasMap()) { |
2199 |
for (int i = l; i < h; ++i) { |
2200 |
long x = a[i]; |
2201 |
if (s.op(i, x)) |
2202 |
a[i] = combiner.op(x, other.lget(k)); |
2203 |
k++; |
2204 |
} |
2205 |
} |
2206 |
else { |
2207 |
long[] b = other.array; |
2208 |
for (int i = l; i < h; ++i) { |
2209 |
long x = a[i]; |
2210 |
if (s.op(i, x)) |
2211 |
a[i] = combiner.op(x, b[k]); |
2212 |
k++; |
2213 |
} |
2214 |
} |
2215 |
} |
2216 |
} |
2217 |
|
2218 |
// Object-mapped |
2219 |
|
2220 |
static abstract class OOMPap<T,U> extends ParallelArrayWithMapping<T,U> { |
2221 |
final Op<? super T, ? extends U> op; |
2222 |
OOMPap(ForkJoinExecutor ex, int origin, int fence, |
2223 |
T[] array, |
2224 |
Op<? super T, ? extends U> op) { |
2225 |
super(ex, origin, fence, array); |
2226 |
this.op = op; |
2227 |
} |
2228 |
|
2229 |
final boolean hasMap() { return true; } |
2230 |
final Object oget(int i) { return op.op(this.array[i]); } |
2231 |
final double dget(int i) { return ((Number)oget(i)).doubleValue(); } |
2232 |
final long lget(int i) { return ((Number)oget(i)).longValue(); } |
2233 |
|
2234 |
final void leafTransfer(int lo, int hi, Object[] dest, int offset) { |
2235 |
final Op f = op; |
2236 |
final Object[] a = this.array; |
2237 |
for (int i = lo; i < hi; ++i) |
2238 |
dest[offset++] = f.op(a[i]); |
2239 |
} |
2240 |
|
2241 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
2242 |
Object[] dest, int offset) { |
2243 |
final Object[] a = this.array; |
2244 |
final Op f = op; |
2245 |
for (int i = loIdx; i < hiIdx; ++i) |
2246 |
dest[offset++] = f.op(a[indices[i]]); |
2247 |
} |
2248 |
} |
2249 |
|
2250 |
static abstract class DOMPap<U> extends ParallelDoubleArrayWithMapping<U> { |
2251 |
final DoubleToObject<? extends U> op; |
2252 |
DOMPap(ForkJoinExecutor ex, int origin, int fence, |
2253 |
double[] array, DoubleToObject<? extends U> op) { |
2254 |
super(ex, origin, fence, array); |
2255 |
this.op = op; |
2256 |
} |
2257 |
|
2258 |
final boolean hasMap() { return true; } |
2259 |
final Object oget(int i) { return op.op(this.array[i]); } |
2260 |
final double dget(int i) { return ((Number)oget(i)).doubleValue(); } |
2261 |
final long lget(int i) { return ((Number)oget(i)).longValue(); } |
2262 |
|
2263 |
final void leafTransfer(int lo, int hi, Object[] dest, int offset) { |
2264 |
final double[] a = this.array; |
2265 |
final DoubleToObject f = op; |
2266 |
for (int i = lo; i < hi; ++i) |
2267 |
dest[offset++] = f.op(a[i]); |
2268 |
} |
2269 |
|
2270 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
2271 |
Object[] dest, int offset) { |
2272 |
final double[] a = this.array; |
2273 |
final DoubleToObject f = op; |
2274 |
for (int i = loIdx; i < hiIdx; ++i) |
2275 |
dest[offset++] = f.op(a[indices[i]]); |
2276 |
} |
2277 |
} |
2278 |
|
2279 |
static abstract class LOMPap<U> extends ParallelLongArrayWithMapping<U> { |
2280 |
final LongToObject<? extends U> op; |
2281 |
LOMPap(ForkJoinExecutor ex, int origin, int fence, |
2282 |
long[] array, LongToObject<? extends U> op) { |
2283 |
super(ex, origin, fence, array); |
2284 |
this.op = op; |
2285 |
} |
2286 |
|
2287 |
final boolean hasMap() { return true; } |
2288 |
final Object oget(int i) { return op.op(this.array[i]); } |
2289 |
final double dget(int i) { return ((Number)oget(i)).doubleValue(); } |
2290 |
final long lget(int i) { return ((Number)oget(i)).longValue(); } |
2291 |
|
2292 |
final void leafTransfer(int lo, int hi, Object[] dest, int offset) { |
2293 |
final long[] a = this.array; |
2294 |
final LongToObject f = op; |
2295 |
for (int i = lo; i < hi; ++i) |
2296 |
dest[offset++] = f.op(a[i]); |
2297 |
} |
2298 |
|
2299 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
2300 |
Object[] dest, int offset) { |
2301 |
final long[] a = this.array; |
2302 |
final LongToObject f = op; |
2303 |
for (int i = loIdx; i < hiIdx; ++i) |
2304 |
dest[offset++] = f.op(a[indices[i]]); |
2305 |
} |
2306 |
} |
2307 |
|
2308 |
// Object mapped, unfiltered |
2309 |
|
2310 |
static final class OUOMPap<T,U> extends OOMPap<T,U> { |
2311 |
OUOMPap(ForkJoinExecutor ex, int origin, int fence, |
2312 |
T[] array, Op<? super T, ? extends U> op) { |
2313 |
super(ex, origin, fence, array, op); |
2314 |
} |
2315 |
|
2316 |
public <V> ParallelArrayWithMapping<T, V> withMapping |
2317 |
(Op<? super U, ? extends V> op) { |
2318 |
return new OUOMPap<T,V>(ex, origin, fence, array, |
2319 |
CommonOps.compoundOp(this.op, op)); |
2320 |
} |
2321 |
|
2322 |
public ParallelArrayWithDoubleMapping<T> withMapping |
2323 |
(ObjectToDouble<? super U> op) { |
2324 |
return new OUDMPap<T>(ex, origin, fence, array, |
2325 |
CommonOps.compoundOp(this.op, op)); |
2326 |
} |
2327 |
|
2328 |
public ParallelArrayWithLongMapping<T> withMapping |
2329 |
(ObjectToLong<? super U> op) { |
2330 |
return new OULMPap<T>(ex, origin, fence, array, |
2331 |
CommonOps.compoundOp(this.op, op)); |
2332 |
} |
2333 |
|
2334 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
2335 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
2336 |
return new OUOCPap<T,V>(ex, origin, fence, array, |
2337 |
compoundIndexedOp(this.op, mapper)); |
2338 |
} |
2339 |
|
2340 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
2341 |
(IntAndObjectToDouble<? super U> mapper) { |
2342 |
return new OUDCPap<T>(ex, origin, fence, array, |
2343 |
compoundIndexedOp(this.op, mapper)); |
2344 |
} |
2345 |
|
2346 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
2347 |
(IntAndObjectToLong<? super U> mapper) { |
2348 |
return new OULCPap<T>(ex, origin, fence, array, |
2349 |
compoundIndexedOp(this.op, mapper)); |
2350 |
} |
2351 |
|
2352 |
void leafApply(int lo, int hi, Procedure procedure) { |
2353 |
final Op f = op; |
2354 |
final Object[] a = this.array; |
2355 |
for (int i = lo; i < hi; ++i) |
2356 |
procedure.op(f.op(a[i])); |
2357 |
} |
2358 |
|
2359 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
2360 |
if (lo >= hi) |
2361 |
return base; |
2362 |
final Object[] a = this.array; |
2363 |
final Op f = op; |
2364 |
Object r = f.op(a[lo]); |
2365 |
for (int i = lo+1; i < hi; ++i) |
2366 |
r = reducer.op(r, f.op(a[i])); |
2367 |
return r; |
2368 |
} |
2369 |
|
2370 |
} |
2371 |
|
2372 |
static final class DUOMPap<U> extends DOMPap<U> { |
2373 |
DUOMPap(ForkJoinExecutor ex, int origin, int fence, |
2374 |
double[] array, DoubleToObject<? extends U> op) { |
2375 |
super(ex, origin, fence, array, op); |
2376 |
} |
2377 |
|
2378 |
public <V> ParallelDoubleArrayWithMapping<V> withMapping |
2379 |
(Op<? super U, ? extends V> op) { |
2380 |
return new DUOMPap<V>(ex, origin, fence, array, |
2381 |
CommonOps.compoundOp(this.op, op)); |
2382 |
} |
2383 |
|
2384 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
2385 |
(ObjectToDouble<? super U> op){ |
2386 |
return new DUDMPap(ex, origin, fence, array, |
2387 |
CommonOps.compoundOp(this.op, op)); |
2388 |
} |
2389 |
|
2390 |
public ParallelDoubleArrayWithLongMapping withMapping |
2391 |
(ObjectToLong<? super U> op) { |
2392 |
return new DULMPap(ex, origin, fence, array, |
2393 |
CommonOps.compoundOp(this.op, op)); |
2394 |
} |
2395 |
|
2396 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
2397 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
2398 |
return new DUOCPap<V>(ex, origin, fence, array, |
2399 |
compoundIndexedOp(this.op, mapper)); |
2400 |
} |
2401 |
|
2402 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
2403 |
(IntAndObjectToDouble<? super U> mapper) { |
2404 |
return new DUDCPap(ex, origin, fence, array, |
2405 |
compoundIndexedOp(this.op, mapper)); |
2406 |
} |
2407 |
|
2408 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
2409 |
(IntAndObjectToLong<? super U> mapper) { |
2410 |
return new DULCPap(ex, origin, fence, array, |
2411 |
compoundIndexedOp(this.op, mapper)); |
2412 |
} |
2413 |
|
2414 |
void leafApply(int lo, int hi, Procedure procedure) { |
2415 |
final double[] a = this.array; |
2416 |
final DoubleToObject f = op; |
2417 |
for (int i = lo; i < hi; ++i) |
2418 |
procedure.op(f.op(a[i])); |
2419 |
} |
2420 |
|
2421 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
2422 |
if (lo >= hi) |
2423 |
return base; |
2424 |
final double[] a = this.array; |
2425 |
final DoubleToObject f = op; |
2426 |
Object r = f.op(a[lo]); |
2427 |
for (int i = lo+1; i < hi; ++i) |
2428 |
r = reducer.op(r, f.op(a[i])); |
2429 |
return r; |
2430 |
} |
2431 |
|
2432 |
} |
2433 |
|
2434 |
static final class LUOMPap<U> extends LOMPap<U> { |
2435 |
LUOMPap(ForkJoinExecutor ex, int origin, int fence, |
2436 |
long[] array, LongToObject<? extends U> op) { |
2437 |
super(ex, origin, fence, array, op); |
2438 |
} |
2439 |
|
2440 |
public <V> ParallelLongArrayWithMapping<V> withMapping |
2441 |
(Op<? super U, ? extends V> op) { |
2442 |
return new LUOMPap<V>(ex, origin, fence, array, |
2443 |
CommonOps.compoundOp(this.op, op)); |
2444 |
} |
2445 |
|
2446 |
public ParallelLongArrayWithLongMapping withMapping |
2447 |
(ObjectToLong<? super U> op) { |
2448 |
return new LULMPap(ex, origin, fence, array, |
2449 |
CommonOps.compoundOp(this.op, op)); |
2450 |
} |
2451 |
|
2452 |
public ParallelLongArrayWithDoubleMapping withMapping |
2453 |
(ObjectToDouble<? super U> op) { |
2454 |
return new LUDMPap(ex, origin, fence, array, |
2455 |
CommonOps.compoundOp(this.op, op)); |
2456 |
} |
2457 |
|
2458 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
2459 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
2460 |
return new LUOCPap<V>(ex, origin, fence, array, |
2461 |
compoundIndexedOp(this.op, mapper)); |
2462 |
} |
2463 |
|
2464 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
2465 |
(IntAndObjectToDouble<? super U> mapper) { |
2466 |
return new LUDCPap(ex, origin, fence, array, |
2467 |
compoundIndexedOp(this.op, mapper)); |
2468 |
} |
2469 |
|
2470 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
2471 |
(IntAndObjectToLong<? super U> mapper) { |
2472 |
return new LULCPap(ex, origin, fence, array, |
2473 |
compoundIndexedOp(this.op, mapper)); |
2474 |
} |
2475 |
|
2476 |
void leafApply(int lo, int hi, Procedure procedure) { |
2477 |
final long[] a = this.array; |
2478 |
final LongToObject f = op; |
2479 |
for (int i = lo; i < hi; ++i) |
2480 |
procedure.op(f.op(a[i])); |
2481 |
} |
2482 |
|
2483 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
2484 |
if (lo >= hi) |
2485 |
return base; |
2486 |
final long[] a = this.array; |
2487 |
final LongToObject f = op; |
2488 |
Object r = f.op(a[lo]); |
2489 |
for (int i = lo+1; i < hi; ++i) |
2490 |
r = reducer.op(r, f.op(a[i])); |
2491 |
return r; |
2492 |
} |
2493 |
|
2494 |
} |
2495 |
|
2496 |
// Object-mapped, filtered |
2497 |
static final class OFOMPap<T,U> extends OOMPap<T,U> { |
2498 |
final Predicate<? super T> selector; |
2499 |
|
2500 |
OFOMPap(ForkJoinExecutor ex, int origin, int fence, |
2501 |
T[] array, Predicate<? super T> selector, |
2502 |
Op<? super T, ? extends U> op) { |
2503 |
super(ex, origin, fence, array, op); |
2504 |
this.selector = selector; |
2505 |
} |
2506 |
|
2507 |
boolean hasFilter() { return true; } |
2508 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
2509 |
|
2510 |
public <V> ParallelArrayWithMapping<T, V> withMapping |
2511 |
(Op<? super U, ? extends V> op) { |
2512 |
return new OFOMPap<T,V> |
2513 |
(ex, origin, fence, array, selector, |
2514 |
CommonOps.compoundOp(this.op, op)); |
2515 |
} |
2516 |
|
2517 |
public ParallelArrayWithDoubleMapping<T> withMapping |
2518 |
(ObjectToDouble<? super U> op) { |
2519 |
return new OFDMPap<T>(ex, origin, fence, array, selector, |
2520 |
CommonOps.compoundOp(this.op, op)); |
2521 |
} |
2522 |
|
2523 |
public ParallelArrayWithLongMapping<T> withMapping |
2524 |
(ObjectToLong<? super U> op) { |
2525 |
return new OFLMPap<T>(ex, origin, fence, array, selector, |
2526 |
CommonOps.compoundOp(this.op, op)); |
2527 |
} |
2528 |
|
2529 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
2530 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
2531 |
return new OFOCPap<T,V>(ex, origin, fence, array, selector, |
2532 |
compoundIndexedOp(this.op, mapper)); |
2533 |
} |
2534 |
|
2535 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
2536 |
(IntAndObjectToDouble<? super U> mapper) { |
2537 |
return new OFDCPap<T>(ex, origin, fence, array, selector, |
2538 |
compoundIndexedOp(this.op, mapper)); |
2539 |
} |
2540 |
|
2541 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
2542 |
(IntAndObjectToLong<? super U> mapper) { |
2543 |
return new OFLCPap<T>(ex, origin, fence, array, selector, |
2544 |
compoundIndexedOp(this.op, mapper)); |
2545 |
} |
2546 |
|
2547 |
void leafApply(int lo, int hi, Procedure procedure) { |
2548 |
final Predicate s = selector; |
2549 |
final Object[] a = this.array; |
2550 |
final Op f = op; |
2551 |
for (int i = lo; i < hi; ++i) { |
2552 |
Object x = a[i]; |
2553 |
if (s.op(x)) |
2554 |
procedure.op(f.op(x)); |
2555 |
} |
2556 |
} |
2557 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
2558 |
final Predicate s = selector; |
2559 |
final Object[] a = this.array; |
2560 |
final Op f = op; |
2561 |
boolean gotFirst = false; |
2562 |
Object r = base; |
2563 |
for (int i = lo; i < hi; ++i) { |
2564 |
Object x = a[i]; |
2565 |
if (s.op(x)) { |
2566 |
Object y = f.op(x); |
2567 |
if (!gotFirst) { |
2568 |
gotFirst = true; |
2569 |
r = y; |
2570 |
} |
2571 |
else |
2572 |
r = reducer.op(r, y); |
2573 |
} |
2574 |
} |
2575 |
return r; |
2576 |
} |
2577 |
|
2578 |
} |
2579 |
|
2580 |
static final class DFOMPap<U> extends DOMPap<U> { |
2581 |
final DoublePredicate selector; |
2582 |
DFOMPap(ForkJoinExecutor ex, int origin, int fence, |
2583 |
double[] array, DoublePredicate selector, |
2584 |
DoubleToObject<? extends U> op) { |
2585 |
super(ex, origin, fence, array, op); |
2586 |
this.selector = selector; |
2587 |
} |
2588 |
|
2589 |
boolean hasFilter() { return true; } |
2590 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
2591 |
|
2592 |
public ParallelArray<U> all(Class<? super U> elementType) { |
2593 |
PAS.FJOSelectAllDriver r = new PAS.FJOSelectAllDriver |
2594 |
(this, elementType); |
2595 |
ex.invoke(r); |
2596 |
return new ParallelArray<U>(ex, (U[])(r.results)); |
2597 |
} |
2598 |
|
2599 |
public <V> ParallelDoubleArrayWithMapping<V> withMapping |
2600 |
(Op<? super U, ? extends V> op) { |
2601 |
return new DFOMPap<V>(ex, origin, fence, array, selector, |
2602 |
CommonOps.compoundOp(this.op, op)); |
2603 |
} |
2604 |
|
2605 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
2606 |
(ObjectToDouble<? super U> op) { |
2607 |
return new DFDMPap(ex, origin, fence, array, selector, |
2608 |
CommonOps.compoundOp(this.op, op)); |
2609 |
} |
2610 |
|
2611 |
public ParallelDoubleArrayWithLongMapping withMapping |
2612 |
(ObjectToLong<? super U> op) { |
2613 |
return new DFLMPap(ex, origin, fence, array, selector, |
2614 |
CommonOps.compoundOp(this.op, op)); |
2615 |
} |
2616 |
|
2617 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
2618 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
2619 |
return new DFOCPap<V>(ex, origin, fence, array, selector, |
2620 |
compoundIndexedOp(this.op, mapper)); |
2621 |
} |
2622 |
|
2623 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
2624 |
(IntAndObjectToDouble<? super U> mapper) { |
2625 |
return new DFDCPap(ex, origin, fence, array, selector, |
2626 |
compoundIndexedOp(this.op, mapper)); |
2627 |
} |
2628 |
|
2629 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
2630 |
(IntAndObjectToLong<? super U> mapper) { |
2631 |
return new DFLCPap(ex, origin, fence, array, selector, |
2632 |
compoundIndexedOp(this.op, mapper)); |
2633 |
} |
2634 |
|
2635 |
void leafApply(int lo, int hi, Procedure procedure) { |
2636 |
final DoublePredicate s = selector; |
2637 |
final DoubleToObject f = op; |
2638 |
final double[] a = this.array; |
2639 |
for (int i = lo; i < hi; ++i) { |
2640 |
double x = a[i]; |
2641 |
if (s.op(x)) |
2642 |
procedure.op(f.op(x)); |
2643 |
} |
2644 |
} |
2645 |
|
2646 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
2647 |
boolean gotFirst = false; |
2648 |
Object r = base; |
2649 |
final DoublePredicate s = selector; |
2650 |
final DoubleToObject f = op; |
2651 |
final double[] a = this.array; |
2652 |
for (int i = lo; i < hi; ++i) { |
2653 |
double x = a[i]; |
2654 |
if (s.op(x)) { |
2655 |
Object y = f.op(x); |
2656 |
if (!gotFirst) { |
2657 |
gotFirst = true; |
2658 |
r = y; |
2659 |
} |
2660 |
else |
2661 |
r = reducer.op(r, y); |
2662 |
} |
2663 |
} |
2664 |
return r; |
2665 |
} |
2666 |
|
2667 |
} |
2668 |
|
2669 |
static final class LFOMPap<U> extends LOMPap<U> { |
2670 |
final LongPredicate selector; |
2671 |
LFOMPap(ForkJoinExecutor ex, int origin, int fence, |
2672 |
long[] array, LongPredicate selector, |
2673 |
LongToObject<? extends U> op) { |
2674 |
super(ex, origin, fence, array, op); |
2675 |
this.selector = selector; |
2676 |
} |
2677 |
|
2678 |
boolean hasFilter() { return true; } |
2679 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
2680 |
|
2681 |
public <V> ParallelLongArrayWithMapping<V> withMapping |
2682 |
(Op<? super U, ? extends V> op) { |
2683 |
return new LFOMPap<V>(ex, origin, fence, array, selector, |
2684 |
CommonOps.compoundOp(this.op, op)); |
2685 |
} |
2686 |
|
2687 |
public ParallelLongArrayWithLongMapping withMapping |
2688 |
(ObjectToLong<? super U> op) { |
2689 |
return new LFLMPap(ex, origin, fence, array, selector, |
2690 |
CommonOps.compoundOp(this.op, op)); |
2691 |
} |
2692 |
|
2693 |
public ParallelLongArrayWithDoubleMapping withMapping |
2694 |
(ObjectToDouble<? super U> op) { |
2695 |
return new LFDMPap(ex, origin, fence, array, selector, |
2696 |
CommonOps.compoundOp(this.op, op)); |
2697 |
} |
2698 |
|
2699 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
2700 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
2701 |
return new LFOCPap<V>(ex, origin, fence, array, selector, |
2702 |
compoundIndexedOp(this.op, mapper)); |
2703 |
} |
2704 |
|
2705 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
2706 |
(IntAndObjectToDouble<? super U> mapper) { |
2707 |
return new LFDCPap(ex, origin, fence, array, selector, |
2708 |
compoundIndexedOp(this.op, mapper)); |
2709 |
} |
2710 |
|
2711 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
2712 |
(IntAndObjectToLong<? super U> mapper) { |
2713 |
return new LFLCPap(ex, origin, fence, array, selector, |
2714 |
compoundIndexedOp(this.op, mapper)); |
2715 |
} |
2716 |
|
2717 |
void leafApply(int lo, int hi, Procedure procedure) { |
2718 |
final LongPredicate s = selector; |
2719 |
final LongToObject f = op; |
2720 |
final long[] a = this.array; |
2721 |
for (int i = lo; i < hi; ++i) { |
2722 |
long x = a[i]; |
2723 |
if (s.op(x)) |
2724 |
procedure.op(f.op(x)); |
2725 |
} |
2726 |
} |
2727 |
|
2728 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
2729 |
final LongPredicate s = selector; |
2730 |
final LongToObject f = op; |
2731 |
boolean gotFirst = false; |
2732 |
Object r = base; |
2733 |
final long[] a = this.array; |
2734 |
for (int i = lo; i < hi; ++i) { |
2735 |
long x = a[i]; |
2736 |
if (s.op(x)) { |
2737 |
Object y = f.op(x); |
2738 |
if (!gotFirst) { |
2739 |
gotFirst = true; |
2740 |
r = y; |
2741 |
} |
2742 |
else |
2743 |
r = reducer.op(r, y); |
2744 |
} |
2745 |
} |
2746 |
return r; |
2747 |
} |
2748 |
|
2749 |
} |
2750 |
|
2751 |
// Object-mapped, relational |
2752 |
static final class OROMPap<T,U> extends OOMPap<T,U> { |
2753 |
final IntAndObjectPredicate<? super T> selector; |
2754 |
|
2755 |
OROMPap(ForkJoinExecutor ex, int origin, int fence, |
2756 |
T[] array, IntAndObjectPredicate<? super T> selector, |
2757 |
Op<? super T, ? extends U> op) { |
2758 |
super(ex, origin, fence, array, op); |
2759 |
this.selector = selector; |
2760 |
} |
2761 |
|
2762 |
boolean hasFilter() { return true; } |
2763 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
2764 |
|
2765 |
public <V> ParallelArrayWithMapping<T, V> withMapping |
2766 |
(Op<? super U, ? extends V> op) { |
2767 |
return new OROMPap<T,V> |
2768 |
(ex, origin, fence, array, selector, |
2769 |
CommonOps.compoundOp(this.op, op)); |
2770 |
} |
2771 |
|
2772 |
public ParallelArrayWithDoubleMapping<T> withMapping(ObjectToDouble<? super U> op) { |
2773 |
return new ORDMPap<T>(ex, origin, fence, array, selector, |
2774 |
CommonOps.compoundOp(this.op, op)); |
2775 |
} |
2776 |
|
2777 |
public ParallelArrayWithLongMapping<T> withMapping(ObjectToLong<? super U> op) { |
2778 |
return new ORLMPap<T>(ex, origin, fence, array, selector, |
2779 |
CommonOps.compoundOp(this.op, op)); |
2780 |
} |
2781 |
|
2782 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
2783 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
2784 |
return new OROCPap<T,V>(ex, origin, fence, array, selector, |
2785 |
compoundIndexedOp(this.op, mapper)); |
2786 |
} |
2787 |
|
2788 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
2789 |
(IntAndObjectToDouble<? super U> mapper) { |
2790 |
return new ORDCPap<T>(ex, origin, fence, array, selector, |
2791 |
compoundIndexedOp(this.op, mapper)); |
2792 |
} |
2793 |
|
2794 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
2795 |
(IntAndObjectToLong<? super U> mapper) { |
2796 |
return new ORLCPap<T>(ex, origin, fence, array, selector, |
2797 |
compoundIndexedOp(this.op, mapper)); |
2798 |
} |
2799 |
|
2800 |
void leafApply(int lo, int hi, Procedure procedure) { |
2801 |
final IntAndObjectPredicate s = selector; |
2802 |
final Object[] a = this.array; |
2803 |
final Op f = op; |
2804 |
for (int i = lo; i < hi; ++i) { |
2805 |
Object x = a[i]; |
2806 |
if (s.op(i, x)) |
2807 |
procedure.op(f.op(x)); |
2808 |
} |
2809 |
} |
2810 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
2811 |
final IntAndObjectPredicate s = selector; |
2812 |
final Object[] a = this.array; |
2813 |
final Op f = op; |
2814 |
boolean gotFirst = false; |
2815 |
Object r = base; |
2816 |
for (int i = lo; i < hi; ++i) { |
2817 |
Object x = a[i]; |
2818 |
if (s.op(i, x)) { |
2819 |
Object y = f.op(x); |
2820 |
if (!gotFirst) { |
2821 |
gotFirst = true; |
2822 |
r = y; |
2823 |
} |
2824 |
else |
2825 |
r = reducer.op(r, y); |
2826 |
} |
2827 |
} |
2828 |
return r; |
2829 |
} |
2830 |
|
2831 |
} |
2832 |
|
2833 |
static final class DROMPap<U> extends DOMPap<U> { |
2834 |
final IntAndDoublePredicate selector; |
2835 |
DROMPap(ForkJoinExecutor ex, int origin, int fence, |
2836 |
double[] array, IntAndDoublePredicate selector, |
2837 |
DoubleToObject<? extends U> op) { |
2838 |
super(ex, origin, fence, array, op); |
2839 |
this.selector = selector; |
2840 |
} |
2841 |
|
2842 |
boolean hasFilter() { return true; } |
2843 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
2844 |
|
2845 |
public ParallelArray<U> all(Class<? super U> elementType) { |
2846 |
PAS.FJOSelectAllDriver r = new PAS.FJOSelectAllDriver |
2847 |
(this, elementType); |
2848 |
ex.invoke(r); |
2849 |
return new ParallelArray<U>(ex, (U[])(r.results)); |
2850 |
} |
2851 |
|
2852 |
public <V> ParallelDoubleArrayWithMapping<V> withMapping |
2853 |
(Op<? super U, ? extends V> op) { |
2854 |
return new DROMPap<V>(ex, origin, fence, array, selector, |
2855 |
CommonOps.compoundOp(this.op, op)); |
2856 |
} |
2857 |
|
2858 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
2859 |
(ObjectToDouble<? super U> op) { |
2860 |
return new DRDMPap(ex, origin, fence, array, selector, |
2861 |
CommonOps.compoundOp(this.op, op)); |
2862 |
} |
2863 |
|
2864 |
public ParallelDoubleArrayWithLongMapping withMapping |
2865 |
(ObjectToLong<? super U> op) { |
2866 |
return new DRLMPap(ex, origin, fence, array, selector, |
2867 |
CommonOps.compoundOp(this.op, op)); |
2868 |
} |
2869 |
|
2870 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
2871 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
2872 |
return new DROCPap<V>(ex, origin, fence, array, selector, |
2873 |
compoundIndexedOp(this.op, mapper)); |
2874 |
} |
2875 |
|
2876 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
2877 |
(IntAndObjectToDouble<? super U> mapper) { |
2878 |
return new DRDCPap(ex, origin, fence, array, selector, |
2879 |
compoundIndexedOp(this.op, mapper)); |
2880 |
} |
2881 |
|
2882 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
2883 |
(IntAndObjectToLong<? super U> mapper) { |
2884 |
return new DRLCPap(ex, origin, fence, array, selector, |
2885 |
compoundIndexedOp(this.op, mapper)); |
2886 |
} |
2887 |
|
2888 |
void leafApply(int lo, int hi, Procedure procedure) { |
2889 |
final IntAndDoublePredicate s = selector; |
2890 |
final DoubleToObject f = op; |
2891 |
final double[] a = this.array; |
2892 |
for (int i = lo; i < hi; ++i) { |
2893 |
double x = a[i]; |
2894 |
if (s.op(i, x)) |
2895 |
procedure.op(f.op(x)); |
2896 |
} |
2897 |
} |
2898 |
|
2899 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
2900 |
boolean gotFirst = false; |
2901 |
Object r = base; |
2902 |
final IntAndDoublePredicate s = selector; |
2903 |
final DoubleToObject f = op; |
2904 |
final double[] a = this.array; |
2905 |
for (int i = lo; i < hi; ++i) { |
2906 |
double x = a[i]; |
2907 |
if (s.op(i, x)) { |
2908 |
Object y = f.op(x); |
2909 |
if (!gotFirst) { |
2910 |
gotFirst = true; |
2911 |
r = y; |
2912 |
} |
2913 |
else |
2914 |
r = reducer.op(r, y); |
2915 |
} |
2916 |
} |
2917 |
return r; |
2918 |
} |
2919 |
|
2920 |
} |
2921 |
|
2922 |
static final class LROMPap<U> extends LOMPap<U> { |
2923 |
final IntAndLongPredicate selector; |
2924 |
LROMPap(ForkJoinExecutor ex, int origin, int fence, |
2925 |
long[] array, IntAndLongPredicate selector, |
2926 |
LongToObject<? extends U> op) { |
2927 |
super(ex, origin, fence, array, op); |
2928 |
this.selector = selector; |
2929 |
} |
2930 |
|
2931 |
boolean hasFilter() { return true; } |
2932 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
2933 |
|
2934 |
public <V> ParallelLongArrayWithMapping<V> withMapping |
2935 |
(Op<? super U, ? extends V> op) { |
2936 |
return new LROMPap<V>(ex, origin, fence, array, selector, |
2937 |
CommonOps.compoundOp(this.op, op)); |
2938 |
} |
2939 |
|
2940 |
public ParallelLongArrayWithLongMapping withMapping |
2941 |
(ObjectToLong<? super U> op) { |
2942 |
return new LRLMPap(ex, origin, fence, array, selector, |
2943 |
CommonOps.compoundOp(this.op, op)); |
2944 |
} |
2945 |
|
2946 |
public ParallelLongArrayWithDoubleMapping withMapping |
2947 |
(ObjectToDouble<? super U> op) { |
2948 |
return new LRDMPap(ex, origin, fence, array, selector, |
2949 |
CommonOps.compoundOp(this.op, op)); |
2950 |
} |
2951 |
|
2952 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
2953 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
2954 |
return new LROCPap<V>(ex, origin, fence, array, selector, |
2955 |
compoundIndexedOp(this.op, mapper)); |
2956 |
} |
2957 |
|
2958 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
2959 |
(IntAndObjectToDouble<? super U> mapper) { |
2960 |
return new LRDCPap(ex, origin, fence, array, selector, |
2961 |
compoundIndexedOp(this.op, mapper)); |
2962 |
} |
2963 |
|
2964 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
2965 |
(IntAndObjectToLong<? super U> mapper) { |
2966 |
return new LRLCPap(ex, origin, fence, array, selector, |
2967 |
compoundIndexedOp(this.op, mapper)); |
2968 |
} |
2969 |
|
2970 |
void leafApply(int lo, int hi, Procedure procedure) { |
2971 |
final IntAndLongPredicate s = selector; |
2972 |
final LongToObject f = op; |
2973 |
final long[] a = this.array; |
2974 |
for (int i = lo; i < hi; ++i) { |
2975 |
long x = a[i]; |
2976 |
if (s.op(i, x)) |
2977 |
procedure.op(f.op(x)); |
2978 |
} |
2979 |
} |
2980 |
|
2981 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
2982 |
final IntAndLongPredicate s = selector; |
2983 |
final LongToObject f = op; |
2984 |
boolean gotFirst = false; |
2985 |
Object r = base; |
2986 |
final long[] a = this.array; |
2987 |
for (int i = lo; i < hi; ++i) { |
2988 |
long x = a[i]; |
2989 |
if (s.op(i, x)) { |
2990 |
Object y = f.op(x); |
2991 |
if (!gotFirst) { |
2992 |
gotFirst = true; |
2993 |
r = y; |
2994 |
} |
2995 |
else |
2996 |
r = reducer.op(r, y); |
2997 |
} |
2998 |
} |
2999 |
return r; |
3000 |
} |
3001 |
} |
3002 |
|
3003 |
// Object-combined |
3004 |
|
3005 |
static abstract class OOCPap<T,U> extends ParallelArrayWithMapping<T,U> { |
3006 |
final IntAndObjectToObject<? super T, ? extends U> op; |
3007 |
OOCPap(ForkJoinExecutor ex, int origin, int fence, |
3008 |
T[] array, |
3009 |
IntAndObjectToObject<? super T, ? extends U> op) { |
3010 |
super(ex, origin, fence, array); |
3011 |
this.op = op; |
3012 |
} |
3013 |
|
3014 |
final boolean hasMap() { return true; } |
3015 |
final Object oget(int i) { return op.op(i, this.array[i]); } |
3016 |
final double dget(int i) { return ((Number)oget(i)).doubleValue(); } |
3017 |
final long lget(int i) { return ((Number)oget(i)).longValue(); } |
3018 |
|
3019 |
final void leafTransfer(int lo, int hi, Object[] dest, int offset) { |
3020 |
final IntAndObjectToObject f = op; |
3021 |
final Object[] a = this.array; |
3022 |
for (int i = lo; i < hi; ++i) |
3023 |
dest[offset++] = f.op(i, a[i]); |
3024 |
} |
3025 |
|
3026 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
3027 |
Object[] dest, int offset) { |
3028 |
final Object[] a = this.array; |
3029 |
final IntAndObjectToObject f = op; |
3030 |
for (int i = loIdx; i < hiIdx; ++i) { |
3031 |
int idx = indices[i]; |
3032 |
dest[offset++] = f.op(idx, a[idx]); |
3033 |
} |
3034 |
} |
3035 |
} |
3036 |
|
3037 |
static abstract class DOCPap<U> extends ParallelDoubleArrayWithMapping<U> { |
3038 |
final IntAndDoubleToObject<? extends U> op; |
3039 |
DOCPap(ForkJoinExecutor ex, int origin, int fence, |
3040 |
double[] array, IntAndDoubleToObject<? extends U> op) { |
3041 |
super(ex, origin, fence, array); |
3042 |
this.op = op; |
3043 |
} |
3044 |
|
3045 |
final boolean hasMap() { return true; } |
3046 |
final Object oget(int i) { return op.op(i, this.array[i]); } |
3047 |
final double dget(int i) { return ((Number)oget(i)).doubleValue(); } |
3048 |
final long lget(int i) { return ((Number)oget(i)).longValue(); } |
3049 |
|
3050 |
final void leafTransfer(int lo, int hi, Object[] dest, int offset) { |
3051 |
final IntAndDoubleToObject f = op; |
3052 |
final double[] a = this.array; |
3053 |
for (int i = lo; i < hi; ++i) |
3054 |
dest[offset++] = f.op(i, a[i]); |
3055 |
} |
3056 |
|
3057 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
3058 |
Object[] dest, int offset) { |
3059 |
final double[] a = this.array; |
3060 |
final IntAndDoubleToObject f = op; |
3061 |
for (int i = loIdx; i < hiIdx; ++i) { |
3062 |
int idx = indices[i]; |
3063 |
dest[offset++] = f.op(idx, a[idx]); |
3064 |
} |
3065 |
} |
3066 |
} |
3067 |
|
3068 |
static abstract class LOCPap<U> extends ParallelLongArrayWithMapping<U> { |
3069 |
final IntAndLongToObject<? extends U> op; |
3070 |
LOCPap(ForkJoinExecutor ex, int origin, int fence, |
3071 |
long[] array, IntAndLongToObject<? extends U> op) { |
3072 |
super(ex, origin, fence, array); |
3073 |
this.op = op; |
3074 |
} |
3075 |
|
3076 |
final boolean hasMap() { return true; } |
3077 |
final Object oget(int i) { return op.op(i, this.array[i]); } |
3078 |
final double dget(int i) { return ((Number)oget(i)).doubleValue(); } |
3079 |
final long lget(int i) { return ((Number)oget(i)).longValue(); } |
3080 |
|
3081 |
final void leafTransfer(int lo, int hi, Object[] dest, int offset) { |
3082 |
final IntAndLongToObject f = op; |
3083 |
final long[] a = this.array; |
3084 |
for (int i = lo; i < hi; ++i) |
3085 |
dest[offset++] = f.op(i, a[i]); |
3086 |
} |
3087 |
|
3088 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
3089 |
Object[] dest, int offset) { |
3090 |
final long[] a = this.array; |
3091 |
final IntAndLongToObject f = op; |
3092 |
for (int i = loIdx; i < hiIdx; ++i) { |
3093 |
int idx = indices[i]; |
3094 |
dest[offset++] = f.op(idx, a[idx]); |
3095 |
} |
3096 |
} |
3097 |
} |
3098 |
|
3099 |
// Object-combined, unfiltered |
3100 |
|
3101 |
static final class OUOCPap<T,U> extends OOCPap<T,U> { |
3102 |
OUOCPap(ForkJoinExecutor ex, int origin, int fence, |
3103 |
T[] array, IntAndObjectToObject<? super T, ? extends U> op) { |
3104 |
super(ex, origin, fence, array, op); |
3105 |
} |
3106 |
|
3107 |
public <V> ParallelArrayWithMapping<T, V> withMapping |
3108 |
(Op<? super U, ? extends V> op) { |
3109 |
return new OUOCPap<T,V>(ex, origin, fence, array, |
3110 |
compoundIndexedOp(this.op, op)); |
3111 |
} |
3112 |
|
3113 |
public ParallelArrayWithDoubleMapping<T> withMapping |
3114 |
(ObjectToDouble<? super U> op) { |
3115 |
return new OUDCPap<T>(ex, origin, fence, array, |
3116 |
compoundIndexedOp(this.op, op)); |
3117 |
} |
3118 |
|
3119 |
public ParallelArrayWithLongMapping<T> withMapping |
3120 |
(ObjectToLong<? super U> op) { |
3121 |
return new OULCPap<T>(ex, origin, fence, array, |
3122 |
compoundIndexedOp(this.op, op)); |
3123 |
} |
3124 |
|
3125 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
3126 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
3127 |
return new OUOCPap<T,V>(ex, origin, fence, array, |
3128 |
compoundIndexedOp(this.op, mapper)); |
3129 |
} |
3130 |
|
3131 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
3132 |
(IntAndObjectToDouble<? super U> mapper) { |
3133 |
return new OUDCPap<T>(ex, origin, fence, array, |
3134 |
compoundIndexedOp(this.op, mapper)); |
3135 |
} |
3136 |
|
3137 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
3138 |
(IntAndObjectToLong<? super U> mapper) { |
3139 |
return new OULCPap<T>(ex, origin, fence, array, |
3140 |
compoundIndexedOp(this.op, mapper)); |
3141 |
} |
3142 |
|
3143 |
void leafApply(int lo, int hi, Procedure procedure) { |
3144 |
final IntAndObjectToObject f = op; |
3145 |
final Object[] a = this.array; |
3146 |
for (int i = lo; i < hi; ++i) |
3147 |
procedure.op(f.op(i, a[i])); |
3148 |
} |
3149 |
|
3150 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
3151 |
if (lo >= hi) |
3152 |
return base; |
3153 |
final Object[] a = this.array; |
3154 |
final IntAndObjectToObject f = op; |
3155 |
Object r = f.op(lo, a[lo]); |
3156 |
for (int i = lo+1; i < hi; ++i) |
3157 |
r = reducer.op(r, f.op(i, a[i])); |
3158 |
return r; |
3159 |
} |
3160 |
|
3161 |
} |
3162 |
|
3163 |
static final class DUOCPap<U> extends DOCPap<U> { |
3164 |
DUOCPap(ForkJoinExecutor ex, int origin, int fence, |
3165 |
double[] array, IntAndDoubleToObject<? extends U> op) { |
3166 |
super(ex, origin, fence, array, op); |
3167 |
} |
3168 |
|
3169 |
public <V> ParallelDoubleArrayWithMapping< V> withMapping |
3170 |
(Op<? super U, ? extends V> op) { |
3171 |
return new DUOCPap<V>(ex, origin, fence, array, |
3172 |
compoundIndexedOp(this.op, op)); |
3173 |
} |
3174 |
|
3175 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
3176 |
(ObjectToDouble<? super U> op) { |
3177 |
return new DUDCPap(ex, origin, fence, array, |
3178 |
compoundIndexedOp(this.op, op)); |
3179 |
} |
3180 |
|
3181 |
public ParallelDoubleArrayWithLongMapping withMapping |
3182 |
(ObjectToLong<? super U> op) { |
3183 |
return new DULCPap(ex, origin, fence, array, |
3184 |
compoundIndexedOp(this.op, op)); |
3185 |
} |
3186 |
|
3187 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
3188 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
3189 |
return new DUOCPap<V>(ex, origin, fence, array, |
3190 |
compoundIndexedOp(this.op, mapper)); |
3191 |
} |
3192 |
|
3193 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
3194 |
(IntAndObjectToDouble<? super U> mapper) { |
3195 |
return new DUDCPap(ex, origin, fence, array, |
3196 |
compoundIndexedOp(this.op, mapper)); |
3197 |
} |
3198 |
|
3199 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
3200 |
(IntAndObjectToLong<? super U> mapper) { |
3201 |
return new DULCPap(ex, origin, fence, array, |
3202 |
compoundIndexedOp(this.op, mapper)); |
3203 |
} |
3204 |
|
3205 |
void leafApply(int lo, int hi, Procedure procedure) { |
3206 |
final IntAndDoubleToObject f = op; |
3207 |
final double[] a = this.array; |
3208 |
for (int i = lo; i < hi; ++i) |
3209 |
procedure.op(f.op(i, a[i])); |
3210 |
} |
3211 |
|
3212 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
3213 |
if (lo >= hi) |
3214 |
return base; |
3215 |
final double[] a = this.array; |
3216 |
final IntAndDoubleToObject f = op; |
3217 |
Object r = f.op(lo, a[lo]); |
3218 |
for (int i = lo+1; i < hi; ++i) |
3219 |
r = reducer.op(r, f.op(i, a[i])); |
3220 |
return r; |
3221 |
} |
3222 |
|
3223 |
} |
3224 |
|
3225 |
static final class LUOCPap<U> extends LOCPap<U> { |
3226 |
LUOCPap(ForkJoinExecutor ex, int origin, int fence, |
3227 |
long[] array, IntAndLongToObject<? extends U> op) { |
3228 |
super(ex, origin, fence, array, op); |
3229 |
} |
3230 |
|
3231 |
public <V> ParallelLongArrayWithMapping< V> withMapping |
3232 |
(Op<? super U, ? extends V> op) { |
3233 |
return new LUOCPap<V>(ex, origin, fence, array, |
3234 |
compoundIndexedOp(this.op, op)); |
3235 |
} |
3236 |
|
3237 |
public ParallelLongArrayWithDoubleMapping withMapping |
3238 |
(ObjectToDouble<? super U> op) { |
3239 |
return new LUDCPap(ex, origin, fence, array, |
3240 |
compoundIndexedOp(this.op, op)); |
3241 |
} |
3242 |
|
3243 |
public ParallelLongArrayWithLongMapping withMapping |
3244 |
(ObjectToLong<? super U> op) { |
3245 |
return new LULCPap(ex, origin, fence, array, |
3246 |
compoundIndexedOp(this.op, op)); |
3247 |
} |
3248 |
|
3249 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
3250 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
3251 |
return new LUOCPap<V>(ex, origin, fence, array, |
3252 |
compoundIndexedOp(this.op, mapper)); |
3253 |
} |
3254 |
|
3255 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
3256 |
(IntAndObjectToDouble<? super U> mapper) { |
3257 |
return new LUDCPap(ex, origin, fence, array, |
3258 |
compoundIndexedOp(this.op, mapper)); |
3259 |
} |
3260 |
|
3261 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
3262 |
(IntAndObjectToLong<? super U> mapper) { |
3263 |
return new LULCPap(ex, origin, fence, array, |
3264 |
compoundIndexedOp(this.op, mapper)); |
3265 |
} |
3266 |
|
3267 |
void leafApply(int lo, int hi, Procedure procedure) { |
3268 |
final IntAndLongToObject f = op; |
3269 |
final long[] a = this.array; |
3270 |
for (int i = lo; i < hi; ++i) |
3271 |
procedure.op(f.op(i, a[i])); |
3272 |
} |
3273 |
|
3274 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
3275 |
if (lo >= hi) |
3276 |
return base; |
3277 |
final long[] a = this.array; |
3278 |
final IntAndLongToObject f = op; |
3279 |
Object r = f.op(lo, a[lo]); |
3280 |
for (int i = lo+1; i < hi; ++i) |
3281 |
r = reducer.op(r, f.op(i, a[i])); |
3282 |
return r; |
3283 |
} |
3284 |
|
3285 |
} |
3286 |
|
3287 |
// object-combined filtered |
3288 |
|
3289 |
static final class OFOCPap<T,U> extends OOCPap<T,U> { |
3290 |
final Predicate<? super T> selector; |
3291 |
OFOCPap(ForkJoinExecutor ex, int origin, int fence, |
3292 |
T[] array, Predicate<? super T> selector, |
3293 |
IntAndObjectToObject<? super T, ? extends U> op) { |
3294 |
super(ex, origin, fence, array, op); |
3295 |
this.selector = selector; |
3296 |
} |
3297 |
|
3298 |
boolean hasFilter() { return true; } |
3299 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
3300 |
|
3301 |
public <V> ParallelArrayWithMapping<T, V> withMapping |
3302 |
(Op<? super U, ? extends V> op) { |
3303 |
return new OFOCPap<T,V>(ex, origin, fence, array, selector, |
3304 |
compoundIndexedOp(this.op, op)); |
3305 |
} |
3306 |
|
3307 |
public ParallelArrayWithDoubleMapping<T> withMapping |
3308 |
(ObjectToDouble<? super U> op) { |
3309 |
return new OFDCPap<T>(ex, origin, fence, array, selector, |
3310 |
compoundIndexedOp(this.op, op)); |
3311 |
} |
3312 |
|
3313 |
public ParallelArrayWithLongMapping<T> withMapping |
3314 |
(ObjectToLong<? super U> op) { |
3315 |
return new OFLCPap<T>(ex, origin, fence, array, selector, |
3316 |
compoundIndexedOp(this.op, op)); |
3317 |
} |
3318 |
|
3319 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
3320 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
3321 |
return new OFOCPap<T,V>(ex, origin, fence, array, selector, |
3322 |
compoundIndexedOp(this.op, mapper)); |
3323 |
} |
3324 |
|
3325 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
3326 |
(IntAndObjectToDouble<? super U> mapper) { |
3327 |
return new OFDCPap<T>(ex, origin, fence, array, selector, |
3328 |
compoundIndexedOp(this.op, mapper)); |
3329 |
} |
3330 |
|
3331 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
3332 |
(IntAndObjectToLong<? super U> mapper) { |
3333 |
return new OFLCPap<T> |
3334 |
(ex, origin, fence, array, selector, |
3335 |
compoundIndexedOp |
3336 |
(this.op, mapper)); |
3337 |
} |
3338 |
|
3339 |
void leafApply(int lo, int hi, Procedure procedure) { |
3340 |
final Predicate s = selector; |
3341 |
final Object[] a = this.array; |
3342 |
final IntAndObjectToObject f = op; |
3343 |
for (int i = lo; i < hi; ++i) { |
3344 |
Object x = a[i]; |
3345 |
if (s.op(x)) |
3346 |
procedure.op(f.op(i, x)); |
3347 |
} |
3348 |
} |
3349 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
3350 |
final Predicate s = selector; |
3351 |
final Object[] a = this.array; |
3352 |
final IntAndObjectToObject f = op; |
3353 |
boolean gotFirst = false; |
3354 |
Object r = base; |
3355 |
for (int i = lo; i < hi; ++i) { |
3356 |
Object x = a[i]; |
3357 |
if (s.op(x)) { |
3358 |
Object y = f.op(i, x); |
3359 |
if (!gotFirst) { |
3360 |
gotFirst = true; |
3361 |
r = y; |
3362 |
} |
3363 |
else |
3364 |
r = reducer.op(r, y); |
3365 |
} |
3366 |
} |
3367 |
return r; |
3368 |
} |
3369 |
} |
3370 |
|
3371 |
static final class DFOCPap<U> extends DOCPap<U> { |
3372 |
final DoublePredicate selector; |
3373 |
DFOCPap(ForkJoinExecutor ex, int origin, int fence, |
3374 |
double[] array, DoublePredicate selector, |
3375 |
IntAndDoubleToObject<? extends U> op) { |
3376 |
super(ex, origin, fence, array, op); |
3377 |
this.selector = selector; |
3378 |
} |
3379 |
|
3380 |
boolean hasFilter() { return true; } |
3381 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
3382 |
|
3383 |
public <V> ParallelDoubleArrayWithMapping< V> withMapping |
3384 |
(Op<? super U, ? extends V> op) { |
3385 |
return new DFOCPap<V>(ex, origin, fence, array, selector, |
3386 |
compoundIndexedOp(this.op, op)); |
3387 |
} |
3388 |
|
3389 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
3390 |
(ObjectToDouble<? super U> op) { |
3391 |
return new DFDCPap(ex, origin, fence, array, selector, |
3392 |
compoundIndexedOp(this.op, op)); |
3393 |
} |
3394 |
|
3395 |
public ParallelDoubleArrayWithLongMapping withMapping |
3396 |
(ObjectToLong<? super U> op) { |
3397 |
return new DFLCPap(ex, origin, fence, array, selector, |
3398 |
compoundIndexedOp(this.op, op)); |
3399 |
} |
3400 |
|
3401 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
3402 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
3403 |
return new DFOCPap<V>(ex, origin, fence, array, selector, |
3404 |
compoundIndexedOp(this.op, mapper)); |
3405 |
} |
3406 |
|
3407 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
3408 |
(IntAndObjectToDouble<? super U> mapper) { |
3409 |
return new DFDCPap(ex, origin, fence, array, selector, |
3410 |
compoundIndexedOp(this.op, mapper)); |
3411 |
} |
3412 |
|
3413 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
3414 |
(IntAndObjectToLong<? super U> mapper) { |
3415 |
return new DFLCPap(ex, origin, fence, array, selector, |
3416 |
compoundIndexedOp(this.op, mapper)); |
3417 |
} |
3418 |
|
3419 |
void leafApply(int lo, int hi, Procedure procedure) { |
3420 |
final DoublePredicate s = selector; |
3421 |
final double[] a = this.array; |
3422 |
final IntAndDoubleToObject f = op; |
3423 |
for (int i = lo; i < hi; ++i) { |
3424 |
double x = a[i]; |
3425 |
if (s.op(x)) |
3426 |
procedure.op(f.op(i, x)); |
3427 |
} |
3428 |
} |
3429 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
3430 |
final DoublePredicate s = selector; |
3431 |
final double[] a = this.array; |
3432 |
final IntAndDoubleToObject f = op; |
3433 |
boolean gotFirst = false; |
3434 |
Object r = base; |
3435 |
for (int i = lo; i < hi; ++i) { |
3436 |
double x = a[i]; |
3437 |
if (s.op(x)) { |
3438 |
Object y = f.op(i, x); |
3439 |
if (!gotFirst) { |
3440 |
gotFirst = true; |
3441 |
r = y; |
3442 |
} |
3443 |
else |
3444 |
r = reducer.op(r, y); |
3445 |
} |
3446 |
} |
3447 |
return r; |
3448 |
} |
3449 |
} |
3450 |
|
3451 |
static final class LFOCPap<U> extends LOCPap<U> { |
3452 |
final LongPredicate selector; |
3453 |
LFOCPap(ForkJoinExecutor ex, int origin, int fence, |
3454 |
long[] array, LongPredicate selector, |
3455 |
IntAndLongToObject<? extends U> op) { |
3456 |
super(ex, origin, fence, array, op); |
3457 |
this.selector = selector; |
3458 |
} |
3459 |
|
3460 |
boolean hasFilter() { return true; } |
3461 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
3462 |
|
3463 |
public <V> ParallelLongArrayWithMapping< V> withMapping |
3464 |
(Op<? super U, ? extends V> op) { |
3465 |
return new LFOCPap<V>(ex, origin, fence, array, selector, |
3466 |
compoundIndexedOp(this.op, op)); |
3467 |
} |
3468 |
|
3469 |
public ParallelLongArrayWithDoubleMapping withMapping |
3470 |
(ObjectToDouble<? super U> op) { |
3471 |
return new LFDCPap(ex, origin, fence, array, selector, |
3472 |
compoundIndexedOp(this.op, op)); |
3473 |
} |
3474 |
|
3475 |
public ParallelLongArrayWithLongMapping withMapping |
3476 |
(ObjectToLong<? super U> op) { |
3477 |
return new LFLCPap(ex, origin, fence, array, selector, |
3478 |
compoundIndexedOp(this.op, op)); |
3479 |
} |
3480 |
|
3481 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
3482 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
3483 |
return new LFOCPap<V>(ex, origin, fence, array, selector, |
3484 |
compoundIndexedOp(this.op, mapper)); |
3485 |
} |
3486 |
|
3487 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
3488 |
(IntAndObjectToDouble<? super U> mapper) { |
3489 |
return new LFDCPap(ex, origin, fence, array, selector, |
3490 |
compoundIndexedOp(this.op, mapper)); |
3491 |
} |
3492 |
|
3493 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
3494 |
(IntAndObjectToLong<? super U> mapper) { |
3495 |
return new LFLCPap(ex, origin, fence, array, selector, |
3496 |
compoundIndexedOp(this.op, mapper)); |
3497 |
} |
3498 |
|
3499 |
void leafApply(int lo, int hi, Procedure procedure) { |
3500 |
final LongPredicate s = selector; |
3501 |
final long[] a = this.array; |
3502 |
final IntAndLongToObject f = op; |
3503 |
for (int i = lo; i < hi; ++i) { |
3504 |
long x = a[i]; |
3505 |
if (s.op(x)) |
3506 |
procedure.op(f.op(i, x)); |
3507 |
} |
3508 |
} |
3509 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
3510 |
final LongPredicate s = selector; |
3511 |
final long[] a = this.array; |
3512 |
final IntAndLongToObject f = op; |
3513 |
boolean gotFirst = false; |
3514 |
Object r = base; |
3515 |
for (int i = lo; i < hi; ++i) { |
3516 |
long x = a[i]; |
3517 |
if (s.op(x)) { |
3518 |
Object y = f.op(i, x); |
3519 |
if (!gotFirst) { |
3520 |
gotFirst = true; |
3521 |
r = y; |
3522 |
} |
3523 |
else |
3524 |
r = reducer.op(r, y); |
3525 |
} |
3526 |
} |
3527 |
return r; |
3528 |
} |
3529 |
} |
3530 |
|
3531 |
// Object-combined, relational |
3532 |
static final class OROCPap<T,U> extends OOCPap<T,U> { |
3533 |
final IntAndObjectPredicate<? super T> selector; |
3534 |
OROCPap(ForkJoinExecutor ex, int origin, int fence, |
3535 |
T[] array, IntAndObjectPredicate<? super T> selector, |
3536 |
IntAndObjectToObject<? super T, ? extends U> op) { |
3537 |
super(ex, origin, fence, array, op); |
3538 |
this.selector = selector; |
3539 |
} |
3540 |
|
3541 |
boolean hasFilter() { return true; } |
3542 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
3543 |
|
3544 |
public <V> ParallelArrayWithMapping<T, V> withMapping |
3545 |
(Op<? super U, ? extends V> op) { |
3546 |
return new OROCPap<T,V>(ex, origin, fence, array, selector, |
3547 |
compoundIndexedOp(this.op, op)); |
3548 |
} |
3549 |
|
3550 |
public ParallelArrayWithDoubleMapping<T> withMapping |
3551 |
(ObjectToDouble<? super U> op) { |
3552 |
return new ORDCPap<T>(ex, origin, fence, array, selector, |
3553 |
compoundIndexedOp(this.op, op)); |
3554 |
} |
3555 |
|
3556 |
public ParallelArrayWithLongMapping<T> withMapping |
3557 |
(ObjectToLong<? super U> op) { |
3558 |
return new ORLCPap<T>(ex, origin, fence, array, selector, |
3559 |
compoundIndexedOp(this.op, op)); |
3560 |
} |
3561 |
|
3562 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
3563 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
3564 |
return new OROCPap<T,V>(ex, origin, fence, array, selector, |
3565 |
compoundIndexedOp(this.op, mapper)); |
3566 |
} |
3567 |
|
3568 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
3569 |
(IntAndObjectToDouble<? super U> mapper) { |
3570 |
return new ORDCPap<T>(ex, origin, fence, array, selector, |
3571 |
compoundIndexedOp(this.op, mapper)); |
3572 |
} |
3573 |
|
3574 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
3575 |
(IntAndObjectToLong<? super U> mapper) { |
3576 |
return new ORLCPap<T> |
3577 |
(ex, origin, fence, array, selector, |
3578 |
compoundIndexedOp |
3579 |
(this.op, mapper)); |
3580 |
} |
3581 |
|
3582 |
void leafApply(int lo, int hi, Procedure procedure) { |
3583 |
final IntAndObjectPredicate s = selector; |
3584 |
final Object[] a = this.array; |
3585 |
final IntAndObjectToObject f = op; |
3586 |
for (int i = lo; i < hi; ++i) { |
3587 |
Object x = a[i]; |
3588 |
if (s.op(i, x)) |
3589 |
procedure.op(f.op(i, x)); |
3590 |
} |
3591 |
} |
3592 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
3593 |
final IntAndObjectPredicate s = selector; |
3594 |
final Object[] a = this.array; |
3595 |
final IntAndObjectToObject f = op; |
3596 |
boolean gotFirst = false; |
3597 |
Object r = base; |
3598 |
for (int i = lo; i < hi; ++i) { |
3599 |
Object x = a[i]; |
3600 |
if (s.op(i, x)) { |
3601 |
Object y = f.op(i, x); |
3602 |
if (!gotFirst) { |
3603 |
gotFirst = true; |
3604 |
r = y; |
3605 |
} |
3606 |
else |
3607 |
r = reducer.op(r, y); |
3608 |
} |
3609 |
} |
3610 |
return r; |
3611 |
} |
3612 |
} |
3613 |
|
3614 |
static final class DROCPap<U> extends DOCPap<U> { |
3615 |
final IntAndDoublePredicate selector; |
3616 |
DROCPap(ForkJoinExecutor ex, int origin, int fence, |
3617 |
double[] array, IntAndDoublePredicate selector, |
3618 |
IntAndDoubleToObject<? extends U> op) { |
3619 |
super(ex, origin, fence, array, op); |
3620 |
this.selector = selector; |
3621 |
} |
3622 |
|
3623 |
boolean hasFilter() { return true; } |
3624 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
3625 |
|
3626 |
public <V> ParallelDoubleArrayWithMapping< V> withMapping |
3627 |
(Op<? super U, ? extends V> op) { |
3628 |
return new DROCPap<V>(ex, origin, fence, array, selector, |
3629 |
compoundIndexedOp(this.op, op)); |
3630 |
} |
3631 |
|
3632 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
3633 |
(ObjectToDouble<? super U> op) { |
3634 |
return new DRDCPap(ex, origin, fence, array, selector, |
3635 |
compoundIndexedOp(this.op, op)); |
3636 |
} |
3637 |
|
3638 |
public ParallelDoubleArrayWithLongMapping withMapping |
3639 |
(ObjectToLong<? super U> op) { |
3640 |
return new DRLCPap(ex, origin, fence, array, selector, |
3641 |
compoundIndexedOp(this.op, op)); |
3642 |
} |
3643 |
|
3644 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
3645 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
3646 |
return new DROCPap<V>(ex, origin, fence, array, selector, |
3647 |
compoundIndexedOp(this.op, mapper)); |
3648 |
} |
3649 |
|
3650 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
3651 |
(IntAndObjectToDouble<? super U> mapper) { |
3652 |
return new DRDCPap(ex, origin, fence, array, selector, |
3653 |
compoundIndexedOp(this.op, mapper)); |
3654 |
} |
3655 |
|
3656 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
3657 |
(IntAndObjectToLong<? super U> mapper) { |
3658 |
return new DRLCPap(ex, origin, fence, array, selector, |
3659 |
compoundIndexedOp(this.op, mapper)); |
3660 |
} |
3661 |
|
3662 |
void leafApply(int lo, int hi, Procedure procedure) { |
3663 |
final IntAndDoublePredicate s = selector; |
3664 |
final double[] a = this.array; |
3665 |
final IntAndDoubleToObject f = op; |
3666 |
for (int i = lo; i < hi; ++i) { |
3667 |
double x = a[i]; |
3668 |
if (s.op(i, x)) |
3669 |
procedure.op(f.op(i, x)); |
3670 |
} |
3671 |
} |
3672 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
3673 |
final IntAndDoublePredicate s = selector; |
3674 |
final double[] a = this.array; |
3675 |
final IntAndDoubleToObject f = op; |
3676 |
boolean gotFirst = false; |
3677 |
Object r = base; |
3678 |
for (int i = lo; i < hi; ++i) { |
3679 |
double x = a[i]; |
3680 |
if (s.op(i, x)) { |
3681 |
Object y = f.op(i, x); |
3682 |
if (!gotFirst) { |
3683 |
gotFirst = true; |
3684 |
r = y; |
3685 |
} |
3686 |
else |
3687 |
r = reducer.op(r, y); |
3688 |
} |
3689 |
} |
3690 |
return r; |
3691 |
} |
3692 |
} |
3693 |
|
3694 |
static final class LROCPap<U> extends LOCPap<U> { |
3695 |
final IntAndLongPredicate selector; |
3696 |
LROCPap(ForkJoinExecutor ex, int origin, int fence, |
3697 |
long[] array, IntAndLongPredicate selector, |
3698 |
IntAndLongToObject<? extends U> op) { |
3699 |
super(ex, origin, fence, array, op); |
3700 |
this.selector = selector; |
3701 |
} |
3702 |
|
3703 |
boolean hasFilter() { return true; } |
3704 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
3705 |
|
3706 |
public <V> ParallelLongArrayWithMapping< V> withMapping |
3707 |
(Op<? super U, ? extends V> op) { |
3708 |
return new LROCPap<V>(ex, origin, fence, array, selector, |
3709 |
compoundIndexedOp(this.op, op)); |
3710 |
} |
3711 |
|
3712 |
public ParallelLongArrayWithDoubleMapping withMapping |
3713 |
(ObjectToDouble<? super U> op) { |
3714 |
return new LRDCPap(ex, origin, fence, array, selector, |
3715 |
compoundIndexedOp(this.op, op)); |
3716 |
} |
3717 |
|
3718 |
public ParallelLongArrayWithLongMapping withMapping |
3719 |
(ObjectToLong<? super U> op) { |
3720 |
return new LRLCPap(ex, origin, fence, array, selector, |
3721 |
compoundIndexedOp(this.op, op)); |
3722 |
} |
3723 |
|
3724 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
3725 |
(IntAndObjectToObject<? super U, ? extends V> mapper) { |
3726 |
return new LROCPap<V>(ex, origin, fence, array, selector, |
3727 |
compoundIndexedOp(this.op, mapper)); |
3728 |
} |
3729 |
|
3730 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
3731 |
(IntAndObjectToDouble<? super U> mapper) { |
3732 |
return new LRDCPap(ex, origin, fence, array, selector, |
3733 |
compoundIndexedOp(this.op, mapper)); |
3734 |
} |
3735 |
|
3736 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
3737 |
(IntAndObjectToLong<? super U> mapper) { |
3738 |
return new LRLCPap(ex, origin, fence, array, selector, |
3739 |
compoundIndexedOp(this.op, mapper)); |
3740 |
} |
3741 |
|
3742 |
void leafApply(int lo, int hi, Procedure procedure) { |
3743 |
final IntAndLongPredicate s = selector; |
3744 |
final long[] a = this.array; |
3745 |
final IntAndLongToObject f = op; |
3746 |
for (int i = lo; i < hi; ++i) { |
3747 |
long x = a[i]; |
3748 |
if (s.op(i, x)) |
3749 |
procedure.op(f.op(i, x)); |
3750 |
} |
3751 |
} |
3752 |
Object leafReduce(int lo, int hi, Reducer reducer, Object base) { |
3753 |
final IntAndLongPredicate s = selector; |
3754 |
final long[] a = this.array; |
3755 |
final IntAndLongToObject f = op; |
3756 |
boolean gotFirst = false; |
3757 |
Object r = base; |
3758 |
for (int i = lo; i < hi; ++i) { |
3759 |
long x = a[i]; |
3760 |
if (s.op(i, x)) { |
3761 |
Object y = f.op(i, x); |
3762 |
if (!gotFirst) { |
3763 |
gotFirst = true; |
3764 |
r = y; |
3765 |
} |
3766 |
else |
3767 |
r = reducer.op(r, y); |
3768 |
} |
3769 |
} |
3770 |
return r; |
3771 |
} |
3772 |
} |
3773 |
|
3774 |
// Double-mapped |
3775 |
|
3776 |
static abstract class ODMPap<T> extends ParallelArrayWithDoubleMapping<T> { |
3777 |
final ObjectToDouble<? super T> op; |
3778 |
ODMPap(ForkJoinExecutor ex, int origin, int fence, |
3779 |
T[] array, ObjectToDouble<? super T> op) { |
3780 |
super(ex, origin, fence, array); |
3781 |
this.op = op; |
3782 |
} |
3783 |
|
3784 |
final boolean hasMap() { return true; } |
3785 |
final double dget(int i) { return op.op(this.array[i]); } |
3786 |
final Object oget(int i) { return Double.valueOf(dget(i)); } |
3787 |
final long lget(int i) { return (long)(dget(i)); } |
3788 |
|
3789 |
final void leafTransfer(int lo, int hi, double[] dest, int offset) { |
3790 |
final ObjectToDouble f = op; |
3791 |
final Object[] a = this.array; |
3792 |
for (int i = lo; i < hi; ++i) |
3793 |
dest[offset++] = f.op(a[i]); |
3794 |
} |
3795 |
|
3796 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
3797 |
double[] dest, int offset) { |
3798 |
final Object[] a = this.array; |
3799 |
final ObjectToDouble f = op; |
3800 |
for (int i = loIdx; i < hiIdx; ++i) |
3801 |
dest[offset++] = f.op(a[indices[i]]); |
3802 |
} |
3803 |
|
3804 |
} |
3805 |
|
3806 |
static abstract class DDMPap extends ParallelDoubleArrayWithDoubleMapping { |
3807 |
final DoubleOp op; |
3808 |
DDMPap |
3809 |
(ForkJoinExecutor ex, int origin, int fence, |
3810 |
double[] array, DoubleOp op) { |
3811 |
super(ex, origin, fence, array); |
3812 |
this.op = op; |
3813 |
} |
3814 |
|
3815 |
final boolean hasMap() { return true; } |
3816 |
final double dget(int i) { return op.op(this.array[i]); } |
3817 |
final Object oget(int i) { return Double.valueOf(dget(i)); } |
3818 |
final long lget(int i) { return (long)(dget(i)); } |
3819 |
|
3820 |
final void leafTransfer(int lo, int hi, double[] dest, int offset) { |
3821 |
final double[] a = this.array; |
3822 |
final DoubleOp f = op; |
3823 |
for (int i = lo; i < hi; ++i) |
3824 |
dest[offset++] = f.op(a[i]); |
3825 |
} |
3826 |
|
3827 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
3828 |
double[] dest, int offset) { |
3829 |
final double[] a = this.array; |
3830 |
final DoubleOp f = op; |
3831 |
for (int i = loIdx; i < hiIdx; ++i) |
3832 |
dest[offset++] = f.op(a[indices[i]]); |
3833 |
} |
3834 |
} |
3835 |
|
3836 |
static abstract class LDMPap extends ParallelLongArrayWithDoubleMapping { |
3837 |
final LongToDouble op; |
3838 |
LDMPap(ForkJoinExecutor ex, int origin, int fence, |
3839 |
long[] array, LongToDouble op) { |
3840 |
super(ex, origin, fence, array); |
3841 |
this.op = op; |
3842 |
} |
3843 |
|
3844 |
final boolean hasMap() { return true; } |
3845 |
final double dget(int i) { return op.op(this.array[i]); } |
3846 |
final Object oget(int i) { return Double.valueOf(dget(i)); } |
3847 |
final long lget(int i) { return (long)(dget(i)); } |
3848 |
|
3849 |
final void leafTransfer(int lo, int hi, double[] dest, int offset) { |
3850 |
final long[] a = this.array; |
3851 |
final LongToDouble f = op; |
3852 |
for (int i = lo; i < hi; ++i) |
3853 |
dest[offset++] = f.op(a[i]); |
3854 |
} |
3855 |
|
3856 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
3857 |
double[] dest, int offset) { |
3858 |
final long[] a = this.array; |
3859 |
final LongToDouble f = op; |
3860 |
for (int i = loIdx; i < hiIdx; ++i) |
3861 |
dest[offset++] = f.op(a[indices[i]]); |
3862 |
} |
3863 |
|
3864 |
} |
3865 |
|
3866 |
// double-mapped, unfiltered |
3867 |
|
3868 |
static final class OUDMPap<T> extends ODMPap<T> { |
3869 |
OUDMPap(ForkJoinExecutor ex, int origin, int fence, |
3870 |
T[] array, ObjectToDouble<? super T> op) { |
3871 |
super(ex, origin, fence, array, op); |
3872 |
} |
3873 |
|
3874 |
public ParallelArrayWithDoubleMapping<T> withMapping(DoubleOp op) { |
3875 |
return new OUDMPap<T>(ex, origin, fence, array, |
3876 |
CommonOps.compoundOp(this.op, op)); |
3877 |
} |
3878 |
|
3879 |
public ParallelArrayWithLongMapping<T> withMapping(DoubleToLong op) { |
3880 |
return new OULMPap<T>(ex, origin, fence, array, |
3881 |
CommonOps.compoundOp(this.op, op)); |
3882 |
} |
3883 |
|
3884 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
3885 |
(DoubleToObject<? extends U> op) { |
3886 |
return new OUOMPap<T,U>(ex, origin, fence, array, |
3887 |
CommonOps.compoundOp(this.op, op)); |
3888 |
} |
3889 |
|
3890 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
3891 |
(IntAndDoubleToObject<? extends V> mapper) { |
3892 |
return new OUOCPap<T,V>(ex, origin, fence, array, |
3893 |
compoundIndexedOp(this.op, mapper)); |
3894 |
} |
3895 |
|
3896 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
3897 |
(IntAndDoubleToDouble mapper) { |
3898 |
return new OUDCPap<T>(ex, origin, fence, array, |
3899 |
compoundIndexedOp(this.op, mapper)); |
3900 |
} |
3901 |
|
3902 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
3903 |
(IntAndDoubleToLong mapper) { |
3904 |
return new OULCPap<T>(ex, origin, fence, array, |
3905 |
compoundIndexedOp(this.op, mapper)); |
3906 |
} |
3907 |
|
3908 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
3909 |
final ObjectToDouble f = op; |
3910 |
final Object[] a = this.array; |
3911 |
for (int i = lo; i < hi; ++i) |
3912 |
procedure.op(f.op(a[i])); |
3913 |
} |
3914 |
|
3915 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
3916 |
if (lo >= hi) |
3917 |
return base; |
3918 |
final Object[] a = this.array; |
3919 |
final ObjectToDouble f = op; |
3920 |
double r = f.op(a[lo]); |
3921 |
for (int i = lo+1; i < hi; ++i) |
3922 |
r = reducer.op(r, f.op(a[i])); |
3923 |
return r; |
3924 |
} |
3925 |
|
3926 |
} |
3927 |
|
3928 |
static final class DUDMPap extends DDMPap { |
3929 |
DUDMPap(ForkJoinExecutor ex, int origin, int fence, |
3930 |
double[] array, DoubleOp op) { |
3931 |
super(ex, origin, fence, array, op); |
3932 |
} |
3933 |
|
3934 |
public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { |
3935 |
return new DUDMPap(ex, origin, fence, array, |
3936 |
CommonOps.compoundOp(this.op, op)); |
3937 |
} |
3938 |
|
3939 |
public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { |
3940 |
return new DULMPap(ex, origin, fence, array, |
3941 |
CommonOps.compoundOp(this.op, op)); |
3942 |
} |
3943 |
|
3944 |
public <U> ParallelDoubleArrayWithMapping<U> withMapping |
3945 |
(DoubleToObject<? extends U> op) { |
3946 |
return new DUOMPap<U>(ex, origin, fence, array, |
3947 |
CommonOps.compoundOp(this.op, op)); |
3948 |
} |
3949 |
|
3950 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
3951 |
(IntAndDoubleToObject<? extends V> mapper) { |
3952 |
return new DUOCPap<V>(ex, origin, fence, array, |
3953 |
compoundIndexedOp(this.op, mapper)); |
3954 |
} |
3955 |
|
3956 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
3957 |
(IntAndDoubleToDouble mapper) { |
3958 |
return new DUDCPap(ex, origin, fence, array, |
3959 |
compoundIndexedOp(this.op, mapper)); |
3960 |
} |
3961 |
|
3962 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
3963 |
(IntAndDoubleToLong mapper) { |
3964 |
return new DULCPap(ex, origin, fence, array, |
3965 |
compoundIndexedOp(this.op, mapper)); |
3966 |
} |
3967 |
|
3968 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
3969 |
final double[] a = this.array; |
3970 |
final DoubleOp f = op; |
3971 |
for (int i = lo; i < hi; ++i) |
3972 |
procedure.op(f.op(a[i])); |
3973 |
} |
3974 |
|
3975 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
3976 |
if (lo >= hi) |
3977 |
return base; |
3978 |
final double[] a = this.array; |
3979 |
final DoubleOp f = op; |
3980 |
double r = f.op(a[lo]); |
3981 |
for (int i = lo+1; i < hi; ++i) |
3982 |
r = reducer.op(r, f.op(a[i])); |
3983 |
return r; |
3984 |
} |
3985 |
|
3986 |
} |
3987 |
|
3988 |
static final class LUDMPap extends LDMPap { |
3989 |
LUDMPap(ForkJoinExecutor ex, int origin, int fence, |
3990 |
long[] array, LongToDouble op) { |
3991 |
super(ex, origin, fence, array, op); |
3992 |
} |
3993 |
|
3994 |
public ParallelLongArrayWithLongMapping withMapping(DoubleToLong op) { |
3995 |
return new LULMPap(ex, origin, fence, array, |
3996 |
CommonOps.compoundOp(this.op, op)); |
3997 |
} |
3998 |
|
3999 |
public ParallelLongArrayWithDoubleMapping withMapping(DoubleOp op) { |
4000 |
return new LUDMPap(ex, origin, fence, array, |
4001 |
CommonOps.compoundOp(this.op, op)); |
4002 |
} |
4003 |
|
4004 |
public <U> ParallelLongArrayWithMapping<U> withMapping |
4005 |
(DoubleToObject<? extends U> op) { |
4006 |
return new LUOMPap<U>(ex, origin, fence, array, |
4007 |
CommonOps.compoundOp(this.op, op)); |
4008 |
} |
4009 |
|
4010 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
4011 |
(IntAndDoubleToObject<? extends V> mapper) { |
4012 |
return new LUOCPap<V>(ex, origin, fence, array, |
4013 |
compoundIndexedOp(this.op, mapper)); |
4014 |
} |
4015 |
|
4016 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
4017 |
(IntAndDoubleToDouble mapper) { |
4018 |
return new LUDCPap(ex, origin, fence, array, |
4019 |
compoundIndexedOp(this.op, mapper)); |
4020 |
} |
4021 |
|
4022 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
4023 |
(IntAndDoubleToLong mapper) { |
4024 |
return new LULCPap(ex, origin, fence, array, |
4025 |
compoundIndexedOp(this.op, mapper)); |
4026 |
} |
4027 |
|
4028 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4029 |
final LongToDouble f = op; |
4030 |
final long[] a = this.array; |
4031 |
for (int i = lo; i < hi; ++i) |
4032 |
procedure.op(f.op(a[i])); |
4033 |
} |
4034 |
|
4035 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4036 |
if (lo >= hi) |
4037 |
return base; |
4038 |
final long[] a = this.array; |
4039 |
final LongToDouble f = op; |
4040 |
double r = f.op(a[lo]); |
4041 |
for (int i = lo+1; i < hi; ++i) |
4042 |
r = reducer.op(r, f.op(a[i])); |
4043 |
return r; |
4044 |
} |
4045 |
|
4046 |
} |
4047 |
|
4048 |
// double-mapped, filtered |
4049 |
|
4050 |
static final class OFDMPap<T> extends ODMPap<T> { |
4051 |
final Predicate<? super T> selector; |
4052 |
OFDMPap(ForkJoinExecutor ex, int origin, int fence, |
4053 |
T[] array, Predicate<? super T> selector, |
4054 |
ObjectToDouble<? super T> op) { |
4055 |
super(ex, origin, fence, array, op); |
4056 |
this.selector = selector; |
4057 |
} |
4058 |
|
4059 |
boolean hasFilter() { return true; } |
4060 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
4061 |
|
4062 |
public ParallelArrayWithDoubleMapping<T> withMapping(DoubleOp op) { |
4063 |
return new OFDMPap<T>(ex, origin, fence, array, selector, |
4064 |
CommonOps.compoundOp(this.op, op)); |
4065 |
} |
4066 |
|
4067 |
public ParallelArrayWithLongMapping<T> withMapping(DoubleToLong op) { |
4068 |
return new OFLMPap<T>(ex, origin, fence, array, selector, |
4069 |
CommonOps.compoundOp(this.op, op)); |
4070 |
} |
4071 |
|
4072 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
4073 |
(DoubleToObject<? extends U> op) { |
4074 |
return new OFOMPap<T,U>(ex, origin, fence, array, selector, |
4075 |
CommonOps.compoundOp(this.op, op)); |
4076 |
} |
4077 |
|
4078 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
4079 |
(IntAndDoubleToObject<? extends V> mapper) { |
4080 |
return new OFOCPap<T,V>(ex, origin, fence, array, selector, |
4081 |
compoundIndexedOp(this.op, mapper)); |
4082 |
} |
4083 |
|
4084 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
4085 |
(IntAndDoubleToDouble mapper) { |
4086 |
return new OFDCPap<T>(ex, origin, fence, array, selector, |
4087 |
compoundIndexedOp(this.op, mapper)); |
4088 |
} |
4089 |
|
4090 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
4091 |
(IntAndDoubleToLong mapper) { |
4092 |
return new OFLCPap<T>(ex, origin, fence, array, selector, |
4093 |
compoundIndexedOp(this.op, mapper)); |
4094 |
} |
4095 |
|
4096 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4097 |
final Predicate s = selector; |
4098 |
final Object[] a = this.array; |
4099 |
final ObjectToDouble f = op; |
4100 |
for (int i = lo; i < hi; ++i) { |
4101 |
Object x = a[i]; |
4102 |
if (s.op(x)) |
4103 |
procedure.op(f.op(x)); |
4104 |
} |
4105 |
} |
4106 |
|
4107 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4108 |
final Predicate s = selector; |
4109 |
final ObjectToDouble f = op; |
4110 |
boolean gotFirst = false; |
4111 |
double r = base; |
4112 |
final Object[] a = this.array; |
4113 |
for (int i = lo; i < hi; ++i) { |
4114 |
Object t = a[i]; |
4115 |
if (s.op(t)) { |
4116 |
double y = f.op(t); |
4117 |
if (!gotFirst) { |
4118 |
gotFirst = true; |
4119 |
r = y; |
4120 |
} |
4121 |
else |
4122 |
r = reducer.op(r, y); |
4123 |
} |
4124 |
} |
4125 |
return r; |
4126 |
} |
4127 |
} |
4128 |
|
4129 |
static final class DFDMPap extends DDMPap { |
4130 |
final DoublePredicate selector; |
4131 |
DFDMPap(ForkJoinExecutor ex, int origin, int fence, |
4132 |
double[] array, DoublePredicate selector, DoubleOp op) { |
4133 |
super(ex, origin, fence, array, op); |
4134 |
this.selector = selector; |
4135 |
} |
4136 |
|
4137 |
boolean hasFilter() { return true; } |
4138 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
4139 |
|
4140 |
public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { |
4141 |
return new DFDMPap(ex, origin, fence, array, selector, |
4142 |
CommonOps.compoundOp(this.op, op)); |
4143 |
} |
4144 |
|
4145 |
public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { |
4146 |
return new DFLMPap(ex, origin, fence, array, selector, |
4147 |
CommonOps.compoundOp(this.op, op)); |
4148 |
} |
4149 |
|
4150 |
public <U> ParallelDoubleArrayWithMapping<U> withMapping |
4151 |
(DoubleToObject<? extends U> op) { |
4152 |
return new DFOMPap<U>(ex, origin, fence, array, selector, |
4153 |
CommonOps.compoundOp(this.op, op)); |
4154 |
} |
4155 |
|
4156 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
4157 |
(IntAndDoubleToObject<? extends V> mapper) { |
4158 |
return new DFOCPap<V>(ex, origin, fence, array, selector, |
4159 |
compoundIndexedOp(this.op, mapper)); |
4160 |
} |
4161 |
|
4162 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
4163 |
(IntAndDoubleToDouble mapper) { |
4164 |
return new DFDCPap(ex, origin, fence, array, selector, |
4165 |
compoundIndexedOp(this.op, mapper)); |
4166 |
} |
4167 |
|
4168 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
4169 |
(IntAndDoubleToLong mapper) { |
4170 |
return new DFLCPap(ex, origin, fence, array, selector, |
4171 |
compoundIndexedOp(this.op, mapper)); |
4172 |
} |
4173 |
|
4174 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4175 |
final DoublePredicate s = selector; |
4176 |
final DoubleOp f = op; |
4177 |
final double[] a = this.array; |
4178 |
for (int i = lo; i < hi; ++i) { |
4179 |
double x = a[i]; |
4180 |
if (s.op(x)) |
4181 |
procedure.op(f.op(x)); |
4182 |
} |
4183 |
} |
4184 |
|
4185 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4186 |
final DoublePredicate s = selector; |
4187 |
boolean gotFirst = false; |
4188 |
double r = base; |
4189 |
final double[] a = this.array; |
4190 |
final DoubleOp f = op; |
4191 |
for (int i = lo; i < hi; ++i) { |
4192 |
double t = a[i]; |
4193 |
if (s.op(t)) { |
4194 |
double y = f.op(t); |
4195 |
if (!gotFirst) { |
4196 |
gotFirst = true; |
4197 |
r = y; |
4198 |
} |
4199 |
else |
4200 |
r = reducer.op(r, y); |
4201 |
} |
4202 |
} |
4203 |
return r; |
4204 |
} |
4205 |
} |
4206 |
|
4207 |
static final class LFDMPap extends LDMPap { |
4208 |
final LongPredicate selector; |
4209 |
LFDMPap(ForkJoinExecutor ex, int origin, int fence, |
4210 |
long[] array, LongPredicate selector, LongToDouble op) { |
4211 |
super(ex, origin, fence, array, op); |
4212 |
this.selector = selector; |
4213 |
} |
4214 |
|
4215 |
boolean hasFilter() { return true; } |
4216 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
4217 |
|
4218 |
public ParallelLongArrayWithLongMapping withMapping(DoubleToLong op) { |
4219 |
return new LFLMPap(ex, origin, fence, array, selector, |
4220 |
CommonOps.compoundOp(this.op, op)); |
4221 |
} |
4222 |
|
4223 |
public ParallelLongArrayWithDoubleMapping withMapping(DoubleOp op) { |
4224 |
return new LFDMPap(ex, origin, fence, array, selector, |
4225 |
CommonOps.compoundOp(this.op, op)); |
4226 |
} |
4227 |
|
4228 |
public <U> ParallelLongArrayWithMapping<U> withMapping |
4229 |
(DoubleToObject<? extends U> op) { |
4230 |
return new LFOMPap<U>(ex, origin, fence, array, selector, |
4231 |
CommonOps.compoundOp(this.op, op)); |
4232 |
} |
4233 |
|
4234 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
4235 |
(IntAndDoubleToObject<? extends V> mapper) { |
4236 |
return new LFOCPap<V>(ex, origin, fence, array, selector, |
4237 |
compoundIndexedOp(this.op, mapper)); |
4238 |
} |
4239 |
|
4240 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
4241 |
(IntAndDoubleToDouble mapper) { |
4242 |
return new LFDCPap(ex, origin, fence, array, selector, |
4243 |
compoundIndexedOp(this.op, mapper)); |
4244 |
} |
4245 |
|
4246 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
4247 |
(IntAndDoubleToLong mapper) { |
4248 |
return new LFLCPap(ex, origin, fence, array, selector, |
4249 |
compoundIndexedOp(this.op, mapper)); |
4250 |
} |
4251 |
|
4252 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4253 |
final LongPredicate s = selector; |
4254 |
final long[] a = this.array; |
4255 |
final LongToDouble f = op; |
4256 |
for (int i = lo; i < hi; ++i) { |
4257 |
long x = a[i]; |
4258 |
if (s.op(x)) |
4259 |
procedure.op(f.op(x)); |
4260 |
} |
4261 |
} |
4262 |
|
4263 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4264 |
final LongPredicate s = selector; |
4265 |
final LongToDouble f = op; |
4266 |
boolean gotFirst = false; |
4267 |
double r = base; |
4268 |
final long[] a = this.array; |
4269 |
for (int i = lo; i < hi; ++i) { |
4270 |
long t = a[i]; |
4271 |
if (s.op(t)) { |
4272 |
double y = f.op(t); |
4273 |
if (!gotFirst) { |
4274 |
gotFirst = true; |
4275 |
r = y; |
4276 |
} |
4277 |
else |
4278 |
r = reducer.op(r, y); |
4279 |
} |
4280 |
} |
4281 |
return r; |
4282 |
} |
4283 |
} |
4284 |
|
4285 |
// double-mapped, relational |
4286 |
static final class ORDMPap<T> extends ODMPap<T> { |
4287 |
final IntAndObjectPredicate<? super T> selector; |
4288 |
ORDMPap(ForkJoinExecutor ex, int origin, int fence, |
4289 |
T[] array, IntAndObjectPredicate<? super T> selector, |
4290 |
ObjectToDouble<? super T> op) { |
4291 |
super(ex, origin, fence, array, op); |
4292 |
this.selector = selector; |
4293 |
} |
4294 |
|
4295 |
boolean hasFilter() { return true; } |
4296 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
4297 |
|
4298 |
public ParallelArrayWithDoubleMapping<T> withMapping(DoubleOp op) { |
4299 |
return new ORDMPap<T>(ex, origin, fence, array, selector, |
4300 |
CommonOps.compoundOp(this.op, op)); |
4301 |
} |
4302 |
|
4303 |
public ParallelArrayWithLongMapping<T> withMapping(DoubleToLong op) { |
4304 |
return new ORLMPap<T>(ex, origin, fence, array, selector, |
4305 |
CommonOps.compoundOp(this.op, op)); |
4306 |
} |
4307 |
|
4308 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
4309 |
(DoubleToObject<? extends U> op) { |
4310 |
return new OROMPap<T,U>(ex, origin, fence, array, selector, |
4311 |
CommonOps.compoundOp(this.op, op)); |
4312 |
} |
4313 |
|
4314 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
4315 |
(IntAndDoubleToObject<? extends V> mapper) { |
4316 |
return new OROCPap<T,V>(ex, origin, fence, array, selector, |
4317 |
compoundIndexedOp(this.op, mapper)); |
4318 |
} |
4319 |
|
4320 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
4321 |
(IntAndDoubleToDouble mapper) { |
4322 |
return new ORDCPap<T>(ex, origin, fence, array, selector, |
4323 |
compoundIndexedOp(this.op, mapper)); |
4324 |
} |
4325 |
|
4326 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
4327 |
(IntAndDoubleToLong mapper) { |
4328 |
return new ORLCPap<T>(ex, origin, fence, array, selector, |
4329 |
compoundIndexedOp(this.op, mapper)); |
4330 |
} |
4331 |
|
4332 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4333 |
final IntAndObjectPredicate s = selector; |
4334 |
final Object[] a = this.array; |
4335 |
final ObjectToDouble f = op; |
4336 |
for (int i = lo; i < hi; ++i) { |
4337 |
Object x = a[i]; |
4338 |
if (s.op(i, x)) |
4339 |
procedure.op(f.op(x)); |
4340 |
} |
4341 |
} |
4342 |
|
4343 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4344 |
final IntAndObjectPredicate s = selector; |
4345 |
final ObjectToDouble f = op; |
4346 |
boolean gotFirst = false; |
4347 |
double r = base; |
4348 |
final Object[] a = this.array; |
4349 |
for (int i = lo; i < hi; ++i) { |
4350 |
Object t = a[i]; |
4351 |
if (s.op(i, t)) { |
4352 |
double y = f.op(t); |
4353 |
if (!gotFirst) { |
4354 |
gotFirst = true; |
4355 |
r = y; |
4356 |
} |
4357 |
else |
4358 |
r = reducer.op(r, y); |
4359 |
} |
4360 |
} |
4361 |
return r; |
4362 |
} |
4363 |
} |
4364 |
|
4365 |
static final class DRDMPap extends DDMPap { |
4366 |
final IntAndDoublePredicate selector; |
4367 |
DRDMPap(ForkJoinExecutor ex, int origin, int fence, |
4368 |
double[] array, IntAndDoublePredicate selector, DoubleOp op) { |
4369 |
super(ex, origin, fence, array, op); |
4370 |
this.selector = selector; |
4371 |
} |
4372 |
|
4373 |
boolean hasFilter() { return true; } |
4374 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
4375 |
|
4376 |
public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { |
4377 |
return new DRDMPap(ex, origin, fence, array, selector, |
4378 |
CommonOps.compoundOp(this.op, op)); |
4379 |
} |
4380 |
|
4381 |
public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { |
4382 |
return new DRLMPap(ex, origin, fence, array, selector, |
4383 |
CommonOps.compoundOp(this.op, op)); |
4384 |
} |
4385 |
|
4386 |
public <U> ParallelDoubleArrayWithMapping<U> withMapping |
4387 |
(DoubleToObject<? extends U> op) { |
4388 |
return new DROMPap<U>(ex, origin, fence, array, selector, |
4389 |
CommonOps.compoundOp(this.op, op)); |
4390 |
} |
4391 |
|
4392 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
4393 |
(IntAndDoubleToObject<? extends V> mapper) { |
4394 |
return new DROCPap<V>(ex, origin, fence, array, selector, |
4395 |
compoundIndexedOp(this.op, mapper)); |
4396 |
} |
4397 |
|
4398 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
4399 |
(IntAndDoubleToDouble mapper) { |
4400 |
return new DRDCPap(ex, origin, fence, array, selector, |
4401 |
compoundIndexedOp(this.op, mapper)); |
4402 |
} |
4403 |
|
4404 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
4405 |
(IntAndDoubleToLong mapper) { |
4406 |
return new DRLCPap(ex, origin, fence, array, selector, |
4407 |
compoundIndexedOp(this.op, mapper)); |
4408 |
} |
4409 |
|
4410 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4411 |
final IntAndDoublePredicate s = selector; |
4412 |
final DoubleOp f = op; |
4413 |
final double[] a = this.array; |
4414 |
for (int i = lo; i < hi; ++i) { |
4415 |
double x = a[i]; |
4416 |
if (s.op(i, x)) |
4417 |
procedure.op(f.op(x)); |
4418 |
} |
4419 |
} |
4420 |
|
4421 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4422 |
final IntAndDoublePredicate s = selector; |
4423 |
boolean gotFirst = false; |
4424 |
double r = base; |
4425 |
final double[] a = this.array; |
4426 |
final DoubleOp f = op; |
4427 |
for (int i = lo; i < hi; ++i) { |
4428 |
double t = a[i]; |
4429 |
if (s.op(i, t)) { |
4430 |
double y = f.op(t); |
4431 |
if (!gotFirst) { |
4432 |
gotFirst = true; |
4433 |
r = y; |
4434 |
} |
4435 |
else |
4436 |
r = reducer.op(r, y); |
4437 |
} |
4438 |
} |
4439 |
return r; |
4440 |
} |
4441 |
} |
4442 |
|
4443 |
static final class LRDMPap extends LDMPap { |
4444 |
final IntAndLongPredicate selector; |
4445 |
LRDMPap(ForkJoinExecutor ex, int origin, int fence, |
4446 |
long[] array, IntAndLongPredicate selector, LongToDouble op) { |
4447 |
super(ex, origin, fence, array, op); |
4448 |
this.selector = selector; |
4449 |
} |
4450 |
|
4451 |
boolean hasFilter() { return true; } |
4452 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
4453 |
|
4454 |
public ParallelLongArrayWithLongMapping withMapping(DoubleToLong op) { |
4455 |
return new LRLMPap(ex, origin, fence, array, selector, |
4456 |
CommonOps.compoundOp(this.op, op)); |
4457 |
} |
4458 |
|
4459 |
public ParallelLongArrayWithDoubleMapping withMapping(DoubleOp op) { |
4460 |
return new LRDMPap(ex, origin, fence, array, selector, |
4461 |
CommonOps.compoundOp(this.op, op)); |
4462 |
} |
4463 |
|
4464 |
public <U> ParallelLongArrayWithMapping<U> withMapping |
4465 |
(DoubleToObject<? extends U> op) { |
4466 |
return new LROMPap<U>(ex, origin, fence, array, selector, |
4467 |
CommonOps.compoundOp(this.op, op)); |
4468 |
} |
4469 |
|
4470 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
4471 |
(IntAndDoubleToObject<? extends V> mapper) { |
4472 |
return new LROCPap<V>(ex, origin, fence, array, selector, |
4473 |
compoundIndexedOp(this.op, mapper)); |
4474 |
} |
4475 |
|
4476 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
4477 |
(IntAndDoubleToDouble mapper) { |
4478 |
return new LRDCPap(ex, origin, fence, array, selector, |
4479 |
compoundIndexedOp(this.op, mapper)); |
4480 |
} |
4481 |
|
4482 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
4483 |
(IntAndDoubleToLong mapper) { |
4484 |
return new LRLCPap(ex, origin, fence, array, selector, |
4485 |
compoundIndexedOp(this.op, mapper)); |
4486 |
} |
4487 |
|
4488 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4489 |
final IntAndLongPredicate s = selector; |
4490 |
final long[] a = this.array; |
4491 |
final LongToDouble f = op; |
4492 |
for (int i = lo; i < hi; ++i) { |
4493 |
long x = a[i]; |
4494 |
if (s.op(i, x)) |
4495 |
procedure.op(f.op(x)); |
4496 |
} |
4497 |
} |
4498 |
|
4499 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4500 |
final IntAndLongPredicate s = selector; |
4501 |
final LongToDouble f = op; |
4502 |
boolean gotFirst = false; |
4503 |
double r = base; |
4504 |
final long[] a = this.array; |
4505 |
for (int i = lo; i < hi; ++i) { |
4506 |
long t = a[i]; |
4507 |
if (s.op(i, t)) { |
4508 |
double y = f.op(t); |
4509 |
if (!gotFirst) { |
4510 |
gotFirst = true; |
4511 |
r = y; |
4512 |
} |
4513 |
else |
4514 |
r = reducer.op(r, y); |
4515 |
} |
4516 |
} |
4517 |
return r; |
4518 |
} |
4519 |
} |
4520 |
|
4521 |
// double-combined |
4522 |
static abstract class ODCPap<T> extends ParallelArrayWithDoubleMapping<T> { |
4523 |
final IntAndObjectToDouble<? super T> op; |
4524 |
ODCPap(ForkJoinExecutor ex, int origin, int fence, |
4525 |
T[] array, IntAndObjectToDouble<? super T> op) { |
4526 |
super(ex, origin, fence, array); |
4527 |
this.op = op; |
4528 |
} |
4529 |
|
4530 |
final boolean hasMap() { return true; } |
4531 |
final double dget(int i) { return op.op(i, this.array[i]); } |
4532 |
final Object oget(int i) { return Double.valueOf(dget(i)); } |
4533 |
final long lget(int i) { return (long)(dget(i)); } |
4534 |
|
4535 |
final void leafTransfer(int lo, int hi, double[] dest, int offset) { |
4536 |
final IntAndObjectToDouble f = op; |
4537 |
final Object[] a = this.array; |
4538 |
for (int i = lo; i < hi; ++i) |
4539 |
dest[offset++] = f.op(i, a[i]); |
4540 |
} |
4541 |
|
4542 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
4543 |
double[] dest, int offset) { |
4544 |
final Object[] a = this.array; |
4545 |
final IntAndObjectToDouble f = op; |
4546 |
for (int i = loIdx; i < hiIdx; ++i) { |
4547 |
int idx = indices[i]; |
4548 |
dest[offset++] = f.op(idx, a[idx]); |
4549 |
} |
4550 |
} |
4551 |
|
4552 |
} |
4553 |
|
4554 |
static abstract class DDCPap extends ParallelDoubleArrayWithDoubleMapping { |
4555 |
final IntAndDoubleToDouble op; |
4556 |
DDCPap(ForkJoinExecutor ex, int origin, int fence, |
4557 |
double[] array, IntAndDoubleToDouble op) { |
4558 |
super(ex, origin, fence, array); |
4559 |
this.op = op; |
4560 |
} |
4561 |
|
4562 |
final boolean hasMap() { return true; } |
4563 |
final double dget(int i) { return op.op(i, this.array[i]); } |
4564 |
final Object oget(int i) { return Double.valueOf(dget(i)); } |
4565 |
final long lget(int i) { return (long)(dget(i)); } |
4566 |
|
4567 |
final void leafTransfer(int lo, int hi, double[] dest, int offset) { |
4568 |
final IntAndDoubleToDouble f = op; |
4569 |
final double[] a = this.array; |
4570 |
for (int i = lo; i < hi; ++i) |
4571 |
dest[offset++] = f.op(i, a[i]); |
4572 |
} |
4573 |
|
4574 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
4575 |
double[] dest, int offset) { |
4576 |
final double[] a = this.array; |
4577 |
final IntAndDoubleToDouble f = op; |
4578 |
for (int i = loIdx; i < hiIdx; ++i) { |
4579 |
int idx = indices[i]; |
4580 |
dest[offset++] = f.op(idx, a[idx]); |
4581 |
} |
4582 |
} |
4583 |
} |
4584 |
|
4585 |
static abstract class LDCPap extends ParallelLongArrayWithDoubleMapping { |
4586 |
final IntAndLongToDouble op; |
4587 |
LDCPap(ForkJoinExecutor ex, int origin, int fence, |
4588 |
long[] array, IntAndLongToDouble op) { |
4589 |
super(ex, origin, fence, array); |
4590 |
this.op = op; |
4591 |
} |
4592 |
|
4593 |
final boolean hasMap() { return true; } |
4594 |
final double dget(int i) { return op.op(i, this.array[i]); } |
4595 |
final Object oget(int i) { return Double.valueOf(dget(i)); } |
4596 |
final long lget(int i) { return (long)(dget(i)); } |
4597 |
|
4598 |
final void leafTransfer(int lo, int hi, double[] dest, int offset) { |
4599 |
final IntAndLongToDouble f = op; |
4600 |
final long[] a = this.array; |
4601 |
for (int i = lo; i < hi; ++i) |
4602 |
dest[offset++] = f.op(i, a[i]); |
4603 |
} |
4604 |
|
4605 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
4606 |
double[] dest, int offset) { |
4607 |
final long[] a = this.array; |
4608 |
final IntAndLongToDouble f = op; |
4609 |
for (int i = loIdx; i < hiIdx; ++i) { |
4610 |
int idx = indices[i]; |
4611 |
dest[offset++] = f.op(idx, a[idx]); |
4612 |
} |
4613 |
} |
4614 |
} |
4615 |
|
4616 |
// double-combined, unfiltered |
4617 |
static final class OUDCPap<T> extends ODCPap<T> { |
4618 |
OUDCPap(ForkJoinExecutor ex, int origin, int fence, |
4619 |
T[] array, IntAndObjectToDouble<? super T> op) { |
4620 |
super(ex, origin, fence, array, op); |
4621 |
} |
4622 |
|
4623 |
public ParallelArrayWithDoubleMapping<T> withMapping(DoubleOp op) { |
4624 |
return new OUDCPap<T>(ex, origin, fence, array, |
4625 |
compoundIndexedOp(this.op, op)); |
4626 |
} |
4627 |
|
4628 |
public ParallelArrayWithLongMapping<T> withMapping(DoubleToLong op) { |
4629 |
return new OULCPap<T>(ex, origin, fence, array, |
4630 |
compoundIndexedOp(this.op, op)); |
4631 |
} |
4632 |
|
4633 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
4634 |
(DoubleToObject<? extends U> op) { |
4635 |
return new OUOCPap<T,U>(ex, origin, fence, array, |
4636 |
compoundIndexedOp(this.op, op)); |
4637 |
} |
4638 |
|
4639 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
4640 |
(IntAndDoubleToObject<? extends V> mapper) { |
4641 |
return new OUOCPap<T,V>(ex, origin, fence, array, |
4642 |
compoundIndexedOp(this.op, mapper)); |
4643 |
} |
4644 |
|
4645 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
4646 |
(IntAndDoubleToDouble mapper) { |
4647 |
return new OUDCPap<T>(ex, origin, fence, array, |
4648 |
compoundIndexedOp(this.op, mapper)); |
4649 |
} |
4650 |
|
4651 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
4652 |
(IntAndDoubleToLong mapper) { |
4653 |
return new OULCPap<T>(ex, origin, fence, array, |
4654 |
compoundIndexedOp(this.op, mapper)); |
4655 |
} |
4656 |
|
4657 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4658 |
final IntAndObjectToDouble f = op; |
4659 |
final Object[] a = this.array; |
4660 |
for (int i = lo; i < hi; ++i) |
4661 |
procedure.op(f.op(i, a[i])); |
4662 |
} |
4663 |
|
4664 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4665 |
if (lo >= hi) |
4666 |
return base; |
4667 |
final Object[] a = this.array; |
4668 |
final IntAndObjectToDouble f = op; |
4669 |
double r = f.op(lo, a[lo]); |
4670 |
for (int i = lo+1; i < hi; ++i) |
4671 |
r = reducer.op(r, f.op(i, a[i])); |
4672 |
return r; |
4673 |
} |
4674 |
|
4675 |
} |
4676 |
|
4677 |
static final class DUDCPap extends DDCPap { |
4678 |
DUDCPap(ForkJoinExecutor ex, int origin, int fence, |
4679 |
double[] array, IntAndDoubleToDouble op) { |
4680 |
super(ex, origin, fence, array, op); |
4681 |
} |
4682 |
|
4683 |
public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { |
4684 |
return new DUDCPap(ex, origin, fence, array, |
4685 |
compoundIndexedOp(this.op, op)); |
4686 |
} |
4687 |
|
4688 |
public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { |
4689 |
return new DULCPap(ex, origin, fence, array, |
4690 |
compoundIndexedOp(this.op, op)); |
4691 |
} |
4692 |
|
4693 |
public <U> ParallelDoubleArrayWithMapping< U> withMapping |
4694 |
(DoubleToObject<? extends U> op) { |
4695 |
return new DUOCPap<U>(ex, origin, fence, array, |
4696 |
compoundIndexedOp(this.op, op)); |
4697 |
} |
4698 |
|
4699 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
4700 |
(IntAndDoubleToObject<? extends V> mapper) { |
4701 |
return new DUOCPap<V>(ex, origin, fence, array, |
4702 |
compoundIndexedOp(this.op, mapper)); |
4703 |
} |
4704 |
|
4705 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
4706 |
(IntAndDoubleToDouble mapper) { |
4707 |
return new DUDCPap(ex, origin, fence, array, |
4708 |
compoundIndexedOp(this.op, mapper)); |
4709 |
} |
4710 |
|
4711 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
4712 |
(IntAndDoubleToLong mapper) { |
4713 |
return new DULCPap(ex, origin, fence, array, |
4714 |
compoundIndexedOp(this.op, mapper)); |
4715 |
} |
4716 |
|
4717 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4718 |
final IntAndDoubleToDouble f = op; |
4719 |
final double[] a = this.array; |
4720 |
for (int i = lo; i < hi; ++i) |
4721 |
procedure.op(f.op(i, a[i])); |
4722 |
} |
4723 |
|
4724 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4725 |
if (lo >= hi) |
4726 |
return base; |
4727 |
final double[] a = this.array; |
4728 |
final IntAndDoubleToDouble f = op; |
4729 |
double r = f.op(lo, a[lo]); |
4730 |
for (int i = lo+1; i < hi; ++i) |
4731 |
r = reducer.op(r, f.op(i, a[i])); |
4732 |
return r; |
4733 |
} |
4734 |
} |
4735 |
|
4736 |
static final class LUDCPap extends LDCPap { |
4737 |
LUDCPap(ForkJoinExecutor ex, int origin, int fence, |
4738 |
long[] array, IntAndLongToDouble op) { |
4739 |
super(ex, origin, fence, array, op); |
4740 |
} |
4741 |
|
4742 |
public ParallelLongArrayWithDoubleMapping withMapping(DoubleOp op) { |
4743 |
return new LUDCPap(ex, origin, fence, array, |
4744 |
compoundIndexedOp(this.op, op)); |
4745 |
} |
4746 |
|
4747 |
public ParallelLongArrayWithLongMapping withMapping(DoubleToLong op) { |
4748 |
return new LULCPap(ex, origin, fence, array, |
4749 |
compoundIndexedOp(this.op, op)); |
4750 |
} |
4751 |
|
4752 |
public <U> ParallelLongArrayWithMapping< U> withMapping |
4753 |
(DoubleToObject<? extends U> op) { |
4754 |
return new LUOCPap<U>(ex, origin, fence, array, |
4755 |
compoundIndexedOp(this.op, op)); |
4756 |
} |
4757 |
|
4758 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
4759 |
(IntAndDoubleToObject<? extends V> mapper) { |
4760 |
return new LUOCPap<V>(ex, origin, fence, array, |
4761 |
compoundIndexedOp(this.op, mapper)); |
4762 |
} |
4763 |
|
4764 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
4765 |
(IntAndDoubleToDouble mapper) { |
4766 |
return new LUDCPap(ex, origin, fence, array, |
4767 |
compoundIndexedOp(this.op, mapper)); |
4768 |
} |
4769 |
|
4770 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
4771 |
(IntAndDoubleToLong mapper) { |
4772 |
return new LULCPap(ex, origin, fence, array, |
4773 |
compoundIndexedOp(this.op, mapper)); |
4774 |
} |
4775 |
|
4776 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4777 |
final IntAndLongToDouble f = op; |
4778 |
final long[] a = this.array; |
4779 |
for (int i = lo; i < hi; ++i) |
4780 |
procedure.op(f.op(i, a[i])); |
4781 |
} |
4782 |
|
4783 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4784 |
if (lo >= hi) |
4785 |
return base; |
4786 |
final long[] a = this.array; |
4787 |
final IntAndLongToDouble f = op; |
4788 |
double r = f.op(lo, a[lo]); |
4789 |
for (int i = lo+1; i < hi; ++i) |
4790 |
r = reducer.op(r, f.op(i, a[i])); |
4791 |
return r; |
4792 |
} |
4793 |
|
4794 |
} |
4795 |
|
4796 |
// double-combined, filtered |
4797 |
static final class OFDCPap<T> extends ODCPap<T> { |
4798 |
final Predicate<? super T> selector; |
4799 |
OFDCPap(ForkJoinExecutor ex, int origin, int fence, |
4800 |
T[] array, Predicate<? super T> selector, |
4801 |
IntAndObjectToDouble<? super T> op) { |
4802 |
super(ex, origin, fence, array, op); |
4803 |
this.selector = selector; |
4804 |
} |
4805 |
|
4806 |
boolean hasFilter() { return true; } |
4807 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
4808 |
|
4809 |
public ParallelArrayWithDoubleMapping<T> withMapping(DoubleOp op) { |
4810 |
return new OFDCPap<T> |
4811 |
(ex, origin, fence, array, selector, |
4812 |
compoundIndexedOp(this.op, op)); |
4813 |
} |
4814 |
|
4815 |
public ParallelArrayWithLongMapping<T> withMapping(DoubleToLong op) { |
4816 |
return new OFLCPap<T>(ex, origin, fence, array, selector, |
4817 |
compoundIndexedOp(this.op, op)); |
4818 |
} |
4819 |
|
4820 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
4821 |
(DoubleToObject<? extends U> op) { |
4822 |
return new OFOCPap<T,U>(ex, origin, fence, array, selector, |
4823 |
compoundIndexedOp(this.op, op)); |
4824 |
} |
4825 |
|
4826 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
4827 |
(IntAndDoubleToObject<? extends V> mapper) { |
4828 |
return new OFOCPap<T,V>(ex, origin, fence, array, selector, |
4829 |
compoundIndexedOp(this.op, mapper)); |
4830 |
} |
4831 |
|
4832 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
4833 |
(IntAndDoubleToDouble mapper) { |
4834 |
return new OFDCPap<T>(ex, origin, fence, array, selector, |
4835 |
compoundIndexedOp(this.op, mapper)); |
4836 |
} |
4837 |
|
4838 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
4839 |
(IntAndDoubleToLong mapper) { |
4840 |
return new OFLCPap<T>(ex, origin, fence, array, selector, |
4841 |
compoundIndexedOp(this.op, mapper)); |
4842 |
} |
4843 |
|
4844 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4845 |
final Predicate s = selector; |
4846 |
final Object[] a = this.array; |
4847 |
final IntAndObjectToDouble f = op; |
4848 |
for (int i = lo; i < hi; ++i) { |
4849 |
Object x = a[i]; |
4850 |
if (s.op(x)) |
4851 |
procedure.op(f.op(i, x)); |
4852 |
} |
4853 |
} |
4854 |
|
4855 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4856 |
final Predicate s = selector; |
4857 |
final IntAndObjectToDouble f = op; |
4858 |
boolean gotFirst = false; |
4859 |
double r = base; |
4860 |
final Object[] a = this.array; |
4861 |
for (int i = lo; i < hi; ++i) { |
4862 |
Object t = a[i]; |
4863 |
if (s.op(t)) { |
4864 |
double y = f.op(i, t); |
4865 |
if (!gotFirst) { |
4866 |
gotFirst = true; |
4867 |
r = y; |
4868 |
} |
4869 |
else |
4870 |
r = reducer.op(r, y); |
4871 |
} |
4872 |
} |
4873 |
return r; |
4874 |
} |
4875 |
} |
4876 |
|
4877 |
static final class DFDCPap extends DDCPap { |
4878 |
final DoublePredicate selector; |
4879 |
DFDCPap(ForkJoinExecutor ex, int origin, int fence, |
4880 |
double[] array, DoublePredicate selector, |
4881 |
IntAndDoubleToDouble op) { |
4882 |
super(ex, origin, fence, array, op); |
4883 |
this.selector = selector; |
4884 |
} |
4885 |
|
4886 |
boolean hasFilter() { return true; } |
4887 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
4888 |
|
4889 |
public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { |
4890 |
return new DFDCPap(ex, origin, fence, array, selector, |
4891 |
compoundIndexedOp(this.op, op)); |
4892 |
} |
4893 |
|
4894 |
public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { |
4895 |
return new DFLCPap (ex, origin, fence, array, selector, |
4896 |
compoundIndexedOp(this.op, op)); |
4897 |
} |
4898 |
|
4899 |
public <U> ParallelDoubleArrayWithMapping< U> withMapping |
4900 |
(DoubleToObject<? extends U> op) { |
4901 |
return new DFOCPap<U>(ex, origin, fence, array, selector, |
4902 |
compoundIndexedOp(this.op, op)); |
4903 |
} |
4904 |
|
4905 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
4906 |
(IntAndDoubleToObject<? extends V> mapper) { |
4907 |
return new DFOCPap<V>(ex, origin, fence, array, selector, |
4908 |
compoundIndexedOp(this.op, mapper)); |
4909 |
} |
4910 |
|
4911 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
4912 |
(IntAndDoubleToDouble mapper) { |
4913 |
return new DFDCPap(ex, origin, fence, array, selector, |
4914 |
compoundIndexedOp(this.op, mapper)); |
4915 |
} |
4916 |
|
4917 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
4918 |
(IntAndDoubleToLong mapper) { |
4919 |
return new DFLCPap(ex, origin, fence, array, selector, |
4920 |
compoundIndexedOp(this.op, mapper)); |
4921 |
} |
4922 |
|
4923 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
4924 |
final DoublePredicate s = selector; |
4925 |
final double[] a = this.array; |
4926 |
final IntAndDoubleToDouble f = op; |
4927 |
for (int i = lo; i < hi; ++i) { |
4928 |
double x = a[i]; |
4929 |
if (s.op(x)) |
4930 |
procedure.op(f.op(i, x)); |
4931 |
} |
4932 |
} |
4933 |
|
4934 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
4935 |
final DoublePredicate s = selector; |
4936 |
final IntAndDoubleToDouble f = op; |
4937 |
boolean gotFirst = false; |
4938 |
double r = base; |
4939 |
final double[] a = this.array; |
4940 |
for (int i = lo; i < hi; ++i) { |
4941 |
double t = a[i]; |
4942 |
if (s.op(t)) { |
4943 |
double y = f.op(i, t); |
4944 |
if (!gotFirst) { |
4945 |
gotFirst = true; |
4946 |
r = y; |
4947 |
} |
4948 |
else |
4949 |
r = reducer.op(r, y); |
4950 |
} |
4951 |
} |
4952 |
return r; |
4953 |
} |
4954 |
} |
4955 |
|
4956 |
static final class LFDCPap extends LDCPap { |
4957 |
final LongPredicate selector; |
4958 |
LFDCPap(ForkJoinExecutor ex, int origin, int fence, |
4959 |
long[] array, LongPredicate selector, IntAndLongToDouble op) { |
4960 |
super(ex, origin, fence, array, op); |
4961 |
this.selector = selector; |
4962 |
} |
4963 |
|
4964 |
boolean hasFilter() { return true; } |
4965 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
4966 |
|
4967 |
public ParallelLongArrayWithDoubleMapping withMapping(DoubleOp op) { |
4968 |
return new LFDCPap(ex, origin, fence, array, selector, |
4969 |
compoundIndexedOp(this.op, op)); |
4970 |
} |
4971 |
|
4972 |
public ParallelLongArrayWithLongMapping withMapping(DoubleToLong op) { |
4973 |
return new LFLCPap(ex, origin, fence, array, selector, |
4974 |
compoundIndexedOp(this.op, op)); |
4975 |
} |
4976 |
|
4977 |
public <U> ParallelLongArrayWithMapping< U> withMapping |
4978 |
(DoubleToObject<? extends U> op) { |
4979 |
return new LFOCPap<U>(ex, origin, fence, array, selector, |
4980 |
compoundIndexedOp(this.op, op)); |
4981 |
} |
4982 |
|
4983 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
4984 |
(IntAndDoubleToObject<? extends V> mapper) { |
4985 |
return new LFOCPap<V>(ex, origin, fence, array, selector, |
4986 |
compoundIndexedOp(this.op, mapper)); |
4987 |
} |
4988 |
|
4989 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
4990 |
(IntAndDoubleToDouble mapper) { |
4991 |
return new LFDCPap(ex, origin, fence, array, selector, |
4992 |
compoundIndexedOp(this.op, mapper)); |
4993 |
} |
4994 |
|
4995 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
4996 |
(IntAndDoubleToLong mapper) { |
4997 |
return new LFLCPap(ex, origin, fence, array, selector, |
4998 |
compoundIndexedOp(this.op, mapper)); |
4999 |
} |
5000 |
|
5001 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
5002 |
final LongPredicate s = selector; |
5003 |
final long[] a = this.array; |
5004 |
final IntAndLongToDouble f = op; |
5005 |
for (int i = lo; i < hi; ++i) { |
5006 |
long x = a[i]; |
5007 |
if (s.op(x)) |
5008 |
procedure.op(f.op(i, x)); |
5009 |
} |
5010 |
} |
5011 |
|
5012 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
5013 |
final LongPredicate s = selector; |
5014 |
final IntAndLongToDouble f = op; |
5015 |
boolean gotFirst = false; |
5016 |
double r = base; |
5017 |
final long[] a = this.array; |
5018 |
for (int i = lo; i < hi; ++i) { |
5019 |
long t = a[i]; |
5020 |
if (s.op(t)) { |
5021 |
double y = f.op(i, t); |
5022 |
if (!gotFirst) { |
5023 |
gotFirst = true; |
5024 |
r = y; |
5025 |
} |
5026 |
else |
5027 |
r = reducer.op(r, y); |
5028 |
} |
5029 |
} |
5030 |
return r; |
5031 |
} |
5032 |
} |
5033 |
|
5034 |
// double-combined, relational |
5035 |
static final class ORDCPap<T> extends ODCPap<T> { |
5036 |
final IntAndObjectPredicate<? super T> selector; |
5037 |
ORDCPap(ForkJoinExecutor ex, int origin, int fence, |
5038 |
T[] array, IntAndObjectPredicate<? super T> selector, |
5039 |
IntAndObjectToDouble<? super T> op) { |
5040 |
super(ex, origin, fence, array, op); |
5041 |
this.selector = selector; |
5042 |
} |
5043 |
|
5044 |
boolean hasFilter() { return true; } |
5045 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
5046 |
|
5047 |
public ParallelArrayWithDoubleMapping<T> withMapping(DoubleOp op) { |
5048 |
return new ORDCPap<T> |
5049 |
(ex, origin, fence, array, selector, |
5050 |
compoundIndexedOp(this.op, op)); |
5051 |
} |
5052 |
|
5053 |
public ParallelArrayWithLongMapping<T> withMapping(DoubleToLong op) { |
5054 |
return new ORLCPap<T>(ex, origin, fence, array, selector, |
5055 |
compoundIndexedOp(this.op, op)); |
5056 |
} |
5057 |
|
5058 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
5059 |
(DoubleToObject<? extends U> op) { |
5060 |
return new OROCPap<T,U>(ex, origin, fence, array, selector, |
5061 |
compoundIndexedOp(this.op, op)); |
5062 |
} |
5063 |
|
5064 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
5065 |
(IntAndDoubleToObject<? extends V> mapper) { |
5066 |
return new OROCPap<T,V>(ex, origin, fence, array, selector, |
5067 |
compoundIndexedOp(this.op, mapper)); |
5068 |
} |
5069 |
|
5070 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
5071 |
(IntAndDoubleToDouble mapper) { |
5072 |
return new ORDCPap<T>(ex, origin, fence, array, selector, |
5073 |
compoundIndexedOp(this.op, mapper)); |
5074 |
} |
5075 |
|
5076 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
5077 |
(IntAndDoubleToLong mapper) { |
5078 |
return new ORLCPap<T>(ex, origin, fence, array, selector, |
5079 |
compoundIndexedOp(this.op, mapper)); |
5080 |
} |
5081 |
|
5082 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
5083 |
final IntAndObjectPredicate s = selector; |
5084 |
final Object[] a = this.array; |
5085 |
final IntAndObjectToDouble f = op; |
5086 |
for (int i = lo; i < hi; ++i) { |
5087 |
Object x = a[i]; |
5088 |
if (s.op(i, x)) |
5089 |
procedure.op(f.op(i, x)); |
5090 |
} |
5091 |
} |
5092 |
|
5093 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
5094 |
final IntAndObjectPredicate s = selector; |
5095 |
final IntAndObjectToDouble f = op; |
5096 |
boolean gotFirst = false; |
5097 |
double r = base; |
5098 |
final Object[] a = this.array; |
5099 |
for (int i = lo; i < hi; ++i) { |
5100 |
Object t = a[i]; |
5101 |
if (s.op(i, t)) { |
5102 |
double y = f.op(i, t); |
5103 |
if (!gotFirst) { |
5104 |
gotFirst = true; |
5105 |
r = y; |
5106 |
} |
5107 |
else |
5108 |
r = reducer.op(r, y); |
5109 |
} |
5110 |
} |
5111 |
return r; |
5112 |
} |
5113 |
} |
5114 |
|
5115 |
static final class DRDCPap extends DDCPap { |
5116 |
final IntAndDoublePredicate selector; |
5117 |
DRDCPap(ForkJoinExecutor ex, int origin, int fence, |
5118 |
double[] array, IntAndDoublePredicate selector, |
5119 |
IntAndDoubleToDouble op) { |
5120 |
super(ex, origin, fence, array, op); |
5121 |
this.selector = selector; |
5122 |
} |
5123 |
|
5124 |
boolean hasFilter() { return true; } |
5125 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
5126 |
|
5127 |
public ParallelDoubleArrayWithDoubleMapping withMapping(DoubleOp op) { |
5128 |
return new DRDCPap(ex, origin, fence, array, selector, |
5129 |
compoundIndexedOp(this.op, op)); |
5130 |
} |
5131 |
|
5132 |
public ParallelDoubleArrayWithLongMapping withMapping(DoubleToLong op) { |
5133 |
return new DRLCPap (ex, origin, fence, array, selector, |
5134 |
compoundIndexedOp(this.op, op)); |
5135 |
} |
5136 |
|
5137 |
public <U> ParallelDoubleArrayWithMapping< U> withMapping |
5138 |
(DoubleToObject<? extends U> op) { |
5139 |
return new DROCPap<U>(ex, origin, fence, array, selector, |
5140 |
compoundIndexedOp(this.op, op)); |
5141 |
} |
5142 |
|
5143 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
5144 |
(IntAndDoubleToObject<? extends V> mapper) { |
5145 |
return new DROCPap<V>(ex, origin, fence, array, selector, |
5146 |
compoundIndexedOp(this.op, mapper)); |
5147 |
} |
5148 |
|
5149 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
5150 |
(IntAndDoubleToDouble mapper) { |
5151 |
return new DRDCPap(ex, origin, fence, array, selector, |
5152 |
compoundIndexedOp(this.op, mapper)); |
5153 |
} |
5154 |
|
5155 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
5156 |
(IntAndDoubleToLong mapper) { |
5157 |
return new DRLCPap(ex, origin, fence, array, selector, |
5158 |
compoundIndexedOp(this.op, mapper)); |
5159 |
} |
5160 |
|
5161 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
5162 |
final IntAndDoublePredicate s = selector; |
5163 |
final double[] a = this.array; |
5164 |
final IntAndDoubleToDouble f = op; |
5165 |
for (int i = lo; i < hi; ++i) { |
5166 |
double x = a[i]; |
5167 |
if (s.op(i, x)) |
5168 |
procedure.op(f.op(i, x)); |
5169 |
} |
5170 |
} |
5171 |
|
5172 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
5173 |
final IntAndDoublePredicate s = selector; |
5174 |
final IntAndDoubleToDouble f = op; |
5175 |
boolean gotFirst = false; |
5176 |
double r = base; |
5177 |
final double[] a = this.array; |
5178 |
for (int i = lo; i < hi; ++i) { |
5179 |
double t = a[i]; |
5180 |
if (s.op(i, t)) { |
5181 |
double y = f.op(i, t); |
5182 |
if (!gotFirst) { |
5183 |
gotFirst = true; |
5184 |
r = y; |
5185 |
} |
5186 |
else |
5187 |
r = reducer.op(r, y); |
5188 |
} |
5189 |
} |
5190 |
return r; |
5191 |
} |
5192 |
} |
5193 |
|
5194 |
static final class LRDCPap extends LDCPap { |
5195 |
final IntAndLongPredicate selector; |
5196 |
LRDCPap(ForkJoinExecutor ex, int origin, int fence, |
5197 |
long[] array, IntAndLongPredicate selector, IntAndLongToDouble op) { |
5198 |
super(ex, origin, fence, array, op); |
5199 |
this.selector = selector; |
5200 |
} |
5201 |
|
5202 |
boolean hasFilter() { return true; } |
5203 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
5204 |
|
5205 |
public ParallelLongArrayWithDoubleMapping withMapping(DoubleOp op) { |
5206 |
return new LRDCPap(ex, origin, fence, array, selector, |
5207 |
compoundIndexedOp(this.op, op)); |
5208 |
} |
5209 |
|
5210 |
public ParallelLongArrayWithLongMapping withMapping(DoubleToLong op) { |
5211 |
return new LRLCPap(ex, origin, fence, array, selector, |
5212 |
compoundIndexedOp(this.op, op)); |
5213 |
} |
5214 |
|
5215 |
public <U> ParallelLongArrayWithMapping< U> withMapping |
5216 |
(DoubleToObject<? extends U> op) { |
5217 |
return new LROCPap<U>(ex, origin, fence, array, selector, |
5218 |
compoundIndexedOp(this.op, op)); |
5219 |
} |
5220 |
|
5221 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
5222 |
(IntAndDoubleToObject<? extends V> mapper) { |
5223 |
return new LROCPap<V>(ex, origin, fence, array, selector, |
5224 |
compoundIndexedOp(this.op, mapper)); |
5225 |
} |
5226 |
|
5227 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
5228 |
(IntAndDoubleToDouble mapper) { |
5229 |
return new LRDCPap(ex, origin, fence, array, selector, |
5230 |
compoundIndexedOp(this.op, mapper)); |
5231 |
} |
5232 |
|
5233 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
5234 |
(IntAndDoubleToLong mapper) { |
5235 |
return new LRLCPap(ex, origin, fence, array, selector, |
5236 |
compoundIndexedOp(this.op, mapper)); |
5237 |
} |
5238 |
|
5239 |
void leafApply(int lo, int hi, DoubleProcedure procedure) { |
5240 |
final IntAndLongPredicate s = selector; |
5241 |
final long[] a = this.array; |
5242 |
final IntAndLongToDouble f = op; |
5243 |
for (int i = lo; i < hi; ++i) { |
5244 |
long x = a[i]; |
5245 |
if (s.op(i, x)) |
5246 |
procedure.op(f.op(i, x)); |
5247 |
} |
5248 |
} |
5249 |
|
5250 |
double leafReduce(int lo, int hi, DoubleReducer reducer, double base) { |
5251 |
final IntAndLongPredicate s = selector; |
5252 |
final IntAndLongToDouble f = op; |
5253 |
boolean gotFirst = false; |
5254 |
double r = base; |
5255 |
final long[] a = this.array; |
5256 |
for (int i = lo; i < hi; ++i) { |
5257 |
long t = a[i]; |
5258 |
if (s.op(i, t)) { |
5259 |
double y = f.op(i, t); |
5260 |
if (!gotFirst) { |
5261 |
gotFirst = true; |
5262 |
r = y; |
5263 |
} |
5264 |
else |
5265 |
r = reducer.op(r, y); |
5266 |
} |
5267 |
} |
5268 |
return r; |
5269 |
} |
5270 |
} |
5271 |
|
5272 |
// long-combined |
5273 |
static abstract class OLMPap<T> extends ParallelArrayWithLongMapping<T> { |
5274 |
final ObjectToLong<? super T> op; |
5275 |
OLMPap(ForkJoinExecutor ex, int origin, int fence, |
5276 |
T[] array, final ObjectToLong<? super T> op) { |
5277 |
super(ex, origin, fence, array); |
5278 |
this.op = op; |
5279 |
} |
5280 |
|
5281 |
final boolean hasMap() { return true; } |
5282 |
final long lget(int i) { return op.op(this.array[i]); } |
5283 |
final Object oget(int i) { return Long.valueOf(lget(i)); } |
5284 |
final double dget(int i) { return (double)(lget(i)); } |
5285 |
|
5286 |
final void leafTransfer(int lo, int hi, long[] dest, int offset) { |
5287 |
final ObjectToLong f = op; |
5288 |
final Object[] a = this.array; |
5289 |
for (int i = lo; i < hi; ++i) |
5290 |
dest[offset++] = f.op(a[i]); |
5291 |
} |
5292 |
|
5293 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
5294 |
long[] dest, int offset) { |
5295 |
final Object[] a = this.array; |
5296 |
final ObjectToLong f = op; |
5297 |
for (int i = loIdx; i < hiIdx; ++i) |
5298 |
dest[offset++] = f.op(a[indices[i]]); |
5299 |
} |
5300 |
} |
5301 |
|
5302 |
static abstract class DLMPap extends ParallelDoubleArrayWithLongMapping { |
5303 |
final DoubleToLong op; |
5304 |
DLMPap(ForkJoinExecutor ex, int origin, int fence, |
5305 |
double[] array, DoubleToLong op) { |
5306 |
super(ex, origin, fence, array); |
5307 |
this.op = op; |
5308 |
} |
5309 |
|
5310 |
final boolean hasMap() { return true; } |
5311 |
final long lget(int i) { return op.op(this.array[i]); } |
5312 |
final Object oget(int i) { return Long.valueOf(lget(i)); } |
5313 |
final double dget(int i) { return (double)(lget(i)); } |
5314 |
|
5315 |
final void leafTransfer(int lo, int hi, long[] dest, int offset) { |
5316 |
final double[] a = this.array; |
5317 |
final DoubleToLong f = op; |
5318 |
for (int i = lo; i < hi; ++i) |
5319 |
dest[offset++] = f.op(a[i]); |
5320 |
} |
5321 |
|
5322 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
5323 |
long[] dest, int offset) { |
5324 |
final double[] a = this.array; |
5325 |
final DoubleToLong f = op; |
5326 |
for (int i = loIdx; i < hiIdx; ++i) |
5327 |
dest[offset++] = f.op(a[indices[i]]); |
5328 |
} |
5329 |
|
5330 |
} |
5331 |
|
5332 |
static abstract class LLMPap extends ParallelLongArrayWithLongMapping { |
5333 |
final LongOp op; |
5334 |
LLMPap(ForkJoinExecutor ex, int origin, int fence, |
5335 |
long[] array, LongOp op) { |
5336 |
super(ex, origin, fence, array); |
5337 |
this.op = op; |
5338 |
} |
5339 |
|
5340 |
final boolean hasMap() { return true; } |
5341 |
final long lget(int i) { return op.op(this.array[i]); } |
5342 |
final Object oget(int i) { return Long.valueOf(lget(i)); } |
5343 |
final double dget(int i) { return (double)(lget(i)); } |
5344 |
|
5345 |
final void leafTransfer(int lo, int hi, long[] dest, int offset) { |
5346 |
final long[] a = this.array; |
5347 |
final LongOp f = op; |
5348 |
for (int i = lo; i < hi; ++i) |
5349 |
dest[offset++] = f.op(a[i]); |
5350 |
} |
5351 |
|
5352 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
5353 |
long[] dest, int offset) { |
5354 |
final long[] a = this.array; |
5355 |
final LongOp f = op; |
5356 |
for (int i = loIdx; i < hiIdx; ++i) |
5357 |
dest[offset++] = f.op(a[indices[i]]); |
5358 |
} |
5359 |
|
5360 |
} |
5361 |
|
5362 |
// long-combined, unfiltered |
5363 |
static final class OULMPap<T> extends OLMPap<T> { |
5364 |
OULMPap(ForkJoinExecutor ex, int origin, int fence, |
5365 |
T[] array, ObjectToLong<? super T> op) { |
5366 |
super(ex, origin, fence, array, op); |
5367 |
} |
5368 |
|
5369 |
public ParallelArrayWithDoubleMapping<T> withMapping(LongToDouble op) { |
5370 |
return new OUDMPap<T>(ex, origin, fence, array, |
5371 |
CommonOps.compoundOp(this.op, op)); |
5372 |
} |
5373 |
|
5374 |
public ParallelArrayWithLongMapping<T> withMapping(LongOp op) { |
5375 |
return new OULMPap<T>(ex, origin, fence, array, |
5376 |
CommonOps.compoundOp(this.op, op)); |
5377 |
} |
5378 |
|
5379 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
5380 |
(LongToObject<? extends U> op) { |
5381 |
return new OUOMPap<T,U>(ex, origin, fence, array, |
5382 |
CommonOps.compoundOp(this.op, op)); |
5383 |
} |
5384 |
|
5385 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
5386 |
(IntAndLongToObject<? extends V> mapper) { |
5387 |
return new OUOCPap<T,V>(ex, origin, fence, array, |
5388 |
compoundIndexedOp(this.op, mapper)); |
5389 |
} |
5390 |
|
5391 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
5392 |
(IntAndLongToDouble mapper) { |
5393 |
return new OUDCPap<T>(ex, origin, fence, array, |
5394 |
compoundIndexedOp(this.op, mapper)); |
5395 |
} |
5396 |
|
5397 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
5398 |
(IntAndLongToLong mapper) { |
5399 |
return new OULCPap<T>(ex, origin, fence, array, |
5400 |
compoundIndexedOp(this.op, mapper)); |
5401 |
} |
5402 |
|
5403 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
5404 |
final Object[] a = this.array; |
5405 |
final ObjectToLong f = op; |
5406 |
for (int i = lo; i < hi; ++i) |
5407 |
procedure.op(f.op(a[i])); |
5408 |
} |
5409 |
|
5410 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
5411 |
if (lo >= hi) |
5412 |
return base; |
5413 |
final Object[] a = this.array; |
5414 |
final ObjectToLong f = op; |
5415 |
long r = f.op(a[lo]); |
5416 |
for (int i = lo+1; i < hi; ++i) |
5417 |
r = reducer.op(r, f.op(a[i])); |
5418 |
return r; |
5419 |
} |
5420 |
} |
5421 |
|
5422 |
static final class DULMPap extends DLMPap { |
5423 |
DULMPap(ForkJoinExecutor ex, int origin, int fence, |
5424 |
double[] array, DoubleToLong op) { |
5425 |
super(ex, origin, fence, array, op); |
5426 |
} |
5427 |
|
5428 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
5429 |
(LongToDouble op) { |
5430 |
return new DUDMPap(ex, origin, fence, array, |
5431 |
CommonOps.compoundOp(this.op, op)); |
5432 |
} |
5433 |
|
5434 |
public ParallelDoubleArrayWithLongMapping withMapping |
5435 |
(LongOp op) { |
5436 |
return new DULMPap(ex, origin, fence, array, |
5437 |
CommonOps.compoundOp(this.op, op)); |
5438 |
} |
5439 |
|
5440 |
public <U> ParallelDoubleArrayWithMapping<U> withMapping |
5441 |
(LongToObject<? extends U> op) { |
5442 |
return new DUOMPap<U>(ex, origin, fence, array, |
5443 |
CommonOps.compoundOp(this.op, op)); |
5444 |
} |
5445 |
|
5446 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
5447 |
(IntAndLongToObject<? extends V> mapper) { |
5448 |
return new DUOCPap<V>(ex, origin, fence, array, |
5449 |
compoundIndexedOp(this.op, mapper)); |
5450 |
} |
5451 |
|
5452 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
5453 |
(IntAndLongToDouble mapper) { |
5454 |
return new DUDCPap(ex, origin, fence, array, |
5455 |
compoundIndexedOp(this.op, mapper)); |
5456 |
} |
5457 |
|
5458 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
5459 |
(IntAndLongToLong mapper) { |
5460 |
return new DULCPap(ex, origin, fence, array, |
5461 |
compoundIndexedOp(this.op, mapper)); |
5462 |
} |
5463 |
|
5464 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
5465 |
final double[] a = this.array; |
5466 |
final DoubleToLong f = op; |
5467 |
for (int i = lo; i < hi; ++i) |
5468 |
procedure.op(f.op(a[i])); |
5469 |
} |
5470 |
|
5471 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
5472 |
if (lo >= hi) |
5473 |
return base; |
5474 |
final double[] a = this.array; |
5475 |
final DoubleToLong f = op; |
5476 |
long r = f.op(a[lo]); |
5477 |
for (int i = lo+1; i < hi; ++i) |
5478 |
r = reducer.op(r, f.op(a[i])); |
5479 |
return r; |
5480 |
} |
5481 |
|
5482 |
} |
5483 |
|
5484 |
static final class LULMPap extends LLMPap { |
5485 |
LULMPap(ForkJoinExecutor ex, int origin, int fence, |
5486 |
long[] array, LongOp op) { |
5487 |
super(ex, origin, fence, array, op); |
5488 |
} |
5489 |
|
5490 |
public ParallelLongArrayWithLongMapping withMapping(LongOp op) { |
5491 |
return new LULMPap(ex, origin, fence, array, |
5492 |
CommonOps.compoundOp(this.op, op)); |
5493 |
} |
5494 |
|
5495 |
public ParallelLongArrayWithDoubleMapping withMapping(LongToDouble op) { |
5496 |
return new LUDMPap(ex, origin, fence, array, |
5497 |
CommonOps.compoundOp(this.op, op)); |
5498 |
} |
5499 |
|
5500 |
public <U> ParallelLongArrayWithMapping<U> withMapping |
5501 |
(LongToObject<? extends U> op) { |
5502 |
return new LUOMPap<U>(ex, origin, fence, array, |
5503 |
CommonOps.compoundOp(this.op, op)); |
5504 |
} |
5505 |
|
5506 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
5507 |
(IntAndLongToObject<? extends V> mapper) { |
5508 |
return new LUOCPap<V>(ex, origin, fence, array, |
5509 |
compoundIndexedOp(this.op, mapper)); |
5510 |
} |
5511 |
|
5512 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
5513 |
(IntAndLongToDouble mapper) { |
5514 |
return new LUDCPap(ex, origin, fence, array, |
5515 |
compoundIndexedOp(this.op, mapper)); |
5516 |
} |
5517 |
|
5518 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
5519 |
(IntAndLongToLong mapper) { |
5520 |
return new LULCPap(ex, origin, fence, array, |
5521 |
compoundIndexedOp(this.op, mapper)); |
5522 |
} |
5523 |
|
5524 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
5525 |
final LongOp f = op; |
5526 |
final long[] a = this.array; |
5527 |
for (int i = lo; i < hi; ++i) |
5528 |
procedure.op(f.op(a[i])); |
5529 |
} |
5530 |
|
5531 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
5532 |
if (lo >= hi) |
5533 |
return base; |
5534 |
final long[] a = this.array; |
5535 |
final LongOp f = op; |
5536 |
long r = f.op(a[lo]); |
5537 |
for (int i = lo+1; i < hi; ++i) |
5538 |
r = reducer.op(r, f.op(a[i])); |
5539 |
return r; |
5540 |
} |
5541 |
} |
5542 |
|
5543 |
// long-combined, filtered |
5544 |
static final class OFLMPap<T> extends OLMPap<T> { |
5545 |
final Predicate<? super T> selector; |
5546 |
OFLMPap(ForkJoinExecutor ex, int origin, int fence, |
5547 |
T[] array, Predicate<? super T> selector, |
5548 |
ObjectToLong<? super T> op) { |
5549 |
super(ex, origin, fence, array, op); |
5550 |
this.selector = selector; |
5551 |
} |
5552 |
|
5553 |
boolean hasFilter() { return true; } |
5554 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
5555 |
|
5556 |
public ParallelArrayWithDoubleMapping<T> withMapping |
5557 |
(LongToDouble op) { |
5558 |
return new OFDMPap<T>(ex, origin, fence, array, selector, |
5559 |
CommonOps.compoundOp(this.op, op)); |
5560 |
} |
5561 |
|
5562 |
public ParallelArrayWithLongMapping<T> withMapping |
5563 |
(LongOp op) { |
5564 |
return new OFLMPap<T>(ex, origin, fence, array, selector, |
5565 |
CommonOps.compoundOp(this.op, op)); |
5566 |
} |
5567 |
|
5568 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
5569 |
(LongToObject<? extends U> op) { |
5570 |
return new OFOMPap<T,U>(ex, origin, fence, array, selector, |
5571 |
CommonOps.compoundOp(this.op, op)); |
5572 |
} |
5573 |
|
5574 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
5575 |
(IntAndLongToObject<? extends V> mapper) { |
5576 |
return new OFOCPap<T,V>(ex, origin, fence, array, selector, |
5577 |
compoundIndexedOp(this.op, mapper)); |
5578 |
} |
5579 |
|
5580 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
5581 |
(IntAndLongToDouble mapper) { |
5582 |
return new OFDCPap<T>(ex, origin, fence, array, selector, |
5583 |
compoundIndexedOp(this.op, mapper)); |
5584 |
} |
5585 |
|
5586 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
5587 |
(IntAndLongToLong mapper) { |
5588 |
return new OFLCPap<T>(ex, origin, fence, array, selector, |
5589 |
compoundIndexedOp(this.op, mapper)); |
5590 |
} |
5591 |
|
5592 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
5593 |
final Predicate s = selector; |
5594 |
final Object[] a = this.array; |
5595 |
final ObjectToLong f = op; |
5596 |
for (int i = lo; i < hi; ++i) { |
5597 |
Object x = a[i]; |
5598 |
if (s.op(x)) |
5599 |
procedure.op(f.op(x)); |
5600 |
} |
5601 |
} |
5602 |
|
5603 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
5604 |
final Predicate s = selector; |
5605 |
final ObjectToLong f = op; |
5606 |
boolean gotFirst = false; |
5607 |
long r = base; |
5608 |
final Object[] a = this.array; |
5609 |
for (int i = lo; i < hi; ++i) { |
5610 |
Object t = a[i]; |
5611 |
if (s.op(t)) { |
5612 |
long y = f.op(t); |
5613 |
if (!gotFirst) { |
5614 |
gotFirst = true; |
5615 |
r = y; |
5616 |
} |
5617 |
else |
5618 |
r = reducer.op(r, y); |
5619 |
} |
5620 |
} |
5621 |
return r; |
5622 |
} |
5623 |
} |
5624 |
|
5625 |
static final class DFLMPap extends DLMPap { |
5626 |
final DoublePredicate selector; |
5627 |
DFLMPap(ForkJoinExecutor ex, int origin, int fence, |
5628 |
double[] array, DoublePredicate selector, DoubleToLong op) { |
5629 |
super(ex, origin, fence, array, op); |
5630 |
this.selector = selector; |
5631 |
} |
5632 |
|
5633 |
boolean hasFilter() { return true; } |
5634 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
5635 |
|
5636 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
5637 |
(LongToDouble op) { |
5638 |
return new DFDMPap(ex, origin, fence, array, selector, |
5639 |
CommonOps.compoundOp(this.op, op)); |
5640 |
} |
5641 |
|
5642 |
public ParallelDoubleArrayWithLongMapping withMapping |
5643 |
(LongOp op) { |
5644 |
return new DFLMPap(ex, origin, fence, array, selector, |
5645 |
CommonOps.compoundOp(this.op, op)); |
5646 |
} |
5647 |
|
5648 |
public <U> ParallelDoubleArrayWithMapping<U> withMapping |
5649 |
(LongToObject<? extends U> op) { |
5650 |
return new DFOMPap<U>(ex, origin, fence, array, selector, |
5651 |
CommonOps.compoundOp(this.op, op)); |
5652 |
} |
5653 |
|
5654 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
5655 |
(IntAndLongToObject<? extends V> mapper) { |
5656 |
return new DFOCPap<V>(ex, origin, fence, array, selector, |
5657 |
compoundIndexedOp(this.op, mapper)); |
5658 |
} |
5659 |
|
5660 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
5661 |
(IntAndLongToDouble mapper) { |
5662 |
return new DFDCPap(ex, origin, fence, array, selector, |
5663 |
compoundIndexedOp(this.op, mapper)); |
5664 |
} |
5665 |
|
5666 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
5667 |
(IntAndLongToLong mapper) { |
5668 |
return new DFLCPap(ex, origin, fence, array, selector, |
5669 |
compoundIndexedOp(this.op, mapper)); |
5670 |
} |
5671 |
|
5672 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
5673 |
final DoublePredicate s = selector; |
5674 |
final DoubleToLong f = op; |
5675 |
final double[] a = this.array; |
5676 |
for (int i = lo; i < hi; ++i) { |
5677 |
double x = a[i]; |
5678 |
if (s.op(x)) |
5679 |
procedure.op(f.op(x)); |
5680 |
} |
5681 |
} |
5682 |
|
5683 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
5684 |
boolean gotFirst = false; |
5685 |
long r = base; |
5686 |
final double[] a = this.array; |
5687 |
final DoublePredicate s = selector; |
5688 |
final DoubleToLong f = op; |
5689 |
for (int i = lo; i < hi; ++i) { |
5690 |
double t = a[i]; |
5691 |
if (s.op(t)) { |
5692 |
long y = f.op(t); |
5693 |
if (!gotFirst) { |
5694 |
gotFirst = true; |
5695 |
r = y; |
5696 |
} |
5697 |
else |
5698 |
r = reducer.op(r, y); |
5699 |
} |
5700 |
} |
5701 |
return r; |
5702 |
} |
5703 |
} |
5704 |
|
5705 |
static final class LFLMPap extends LLMPap { |
5706 |
final LongPredicate selector; |
5707 |
LFLMPap(ForkJoinExecutor ex, int origin, int fence, |
5708 |
long[] array, LongPredicate selector, LongOp op) { |
5709 |
super(ex, origin, fence, array, op); |
5710 |
this.selector = selector; |
5711 |
} |
5712 |
|
5713 |
boolean hasFilter() { return true; } |
5714 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
5715 |
|
5716 |
public ParallelLongArrayWithLongMapping withMapping(LongOp op) { |
5717 |
return new LFLMPap(ex, origin, fence, array, selector, |
5718 |
CommonOps.compoundOp(this.op, op)); |
5719 |
} |
5720 |
|
5721 |
public ParallelLongArrayWithDoubleMapping withMapping(LongToDouble op) { |
5722 |
return new LFDMPap(ex, origin, fence, array, selector, |
5723 |
CommonOps.compoundOp(this.op, op)); |
5724 |
} |
5725 |
|
5726 |
public <U> ParallelLongArrayWithMapping<U> withMapping |
5727 |
(LongToObject<? extends U> op) { |
5728 |
return new LFOMPap<U>(ex, origin, fence, array, selector, |
5729 |
CommonOps.compoundOp(this.op, op)); |
5730 |
} |
5731 |
|
5732 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
5733 |
(IntAndLongToObject<? extends V> mapper) { |
5734 |
return new LFOCPap<V>(ex, origin, fence, array, selector, |
5735 |
compoundIndexedOp(this.op, mapper)); |
5736 |
} |
5737 |
|
5738 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
5739 |
(IntAndLongToDouble mapper) { |
5740 |
return new LFDCPap(ex, origin, fence, array, selector, |
5741 |
compoundIndexedOp(this.op, mapper)); |
5742 |
} |
5743 |
|
5744 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
5745 |
(IntAndLongToLong mapper) { |
5746 |
return new LFLCPap(ex, origin, fence, array, selector, |
5747 |
compoundIndexedOp(this.op, mapper)); |
5748 |
} |
5749 |
|
5750 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
5751 |
final LongPredicate s = selector; |
5752 |
final LongOp f = op; |
5753 |
final long[] a = this.array; |
5754 |
for (int i = lo; i < hi; ++i) { |
5755 |
long x = a[i]; |
5756 |
if (s.op(x)) |
5757 |
procedure.op(f.op(x)); |
5758 |
} |
5759 |
} |
5760 |
|
5761 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
5762 |
final LongPredicate s = selector; |
5763 |
final LongOp f = op; |
5764 |
boolean gotFirst = false; |
5765 |
long r = base; |
5766 |
final long[] a = this.array; |
5767 |
for (int i = lo; i < hi; ++i) { |
5768 |
long t = a[i]; |
5769 |
if (s.op(t)) { |
5770 |
long y = f.op(t); |
5771 |
if (!gotFirst) { |
5772 |
gotFirst = true; |
5773 |
r = y; |
5774 |
} |
5775 |
else |
5776 |
r = reducer.op(r, y); |
5777 |
} |
5778 |
} |
5779 |
return r; |
5780 |
} |
5781 |
} |
5782 |
|
5783 |
// Long-mapped, relational |
5784 |
static final class ORLMPap<T> extends OLMPap<T> { |
5785 |
final IntAndObjectPredicate<? super T> selector; |
5786 |
ORLMPap(ForkJoinExecutor ex, int origin, int fence, |
5787 |
T[] array, IntAndObjectPredicate<? super T> selector, |
5788 |
ObjectToLong<? super T> op) { |
5789 |
super(ex, origin, fence, array, op); |
5790 |
this.selector = selector; |
5791 |
} |
5792 |
|
5793 |
boolean hasFilter() { return true; } |
5794 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
5795 |
|
5796 |
public ParallelArrayWithDoubleMapping<T> withMapping |
5797 |
(LongToDouble op) { |
5798 |
return new ORDMPap<T>(ex, origin, fence, array, selector, |
5799 |
CommonOps.compoundOp(this.op, op)); |
5800 |
} |
5801 |
|
5802 |
public ParallelArrayWithLongMapping<T> withMapping |
5803 |
(LongOp op) { |
5804 |
return new ORLMPap<T>(ex, origin, fence, array, selector, |
5805 |
CommonOps.compoundOp(this.op, op)); |
5806 |
} |
5807 |
|
5808 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
5809 |
(LongToObject<? extends U> op) { |
5810 |
return new OROMPap<T,U>(ex, origin, fence, array, selector, |
5811 |
CommonOps.compoundOp(this.op, op)); |
5812 |
} |
5813 |
|
5814 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
5815 |
(IntAndLongToObject<? extends V> mapper) { |
5816 |
return new OROCPap<T,V>(ex, origin, fence, array, selector, |
5817 |
compoundIndexedOp(this.op, mapper)); |
5818 |
} |
5819 |
|
5820 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
5821 |
(IntAndLongToDouble mapper) { |
5822 |
return new ORDCPap<T>(ex, origin, fence, array, selector, |
5823 |
compoundIndexedOp(this.op, mapper)); |
5824 |
} |
5825 |
|
5826 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
5827 |
(IntAndLongToLong mapper) { |
5828 |
return new ORLCPap<T>(ex, origin, fence, array, selector, |
5829 |
compoundIndexedOp(this.op, mapper)); |
5830 |
} |
5831 |
|
5832 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
5833 |
final IntAndObjectPredicate s = selector; |
5834 |
final Object[] a = this.array; |
5835 |
final ObjectToLong f = op; |
5836 |
for (int i = lo; i < hi; ++i) { |
5837 |
Object x = a[i]; |
5838 |
if (s.op(i, x)) |
5839 |
procedure.op(f.op(x)); |
5840 |
} |
5841 |
} |
5842 |
|
5843 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
5844 |
final IntAndObjectPredicate s = selector; |
5845 |
final ObjectToLong f = op; |
5846 |
boolean gotFirst = false; |
5847 |
long r = base; |
5848 |
final Object[] a = this.array; |
5849 |
for (int i = lo; i < hi; ++i) { |
5850 |
Object t = a[i]; |
5851 |
if (s.op(i, t)) { |
5852 |
long y = f.op(t); |
5853 |
if (!gotFirst) { |
5854 |
gotFirst = true; |
5855 |
r = y; |
5856 |
} |
5857 |
else |
5858 |
r = reducer.op(r, y); |
5859 |
} |
5860 |
} |
5861 |
return r; |
5862 |
} |
5863 |
} |
5864 |
|
5865 |
static final class DRLMPap extends DLMPap { |
5866 |
final IntAndDoublePredicate selector; |
5867 |
DRLMPap(ForkJoinExecutor ex, int origin, int fence, double[] array, |
5868 |
IntAndDoublePredicate selector, DoubleToLong op) { |
5869 |
super(ex, origin, fence, array, op); |
5870 |
this.selector = selector; |
5871 |
} |
5872 |
|
5873 |
boolean hasFilter() { return true; } |
5874 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
5875 |
|
5876 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
5877 |
(LongToDouble op) { |
5878 |
return new DRDMPap(ex, origin, fence, array, selector, |
5879 |
CommonOps.compoundOp(this.op, op)); |
5880 |
} |
5881 |
|
5882 |
public ParallelDoubleArrayWithLongMapping withMapping |
5883 |
(LongOp op) { |
5884 |
return new DRLMPap(ex, origin, fence, array, selector, |
5885 |
CommonOps.compoundOp(this.op, op)); |
5886 |
} |
5887 |
|
5888 |
public <U> ParallelDoubleArrayWithMapping<U> withMapping |
5889 |
(LongToObject<? extends U> op) { |
5890 |
return new DROMPap<U>(ex, origin, fence, array, selector, |
5891 |
CommonOps.compoundOp(this.op, op)); |
5892 |
} |
5893 |
|
5894 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
5895 |
(IntAndLongToObject<? extends V> mapper) { |
5896 |
return new DROCPap<V>(ex, origin, fence, array, selector, |
5897 |
compoundIndexedOp(this.op, mapper)); |
5898 |
} |
5899 |
|
5900 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
5901 |
(IntAndLongToDouble mapper) { |
5902 |
return new DRDCPap(ex, origin, fence, array, selector, |
5903 |
compoundIndexedOp(this.op, mapper)); |
5904 |
} |
5905 |
|
5906 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
5907 |
(IntAndLongToLong mapper) { |
5908 |
return new DRLCPap(ex, origin, fence, array, selector, |
5909 |
compoundIndexedOp(this.op, mapper)); |
5910 |
} |
5911 |
|
5912 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
5913 |
final IntAndDoublePredicate s = selector; |
5914 |
final DoubleToLong f = op; |
5915 |
final double[] a = this.array; |
5916 |
for (int i = lo; i < hi; ++i) { |
5917 |
double x = a[i]; |
5918 |
if (s.op(i, x)) |
5919 |
procedure.op(f.op(x)); |
5920 |
} |
5921 |
} |
5922 |
|
5923 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
5924 |
boolean gotFirst = false; |
5925 |
long r = base; |
5926 |
final double[] a = this.array; |
5927 |
final IntAndDoublePredicate s = selector; |
5928 |
final DoubleToLong f = op; |
5929 |
for (int i = lo; i < hi; ++i) { |
5930 |
double t = a[i]; |
5931 |
if (s.op(i, t)) { |
5932 |
long y = f.op(t); |
5933 |
if (!gotFirst) { |
5934 |
gotFirst = true; |
5935 |
r = y; |
5936 |
} |
5937 |
else |
5938 |
r = reducer.op(r, y); |
5939 |
} |
5940 |
} |
5941 |
return r; |
5942 |
} |
5943 |
} |
5944 |
|
5945 |
static final class LRLMPap extends LLMPap { |
5946 |
final IntAndLongPredicate selector; |
5947 |
LRLMPap(ForkJoinExecutor ex, int origin, int fence, |
5948 |
long[] array, IntAndLongPredicate selector, LongOp op) { |
5949 |
super(ex, origin, fence, array, op); |
5950 |
this.selector = selector; |
5951 |
} |
5952 |
|
5953 |
boolean hasFilter() { return true; } |
5954 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
5955 |
|
5956 |
public ParallelLongArrayWithLongMapping withMapping(LongOp op) { |
5957 |
return new LRLMPap(ex, origin, fence, array, selector, |
5958 |
CommonOps.compoundOp(this.op, op)); |
5959 |
} |
5960 |
|
5961 |
public ParallelLongArrayWithDoubleMapping withMapping(LongToDouble op) { |
5962 |
return new LRDMPap(ex, origin, fence, array, selector, |
5963 |
CommonOps.compoundOp(this.op, op)); |
5964 |
} |
5965 |
|
5966 |
public <U> ParallelLongArrayWithMapping<U> withMapping |
5967 |
(LongToObject<? extends U> op) { |
5968 |
return new LROMPap<U>(ex, origin, fence, array, selector, |
5969 |
CommonOps.compoundOp(this.op, op)); |
5970 |
} |
5971 |
|
5972 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
5973 |
(IntAndLongToObject<? extends V> mapper) { |
5974 |
return new LROCPap<V>(ex, origin, fence, array, selector, |
5975 |
compoundIndexedOp(this.op, mapper)); |
5976 |
} |
5977 |
|
5978 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
5979 |
(IntAndLongToDouble mapper) { |
5980 |
return new LRDCPap(ex, origin, fence, array, selector, |
5981 |
compoundIndexedOp(this.op, mapper)); |
5982 |
} |
5983 |
|
5984 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
5985 |
(IntAndLongToLong mapper) { |
5986 |
return new LRLCPap(ex, origin, fence, array, selector, |
5987 |
compoundIndexedOp(this.op, mapper)); |
5988 |
} |
5989 |
|
5990 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
5991 |
final IntAndLongPredicate s = selector; |
5992 |
final LongOp f = op; |
5993 |
final long[] a = this.array; |
5994 |
for (int i = lo; i < hi; ++i) { |
5995 |
long x = a[i]; |
5996 |
if (s.op(i, x)) |
5997 |
procedure.op(f.op(x)); |
5998 |
} |
5999 |
} |
6000 |
|
6001 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6002 |
final IntAndLongPredicate s = selector; |
6003 |
final LongOp f = op; |
6004 |
boolean gotFirst = false; |
6005 |
long r = base; |
6006 |
final long[] a = this.array; |
6007 |
for (int i = lo; i < hi; ++i) { |
6008 |
long t = a[i]; |
6009 |
if (s.op(i, t)) { |
6010 |
long y = f.op(t); |
6011 |
if (!gotFirst) { |
6012 |
gotFirst = true; |
6013 |
r = y; |
6014 |
} |
6015 |
else |
6016 |
r = reducer.op(r, y); |
6017 |
} |
6018 |
} |
6019 |
return r; |
6020 |
} |
6021 |
} |
6022 |
|
6023 |
// long-combined |
6024 |
static abstract class OLCPap<T> extends ParallelArrayWithLongMapping<T> { |
6025 |
final IntAndObjectToLong<? super T> op; |
6026 |
OLCPap(ForkJoinExecutor ex, int origin, int fence, |
6027 |
T[] array, IntAndObjectToLong<? super T> op) { |
6028 |
super(ex, origin, fence, array); |
6029 |
this.op = op; |
6030 |
} |
6031 |
|
6032 |
final boolean hasMap() { return true; } |
6033 |
final long lget(int i) { return op.op(i, this.array[i]); } |
6034 |
final Object oget(int i) { return Long.valueOf(lget(i)); } |
6035 |
final double dget(int i) { return (double)(lget(i)); } |
6036 |
|
6037 |
final void leafTransfer(int lo, int hi, long[] dest, int offset) { |
6038 |
final IntAndObjectToLong f = op; |
6039 |
final Object[] a = this.array; |
6040 |
for (int i = lo; i < hi; ++i) |
6041 |
dest[offset++] = f.op(i, a[i]); |
6042 |
} |
6043 |
|
6044 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
6045 |
long[] dest, int offset) { |
6046 |
final Object[] a = this.array; |
6047 |
final IntAndObjectToLong f = op; |
6048 |
for (int i = loIdx; i < hiIdx; ++i) { |
6049 |
int idx = indices[i]; |
6050 |
dest[offset++] = f.op(idx, a[idx]); |
6051 |
} |
6052 |
} |
6053 |
} |
6054 |
|
6055 |
static abstract class DLCPap extends ParallelDoubleArrayWithLongMapping { |
6056 |
final IntAndDoubleToLong op; |
6057 |
DLCPap(ForkJoinExecutor ex, int origin, int fence, |
6058 |
double[] array, IntAndDoubleToLong op) { |
6059 |
super(ex, origin, fence, array); |
6060 |
this.op = op; |
6061 |
} |
6062 |
|
6063 |
final boolean hasMap() { return true; } |
6064 |
final long lget(int i) { return op.op(i, this.array[i]); } |
6065 |
final Object oget(int i) { return Long.valueOf(lget(i)); } |
6066 |
final double dget(int i) { return (double)(lget(i)); } |
6067 |
|
6068 |
final void leafTransfer(int lo, int hi, long[] dest, int offset) { |
6069 |
final IntAndDoubleToLong f = op; |
6070 |
final double[] a = this.array; |
6071 |
for (int i = lo; i < hi; ++i) |
6072 |
dest[offset++] = f.op(i, a[i]); |
6073 |
} |
6074 |
|
6075 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
6076 |
long[] dest, int offset) { |
6077 |
final double[] a = this.array; |
6078 |
final IntAndDoubleToLong f = op; |
6079 |
for (int i = loIdx; i < hiIdx; ++i) { |
6080 |
int idx = indices[i]; |
6081 |
dest[offset++] = f.op(idx, a[idx]); |
6082 |
} |
6083 |
} |
6084 |
} |
6085 |
|
6086 |
static abstract class LLCPap extends ParallelLongArrayWithLongMapping { |
6087 |
final IntAndLongToLong op; |
6088 |
LLCPap(ForkJoinExecutor ex, int origin, int fence, |
6089 |
long[] array, IntAndLongToLong op) { |
6090 |
super(ex, origin, fence, array); |
6091 |
this.op = op; |
6092 |
} |
6093 |
|
6094 |
final boolean hasMap() { return true; } |
6095 |
final long lget(int i) { return op.op(i, this.array[i]); } |
6096 |
final Object oget(int i) { return Long.valueOf(lget(i)); } |
6097 |
final double dget(int i) { return (double)(lget(i)); } |
6098 |
|
6099 |
final void leafTransfer(int lo, int hi, long[] dest, int offset) { |
6100 |
final IntAndLongToLong f = op; |
6101 |
final long[] a = this.array; |
6102 |
for (int i = lo; i < hi; ++i) |
6103 |
dest[offset++] = f.op(i, a[i]); |
6104 |
} |
6105 |
|
6106 |
final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx, |
6107 |
long[] dest, int offset) { |
6108 |
final long[] a = this.array; |
6109 |
final IntAndLongToLong f = op; |
6110 |
for (int i = loIdx; i < hiIdx; ++i) { |
6111 |
int idx = indices[i]; |
6112 |
dest[offset++] = f.op(idx, a[idx]); |
6113 |
} |
6114 |
} |
6115 |
} |
6116 |
|
6117 |
// long-combined, unfiltered |
6118 |
static final class OULCPap<T> extends OLCPap<T> { |
6119 |
OULCPap(ForkJoinExecutor ex, int origin, int fence, |
6120 |
T[] array, IntAndObjectToLong<? super T> op) { |
6121 |
super(ex, origin, fence, array, op); |
6122 |
} |
6123 |
|
6124 |
public ParallelArrayWithDoubleMapping<T> withMapping(LongToDouble op) { |
6125 |
return new OUDCPap<T>(ex, origin, fence, array, |
6126 |
compoundIndexedOp(this.op, op)); |
6127 |
} |
6128 |
|
6129 |
public ParallelArrayWithLongMapping<T> withMapping(LongOp op) { |
6130 |
return new OULCPap<T>(ex, origin, fence, array, |
6131 |
compoundIndexedOp(this.op, op)); |
6132 |
} |
6133 |
|
6134 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
6135 |
(LongToObject<? extends U> op) { |
6136 |
return new OUOCPap<T,U>(ex, origin, fence, array, |
6137 |
compoundIndexedOp(this.op, op)); |
6138 |
} |
6139 |
|
6140 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
6141 |
(IntAndLongToObject<? extends V> mapper) { |
6142 |
return new OUOCPap<T,V>(ex, origin, fence, array, |
6143 |
compoundIndexedOp(this.op, mapper)); |
6144 |
} |
6145 |
|
6146 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
6147 |
(IntAndLongToDouble mapper) { |
6148 |
return new OUDCPap<T>(ex, origin, fence, array, |
6149 |
compoundIndexedOp(this.op, mapper)); |
6150 |
} |
6151 |
|
6152 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
6153 |
(IntAndLongToLong mapper) { |
6154 |
return new OULCPap<T>(ex, origin, fence, array, |
6155 |
compoundIndexedOp(this.op, mapper)); |
6156 |
} |
6157 |
|
6158 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
6159 |
final IntAndObjectToLong f = op; |
6160 |
final Object[] a = this.array; |
6161 |
for (int i = lo; i < hi; ++i) |
6162 |
procedure.op(f.op(i, a[i])); |
6163 |
} |
6164 |
|
6165 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6166 |
if (lo >= hi) |
6167 |
return base; |
6168 |
final Object[] a = this.array; |
6169 |
final IntAndObjectToLong f = op; |
6170 |
long r = f.op(lo, a[lo]); |
6171 |
for (int i = lo+1; i < hi; ++i) |
6172 |
r = reducer.op(r, f.op(i, a[i])); |
6173 |
return r; |
6174 |
} |
6175 |
|
6176 |
} |
6177 |
static final class DULCPap extends DLCPap { |
6178 |
DULCPap(ForkJoinExecutor ex, int origin, int fence, |
6179 |
double[] array, IntAndDoubleToLong op) { |
6180 |
super(ex, origin, fence, array, op); |
6181 |
} |
6182 |
|
6183 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
6184 |
(LongToDouble op) { |
6185 |
return new DUDCPap(ex, origin, fence, array, |
6186 |
compoundIndexedOp(this.op, op)); |
6187 |
} |
6188 |
|
6189 |
public ParallelDoubleArrayWithLongMapping withMapping(LongOp op) { |
6190 |
return new DULCPap(ex, origin, fence, array, |
6191 |
compoundIndexedOp(this.op, op)); |
6192 |
} |
6193 |
|
6194 |
public <U> ParallelDoubleArrayWithMapping< U> withMapping |
6195 |
(LongToObject<? extends U> op) { |
6196 |
return new DUOCPap<U>(ex, origin, fence, array, |
6197 |
compoundIndexedOp(this.op, op)); |
6198 |
} |
6199 |
|
6200 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
6201 |
(IntAndLongToObject<? extends V> mapper) { |
6202 |
return new DUOCPap<V>(ex, origin, fence, array, |
6203 |
compoundIndexedOp(this.op, mapper)); |
6204 |
} |
6205 |
|
6206 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
6207 |
(IntAndLongToDouble mapper) { |
6208 |
return new DUDCPap(ex, origin, fence, array, |
6209 |
compoundIndexedOp(this.op, mapper)); |
6210 |
} |
6211 |
|
6212 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
6213 |
(IntAndLongToLong mapper) { |
6214 |
return new DULCPap(ex, origin, fence, array, |
6215 |
compoundIndexedOp(this.op, mapper)); |
6216 |
} |
6217 |
|
6218 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
6219 |
final IntAndDoubleToLong f = op; |
6220 |
final double[] a = this.array; |
6221 |
for (int i = lo; i < hi; ++i) |
6222 |
procedure.op(f.op(i, a[i])); |
6223 |
} |
6224 |
|
6225 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6226 |
if (lo >= hi) |
6227 |
return base; |
6228 |
final double[] a = this.array; |
6229 |
final IntAndDoubleToLong f = op; |
6230 |
long r = f.op(lo, a[lo]); |
6231 |
for (int i = lo+1; i < hi; ++i) |
6232 |
r = reducer.op(r, f.op(i, a[i])); |
6233 |
return r; |
6234 |
} |
6235 |
} |
6236 |
|
6237 |
static final class LULCPap extends LLCPap { |
6238 |
LULCPap(ForkJoinExecutor ex, int origin, int fence, |
6239 |
long[] array, IntAndLongToLong op) { |
6240 |
super(ex, origin, fence, array, op); |
6241 |
} |
6242 |
|
6243 |
public ParallelLongArrayWithDoubleMapping withMapping(LongToDouble op) { |
6244 |
return new LUDCPap(ex, origin, fence, array, |
6245 |
compoundIndexedOp(this.op, op)); |
6246 |
} |
6247 |
|
6248 |
public ParallelLongArrayWithLongMapping withMapping(LongOp op) { |
6249 |
return new LULCPap(ex, origin, fence, array, |
6250 |
compoundIndexedOp(this.op, op)); |
6251 |
} |
6252 |
|
6253 |
public <U> ParallelLongArrayWithMapping< U> withMapping |
6254 |
(LongToObject<? extends U> op) { |
6255 |
return new LUOCPap<U>(ex, origin, fence, array, |
6256 |
compoundIndexedOp(this.op, op)); |
6257 |
} |
6258 |
|
6259 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
6260 |
(IntAndLongToObject<? extends V> mapper) { |
6261 |
return new LUOCPap<V>(ex, origin, fence, array, |
6262 |
compoundIndexedOp(this.op, mapper)); |
6263 |
} |
6264 |
|
6265 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
6266 |
(IntAndLongToDouble mapper) { |
6267 |
return new LUDCPap(ex, origin, fence, array, |
6268 |
compoundIndexedOp(this.op, mapper)); |
6269 |
} |
6270 |
|
6271 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
6272 |
(IntAndLongToLong mapper) { |
6273 |
return new LULCPap(ex, origin, fence, array, |
6274 |
compoundIndexedOp(this.op, mapper)); |
6275 |
} |
6276 |
|
6277 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
6278 |
final IntAndLongToLong f = op; |
6279 |
final long[] a = this.array; |
6280 |
for (int i = lo; i < hi; ++i) |
6281 |
procedure.op(f.op(i, a[i])); |
6282 |
} |
6283 |
|
6284 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6285 |
if (lo >= hi) |
6286 |
return base; |
6287 |
final long[] a = this.array; |
6288 |
final IntAndLongToLong f = op; |
6289 |
long r = f.op(lo, a[lo]); |
6290 |
for (int i = lo+1; i < hi; ++i) |
6291 |
r = reducer.op(r, f.op(i, a[i])); |
6292 |
return r; |
6293 |
} |
6294 |
} |
6295 |
|
6296 |
// long-combined, filtered |
6297 |
static final class OFLCPap<T> extends OLCPap<T> { |
6298 |
final Predicate<? super T> selector; |
6299 |
OFLCPap(ForkJoinExecutor ex, int origin, int fence, |
6300 |
T[] array, Predicate<? super T> selector, |
6301 |
IntAndObjectToLong<? super T> op) { |
6302 |
super(ex, origin, fence, array, op); |
6303 |
this.selector = selector; |
6304 |
} |
6305 |
|
6306 |
boolean hasFilter() { return true; } |
6307 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
6308 |
|
6309 |
public ParallelArrayWithDoubleMapping<T> withMapping(LongToDouble op) { |
6310 |
return new OFDCPap<T>(ex, origin, fence, array, selector, |
6311 |
compoundIndexedOp(this.op, op)); |
6312 |
} |
6313 |
|
6314 |
public ParallelArrayWithLongMapping<T> withMapping(LongOp op) { |
6315 |
return new OFLCPap<T>(ex, origin, fence, array, selector, |
6316 |
compoundIndexedOp(this.op, op)); |
6317 |
} |
6318 |
|
6319 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
6320 |
(LongToObject<? extends U> op) { |
6321 |
return new OFOCPap<T,U>(ex, origin, fence, array, |
6322 |
selector, |
6323 |
compoundIndexedOp(this.op, op)); |
6324 |
} |
6325 |
|
6326 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
6327 |
(IntAndLongToObject<? extends V> mapper) { |
6328 |
return new OFOCPap<T,V>(ex, origin, fence, array, |
6329 |
selector, |
6330 |
compoundIndexedOp(this.op, mapper)); |
6331 |
} |
6332 |
|
6333 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
6334 |
(IntAndLongToDouble mapper) { |
6335 |
return new OFDCPap<T>(ex, origin, fence, array, selector, |
6336 |
compoundIndexedOp(this.op, mapper)); |
6337 |
} |
6338 |
|
6339 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
6340 |
(IntAndLongToLong mapper) { |
6341 |
return new OFLCPap<T>(ex, origin, fence, array, selector, |
6342 |
compoundIndexedOp(this.op, mapper)); |
6343 |
} |
6344 |
|
6345 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
6346 |
final Predicate s = selector; |
6347 |
final Object[] a = this.array; |
6348 |
final IntAndObjectToLong f = op; |
6349 |
for (int i = lo; i < hi; ++i) { |
6350 |
Object x = a[i]; |
6351 |
if (s.op(x)) |
6352 |
procedure.op(f.op(i, x)); |
6353 |
} |
6354 |
} |
6355 |
|
6356 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6357 |
final Predicate s = selector; |
6358 |
final IntAndObjectToLong f = op; |
6359 |
boolean gotFirst = false; |
6360 |
long r = base; |
6361 |
final Object[] a = this.array; |
6362 |
for (int i = lo; i < hi; ++i) { |
6363 |
Object t = a[i]; |
6364 |
if (s.op(t)) { |
6365 |
long y = f.op(i, t); |
6366 |
if (!gotFirst) { |
6367 |
gotFirst = true; |
6368 |
r = y; |
6369 |
} |
6370 |
else |
6371 |
r = reducer.op(r, y); |
6372 |
} |
6373 |
} |
6374 |
return r; |
6375 |
} |
6376 |
|
6377 |
} |
6378 |
|
6379 |
static final class DFLCPap extends DLCPap { |
6380 |
final DoublePredicate selector; |
6381 |
DFLCPap(ForkJoinExecutor ex, int origin, int fence, |
6382 |
double[] array, DoublePredicate selector, |
6383 |
IntAndDoubleToLong op) { |
6384 |
super(ex, origin, fence, array, op); |
6385 |
this.selector = selector; |
6386 |
} |
6387 |
|
6388 |
boolean hasFilter() { return true; } |
6389 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
6390 |
|
6391 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
6392 |
(LongToDouble op) { |
6393 |
return new DFDCPap(ex, origin, fence, array, selector, |
6394 |
compoundIndexedOp(this.op, op)); |
6395 |
} |
6396 |
|
6397 |
public ParallelDoubleArrayWithLongMapping withMapping(LongOp op) { |
6398 |
return new DFLCPap(ex, origin, fence, array, selector, |
6399 |
compoundIndexedOp(this.op, op)); |
6400 |
} |
6401 |
|
6402 |
public <U> ParallelDoubleArrayWithMapping< U> withMapping |
6403 |
(LongToObject<? extends U> op) { |
6404 |
return new DFOCPap<U>(ex, origin, fence, array, selector, |
6405 |
compoundIndexedOp(this.op, op)); |
6406 |
} |
6407 |
|
6408 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
6409 |
(IntAndLongToObject<? extends V> mapper) { |
6410 |
return new DFOCPap<V>(ex, origin, fence, array, selector, |
6411 |
compoundIndexedOp(this.op, mapper)); |
6412 |
} |
6413 |
|
6414 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
6415 |
(IntAndLongToDouble mapper) { |
6416 |
return new DFDCPap(ex, origin, fence, array, selector, |
6417 |
compoundIndexedOp(this.op, mapper)); |
6418 |
} |
6419 |
|
6420 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
6421 |
(IntAndLongToLong mapper) { |
6422 |
return new DFLCPap(ex, origin, fence, array, selector, |
6423 |
compoundIndexedOp(this.op, mapper)); |
6424 |
} |
6425 |
|
6426 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
6427 |
final DoublePredicate s = selector; |
6428 |
final double[] a = this.array; |
6429 |
final IntAndDoubleToLong f = op; |
6430 |
for (int i = lo; i < hi; ++i) { |
6431 |
double x = a[i]; |
6432 |
if (s.op(x)) |
6433 |
procedure.op(f.op(i, x)); |
6434 |
} |
6435 |
} |
6436 |
|
6437 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6438 |
final DoublePredicate s = selector; |
6439 |
final IntAndDoubleToLong f = op; |
6440 |
boolean gotFirst = false; |
6441 |
long r = base; |
6442 |
final double[] a = this.array; |
6443 |
for (int i = lo; i < hi; ++i) { |
6444 |
double t = a[i]; |
6445 |
if (s.op(t)) { |
6446 |
long y = f.op(i, t); |
6447 |
if (!gotFirst) { |
6448 |
gotFirst = true; |
6449 |
r = y; |
6450 |
} |
6451 |
else |
6452 |
r = reducer.op(r, y); |
6453 |
} |
6454 |
} |
6455 |
return r; |
6456 |
} |
6457 |
} |
6458 |
|
6459 |
static final class LFLCPap extends LLCPap { |
6460 |
final LongPredicate selector; |
6461 |
LFLCPap(ForkJoinExecutor ex, int origin, int fence, |
6462 |
long[] array, LongPredicate selector, |
6463 |
IntAndLongToLong op) { |
6464 |
super(ex, origin, fence, array, op); |
6465 |
this.selector = selector; |
6466 |
} |
6467 |
|
6468 |
boolean hasFilter() { return true; } |
6469 |
boolean isSelected(int i) { return selector.op(this.array[i]); } |
6470 |
|
6471 |
public ParallelLongArrayWithDoubleMapping withMapping(LongToDouble op) { |
6472 |
return new LFDCPap(ex, origin, fence, array, selector, |
6473 |
compoundIndexedOp(this.op, op)); |
6474 |
} |
6475 |
|
6476 |
public ParallelLongArrayWithLongMapping withMapping(LongOp op) { |
6477 |
return new LFLCPap(ex, origin, fence, array, selector, |
6478 |
compoundIndexedOp(this.op, op)); |
6479 |
} |
6480 |
|
6481 |
public <U> ParallelLongArrayWithMapping< U> withMapping |
6482 |
(LongToObject<? extends U> op) { |
6483 |
return new LFOCPap<U>(ex, origin, fence, array, selector, |
6484 |
compoundIndexedOp(this.op, op)); |
6485 |
} |
6486 |
|
6487 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
6488 |
(IntAndLongToObject<? extends V> mapper) { |
6489 |
return new LFOCPap<V>(ex, origin, fence, array, selector, |
6490 |
compoundIndexedOp(this.op, mapper)); |
6491 |
} |
6492 |
|
6493 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
6494 |
(IntAndLongToDouble mapper) { |
6495 |
return new LFDCPap(ex, origin, fence, array, selector, |
6496 |
compoundIndexedOp(this.op, mapper)); |
6497 |
} |
6498 |
|
6499 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
6500 |
(IntAndLongToLong mapper) { |
6501 |
return new LFLCPap(ex, origin, fence, array, selector, |
6502 |
compoundIndexedOp(this.op, mapper)); |
6503 |
} |
6504 |
|
6505 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
6506 |
final LongPredicate s = selector; |
6507 |
final long[] a = this.array; |
6508 |
final IntAndLongToLong f = op; |
6509 |
for (int i = lo; i < hi; ++i) { |
6510 |
long x = a[i]; |
6511 |
if (s.op(x)) |
6512 |
procedure.op(f.op(i, x)); |
6513 |
} |
6514 |
} |
6515 |
|
6516 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6517 |
final LongPredicate s = selector; |
6518 |
final IntAndLongToLong f = op; |
6519 |
boolean gotFirst = false; |
6520 |
long r = base; |
6521 |
final long[] a = this.array; |
6522 |
for (int i = lo; i < hi; ++i) { |
6523 |
long t = a[i]; |
6524 |
if (s.op(t)) { |
6525 |
long y = f.op(i, t); |
6526 |
if (!gotFirst) { |
6527 |
gotFirst = true; |
6528 |
r = y; |
6529 |
} |
6530 |
else |
6531 |
r = reducer.op(r, y); |
6532 |
} |
6533 |
} |
6534 |
return r; |
6535 |
} |
6536 |
} |
6537 |
|
6538 |
// long-combined, relational |
6539 |
static final class ORLCPap<T> extends OLCPap<T> { |
6540 |
final IntAndObjectPredicate<? super T> selector; |
6541 |
ORLCPap(ForkJoinExecutor ex, int origin, int fence, |
6542 |
T[] array, IntAndObjectPredicate<? super T> selector, |
6543 |
IntAndObjectToLong<? super T> op) { |
6544 |
super(ex, origin, fence, array, op); |
6545 |
this.selector = selector; |
6546 |
} |
6547 |
|
6548 |
boolean hasFilter() { return true; } |
6549 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
6550 |
|
6551 |
public ParallelArrayWithDoubleMapping<T> withMapping(LongToDouble op) { |
6552 |
return new ORDCPap<T>(ex, origin, fence, array, selector, |
6553 |
compoundIndexedOp(this.op, op)); |
6554 |
} |
6555 |
|
6556 |
public ParallelArrayWithLongMapping<T> withMapping(LongOp op) { |
6557 |
return new ORLCPap<T>(ex, origin, fence, array, selector, |
6558 |
compoundIndexedOp(this.op, op)); |
6559 |
} |
6560 |
|
6561 |
public <U> ParallelArrayWithMapping<T, U> withMapping |
6562 |
(LongToObject<? extends U> op) { |
6563 |
return new OROCPap<T,U>(ex, origin, fence, array, |
6564 |
selector, |
6565 |
compoundIndexedOp(this.op, op)); |
6566 |
} |
6567 |
|
6568 |
public <V> ParallelArrayWithMapping<T,V> withIndexedMapping |
6569 |
(IntAndLongToObject<? extends V> mapper) { |
6570 |
return new OROCPap<T,V>(ex, origin, fence, array, |
6571 |
selector, |
6572 |
compoundIndexedOp(this.op, mapper)); |
6573 |
} |
6574 |
|
6575 |
public ParallelArrayWithDoubleMapping<T> withIndexedMapping |
6576 |
(IntAndLongToDouble mapper) { |
6577 |
return new ORDCPap<T>(ex, origin, fence, array, selector, |
6578 |
compoundIndexedOp(this.op, mapper)); |
6579 |
} |
6580 |
|
6581 |
public ParallelArrayWithLongMapping<T> withIndexedMapping |
6582 |
(IntAndLongToLong mapper) { |
6583 |
return new ORLCPap<T>(ex, origin, fence, array, selector, |
6584 |
compoundIndexedOp(this.op, mapper)); |
6585 |
} |
6586 |
|
6587 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
6588 |
final IntAndObjectPredicate s = selector; |
6589 |
final Object[] a = this.array; |
6590 |
final IntAndObjectToLong f = op; |
6591 |
for (int i = lo; i < hi; ++i) { |
6592 |
Object x = a[i]; |
6593 |
if (s.op(i, x)) |
6594 |
procedure.op(f.op(i, x)); |
6595 |
} |
6596 |
} |
6597 |
|
6598 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6599 |
final IntAndObjectPredicate s = selector; |
6600 |
final IntAndObjectToLong f = op; |
6601 |
boolean gotFirst = false; |
6602 |
long r = base; |
6603 |
final Object[] a = this.array; |
6604 |
for (int i = lo; i < hi; ++i) { |
6605 |
Object t = a[i]; |
6606 |
if (s.op(i, t)) { |
6607 |
long y = f.op(i, t); |
6608 |
if (!gotFirst) { |
6609 |
gotFirst = true; |
6610 |
r = y; |
6611 |
} |
6612 |
else |
6613 |
r = reducer.op(r, y); |
6614 |
} |
6615 |
} |
6616 |
return r; |
6617 |
} |
6618 |
|
6619 |
} |
6620 |
|
6621 |
static final class DRLCPap extends DLCPap { |
6622 |
final IntAndDoublePredicate selector; |
6623 |
DRLCPap(ForkJoinExecutor ex, int origin, int fence, |
6624 |
double[] array, IntAndDoublePredicate selector, |
6625 |
IntAndDoubleToLong op) { |
6626 |
super(ex, origin, fence, array, op); |
6627 |
this.selector = selector; |
6628 |
} |
6629 |
|
6630 |
boolean hasFilter() { return true; } |
6631 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
6632 |
|
6633 |
public ParallelDoubleArrayWithDoubleMapping withMapping |
6634 |
(LongToDouble op) { |
6635 |
return new DRDCPap(ex, origin, fence, array, selector, |
6636 |
compoundIndexedOp(this.op, op)); |
6637 |
} |
6638 |
|
6639 |
public ParallelDoubleArrayWithLongMapping withMapping(LongOp op) { |
6640 |
return new DRLCPap(ex, origin, fence, array, selector, |
6641 |
compoundIndexedOp(this.op, op)); |
6642 |
} |
6643 |
|
6644 |
public <U> ParallelDoubleArrayWithMapping< U> withMapping |
6645 |
(LongToObject<? extends U> op) { |
6646 |
return new DROCPap<U>(ex, origin, fence, array, selector, |
6647 |
compoundIndexedOp(this.op, op)); |
6648 |
} |
6649 |
|
6650 |
public <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping |
6651 |
(IntAndLongToObject<? extends V> mapper) { |
6652 |
return new DROCPap<V>(ex, origin, fence, array, selector, |
6653 |
compoundIndexedOp(this.op, mapper)); |
6654 |
} |
6655 |
|
6656 |
public ParallelDoubleArrayWithDoubleMapping withIndexedMapping |
6657 |
(IntAndLongToDouble mapper) { |
6658 |
return new DRDCPap(ex, origin, fence, array, selector, |
6659 |
compoundIndexedOp(this.op, mapper)); |
6660 |
} |
6661 |
|
6662 |
public ParallelDoubleArrayWithLongMapping withIndexedMapping |
6663 |
(IntAndLongToLong mapper) { |
6664 |
return new DRLCPap(ex, origin, fence, array, selector, |
6665 |
compoundIndexedOp(this.op, mapper)); |
6666 |
} |
6667 |
|
6668 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
6669 |
final IntAndDoublePredicate s = selector; |
6670 |
final double[] a = this.array; |
6671 |
final IntAndDoubleToLong f = op; |
6672 |
for (int i = lo; i < hi; ++i) { |
6673 |
double x = a[i]; |
6674 |
if (s.op(i, x)) |
6675 |
procedure.op(f.op(i, x)); |
6676 |
} |
6677 |
} |
6678 |
|
6679 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6680 |
final IntAndDoublePredicate s = selector; |
6681 |
final IntAndDoubleToLong f = op; |
6682 |
boolean gotFirst = false; |
6683 |
long r = base; |
6684 |
final double[] a = this.array; |
6685 |
for (int i = lo; i < hi; ++i) { |
6686 |
double t = a[i]; |
6687 |
if (s.op(i, t)) { |
6688 |
long y = f.op(i, t); |
6689 |
if (!gotFirst) { |
6690 |
gotFirst = true; |
6691 |
r = y; |
6692 |
} |
6693 |
else |
6694 |
r = reducer.op(r, y); |
6695 |
} |
6696 |
} |
6697 |
return r; |
6698 |
} |
6699 |
} |
6700 |
|
6701 |
static final class LRLCPap extends LLCPap { |
6702 |
final IntAndLongPredicate selector; |
6703 |
LRLCPap(ForkJoinExecutor ex, int origin, int fence, |
6704 |
long[] array, IntAndLongPredicate selector, |
6705 |
IntAndLongToLong op) { |
6706 |
super(ex, origin, fence, array, op); |
6707 |
this.selector = selector; |
6708 |
} |
6709 |
|
6710 |
boolean hasFilter() { return true; } |
6711 |
boolean isSelected(int i) { return selector.op(i, this.array[i]); } |
6712 |
|
6713 |
public ParallelLongArrayWithDoubleMapping withMapping(LongToDouble op) { |
6714 |
return new LRDCPap(ex, origin, fence, array, selector, |
6715 |
compoundIndexedOp(this.op, op)); |
6716 |
} |
6717 |
|
6718 |
public ParallelLongArrayWithLongMapping withMapping(LongOp op) { |
6719 |
return new LRLCPap(ex, origin, fence, array, selector, |
6720 |
compoundIndexedOp(this.op, op)); |
6721 |
} |
6722 |
|
6723 |
public <U> ParallelLongArrayWithMapping< U> withMapping |
6724 |
(LongToObject<? extends U> op) { |
6725 |
return new LROCPap<U>(ex, origin, fence, array, selector, |
6726 |
compoundIndexedOp(this.op, op)); |
6727 |
} |
6728 |
|
6729 |
public <V> ParallelLongArrayWithMapping<V> withIndexedMapping |
6730 |
(IntAndLongToObject<? extends V> mapper) { |
6731 |
return new LROCPap<V>(ex, origin, fence, array, selector, |
6732 |
compoundIndexedOp(this.op, mapper)); |
6733 |
} |
6734 |
|
6735 |
public ParallelLongArrayWithDoubleMapping withIndexedMapping |
6736 |
(IntAndLongToDouble mapper) { |
6737 |
return new LRDCPap(ex, origin, fence, array, selector, |
6738 |
compoundIndexedOp(this.op, mapper)); |
6739 |
} |
6740 |
|
6741 |
public ParallelLongArrayWithLongMapping withIndexedMapping |
6742 |
(IntAndLongToLong mapper) { |
6743 |
return new LRLCPap(ex, origin, fence, array, selector, |
6744 |
compoundIndexedOp(this.op, mapper)); |
6745 |
} |
6746 |
|
6747 |
void leafApply(int lo, int hi, LongProcedure procedure) { |
6748 |
final IntAndLongPredicate s = selector; |
6749 |
final long[] a = this.array; |
6750 |
final IntAndLongToLong f = op; |
6751 |
for (int i = lo; i < hi; ++i) { |
6752 |
long x = a[i]; |
6753 |
if (s.op(i, x)) |
6754 |
procedure.op(f.op(i, x)); |
6755 |
} |
6756 |
} |
6757 |
|
6758 |
long leafReduce(int lo, int hi, LongReducer reducer, long base) { |
6759 |
final IntAndLongPredicate s = selector; |
6760 |
final IntAndLongToLong f = op; |
6761 |
boolean gotFirst = false; |
6762 |
long r = base; |
6763 |
final long[] a = this.array; |
6764 |
for (int i = lo; i < hi; ++i) { |
6765 |
long t = a[i]; |
6766 |
if (s.op(i, t)) { |
6767 |
long y = f.op(i, t); |
6768 |
if (!gotFirst) { |
6769 |
gotFirst = true; |
6770 |
r = y; |
6771 |
} |
6772 |
else |
6773 |
r = reducer.op(r, y); |
6774 |
} |
6775 |
} |
6776 |
return r; |
6777 |
} |
6778 |
} |
6779 |
|
6780 |
/* |
6781 |
* Iterator support |
6782 |
*/ |
6783 |
|
6784 |
class SequentiallyAsDouble implements Iterable<Double> { |
6785 |
public Iterator<Double> iterator() { |
6786 |
if (hasFilter()) |
6787 |
return new FilteredAsDoubleIterator(); |
6788 |
else |
6789 |
return new UnfilteredAsDoubleIterator(); |
6790 |
} |
6791 |
} |
6792 |
|
6793 |
class UnfilteredAsDoubleIterator implements Iterator<Double> { |
6794 |
int cursor = origin; |
6795 |
public boolean hasNext() { return cursor < fence; } |
6796 |
public Double next() { |
6797 |
if (cursor >= fence) |
6798 |
throw new NoSuchElementException(); |
6799 |
return Double.valueOf(dget(cursor++)); |
6800 |
} |
6801 |
public void remove() { |
6802 |
throw new UnsupportedOperationException(); |
6803 |
} |
6804 |
} |
6805 |
|
6806 |
class FilteredAsDoubleIterator implements Iterator<Double> { |
6807 |
double next; |
6808 |
int cursor; |
6809 |
FilteredAsDoubleIterator() { |
6810 |
cursor = origin; |
6811 |
advance() ; |
6812 |
} |
6813 |
private void advance() { |
6814 |
while (cursor < fence) { |
6815 |
if (isSelected(cursor)) { |
6816 |
next = dget(cursor); |
6817 |
break; |
6818 |
} |
6819 |
cursor++; |
6820 |
} |
6821 |
} |
6822 |
|
6823 |
public boolean hasNext() { return cursor < fence; } |
6824 |
public Double next() { |
6825 |
if (cursor >= fence) |
6826 |
throw new NoSuchElementException(); |
6827 |
Double x = Double.valueOf(next); |
6828 |
cursor++; |
6829 |
advance(); |
6830 |
return x; |
6831 |
} |
6832 |
public void remove() { |
6833 |
throw new UnsupportedOperationException(); |
6834 |
} |
6835 |
} |
6836 |
|
6837 |
class SequentiallyAsLong implements Iterable<Long> { |
6838 |
public Iterator<Long> iterator() { |
6839 |
if (hasFilter()) |
6840 |
return new FilteredAsLongIterator(); |
6841 |
else |
6842 |
return new UnfilteredAsLongIterator(); |
6843 |
} |
6844 |
} |
6845 |
|
6846 |
class UnfilteredAsLongIterator implements Iterator<Long> { |
6847 |
int cursor = origin; |
6848 |
public boolean hasNext() { return cursor < fence; } |
6849 |
public Long next() { |
6850 |
if (cursor >= fence) |
6851 |
throw new NoSuchElementException(); |
6852 |
return Long.valueOf(lget(cursor++)); |
6853 |
} |
6854 |
public void remove() { |
6855 |
throw new UnsupportedOperationException(); |
6856 |
} |
6857 |
} |
6858 |
|
6859 |
class FilteredAsLongIterator implements Iterator<Long> { |
6860 |
long next; |
6861 |
int cursor; |
6862 |
FilteredAsLongIterator() { |
6863 |
cursor = origin; |
6864 |
advance() ; |
6865 |
} |
6866 |
private void advance() { |
6867 |
while (cursor < fence) { |
6868 |
if (isSelected(cursor)) { |
6869 |
next = lget(cursor); |
6870 |
break; |
6871 |
} |
6872 |
cursor++; |
6873 |
} |
6874 |
} |
6875 |
|
6876 |
public boolean hasNext() { return cursor < fence; } |
6877 |
public Long next() { |
6878 |
if (cursor >= fence) |
6879 |
throw new NoSuchElementException(); |
6880 |
Long x = Long.valueOf(next); |
6881 |
cursor++; |
6882 |
advance(); |
6883 |
return x; |
6884 |
} |
6885 |
public void remove() { |
6886 |
throw new UnsupportedOperationException(); |
6887 |
} |
6888 |
} |
6889 |
|
6890 |
class Sequentially<U> implements Iterable<U> { |
6891 |
public Iterator<U> iterator() { |
6892 |
if (hasFilter()) |
6893 |
return new FilteredIterator<U>(); |
6894 |
else |
6895 |
return new UnfilteredIterator<U>(); |
6896 |
} |
6897 |
} |
6898 |
|
6899 |
class UnfilteredIterator<U> implements Iterator<U> { |
6900 |
int cursor = origin; |
6901 |
public boolean hasNext() { return cursor < fence; } |
6902 |
public U next() { |
6903 |
if (cursor >= fence) |
6904 |
throw new NoSuchElementException(); |
6905 |
return (U)oget(cursor++); |
6906 |
} |
6907 |
public void remove() { |
6908 |
throw new UnsupportedOperationException(); |
6909 |
} |
6910 |
} |
6911 |
|
6912 |
class FilteredIterator<U> implements Iterator<U> { |
6913 |
Object next; |
6914 |
int cursor; |
6915 |
FilteredIterator() { |
6916 |
cursor = origin; |
6917 |
advance() ; |
6918 |
} |
6919 |
private void advance() { |
6920 |
while (cursor < fence) { |
6921 |
if (isSelected(cursor)) { |
6922 |
next = oget(cursor); |
6923 |
break; |
6924 |
} |
6925 |
cursor++; |
6926 |
} |
6927 |
} |
6928 |
|
6929 |
public boolean hasNext() { return cursor < fence; } |
6930 |
public U next() { |
6931 |
if (cursor >= fence) |
6932 |
throw new NoSuchElementException(); |
6933 |
U x = (U)next; |
6934 |
cursor++; |
6935 |
advance(); |
6936 |
return x; |
6937 |
} |
6938 |
public void remove() { |
6939 |
throw new UnsupportedOperationException(); |
6940 |
} |
6941 |
} |
6942 |
|
6943 |
// Zillions of little classes to support binary ops |
6944 |
// ToDo: specialize to flatten dispatch |
6945 |
|
6946 |
static <T,U,V,W> IntAndObjectToObject<T,V> indexedMapper |
6947 |
(final BinaryOp<? super T, ? super U, ? extends V> combiner, |
6948 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
6949 |
return new IntAndObjectToObject<T,V>() { |
6950 |
final int offset = u.origin - origin; |
6951 |
public V op(int i, T a) { return combiner.op(a, (U)(u.oget(i+offset))); } |
6952 |
}; |
6953 |
} |
6954 |
|
6955 |
static <T,U,W> IntAndObjectToDouble<T> indexedMapper |
6956 |
(final ObjectAndObjectToDouble<? super T, ? super U> combiner, |
6957 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
6958 |
return new IntAndObjectToDouble<T>() { |
6959 |
final int offset = u.origin - origin; |
6960 |
public double op(int i, T a) { return combiner.op(a, (U)(u.oget(i+offset))); } |
6961 |
}; |
6962 |
} |
6963 |
|
6964 |
static <T,U,W> IntAndObjectToLong<T> indexedMapper |
6965 |
(final ObjectAndObjectToLong<? super T, ? super U> combiner, |
6966 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
6967 |
return new IntAndObjectToLong<T>() { |
6968 |
final int offset = u.origin - origin; |
6969 |
public long op(int i, T a) { return combiner.op(a, (U)(u.oget(i+offset))); } |
6970 |
}; |
6971 |
} |
6972 |
|
6973 |
static <T,V> IntAndObjectToObject<T,V> indexedMapper |
6974 |
(final ObjectAndDoubleToObject<? super T, ? extends V> combiner, |
6975 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
6976 |
return new IntAndObjectToObject<T,V>() { |
6977 |
final int offset = u.origin - origin; |
6978 |
public V op(int i, T a) { return combiner.op(a, u.dget(i+offset)); } |
6979 |
}; |
6980 |
} |
6981 |
|
6982 |
static <T> IntAndObjectToDouble<T> indexedMapper |
6983 |
(final ObjectAndDoubleToDouble<? super T> combiner, |
6984 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
6985 |
return new IntAndObjectToDouble<T>() { |
6986 |
final int offset = u.origin - origin; |
6987 |
public double op(int i, T a) { return combiner.op(a, u.dget(i+offset)); } |
6988 |
}; |
6989 |
} |
6990 |
|
6991 |
static <T,U> IntAndObjectToLong<T> indexedMapper |
6992 |
(final ObjectAndDoubleToLong<? super T> combiner, |
6993 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
6994 |
return new IntAndObjectToLong<T>() { |
6995 |
final int offset = u.origin - origin; |
6996 |
public long op(int i, T a) { return combiner.op(a, u.dget(i+offset)); } |
6997 |
}; |
6998 |
} |
6999 |
|
7000 |
static <T,V> IntAndObjectToObject<T,V> indexedMapper |
7001 |
(final ObjectAndLongToObject<? super T, ? extends V> combiner, |
7002 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7003 |
return new IntAndObjectToObject<T,V>() { |
7004 |
final int offset = u.origin - origin; |
7005 |
public V op(int i, T a) { return combiner.op(a, u.lget(i+offset)); } |
7006 |
}; |
7007 |
} |
7008 |
|
7009 |
static <T> IntAndObjectToDouble<T> indexedMapper |
7010 |
(final ObjectAndLongToDouble<? super T> combiner, |
7011 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7012 |
return new IntAndObjectToDouble<T>() { |
7013 |
final int offset = u.origin - origin; |
7014 |
public double op(int i, T a) { return combiner.op(a, u.lget(i+offset)); } |
7015 |
}; |
7016 |
} |
7017 |
|
7018 |
static <T> IntAndObjectToLong<T> indexedMapper |
7019 |
(final ObjectAndLongToLong<? super T> combiner, |
7020 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7021 |
return new IntAndObjectToLong<T>() { |
7022 |
final int offset = u.origin - origin; |
7023 |
public long op(int i, T a) { return combiner.op(a, u.lget(i+offset)); } |
7024 |
}; |
7025 |
} |
7026 |
|
7027 |
static <U,V,W> IntAndDoubleToObject<V> indexedMapper |
7028 |
(final DoubleAndObjectToObject<? super U, ? extends V> combiner, |
7029 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
7030 |
return new IntAndDoubleToObject<V>() { |
7031 |
final int offset = u.origin - origin; |
7032 |
public V op(int i, double a) { return combiner.op(a, (U)(u.oget(i+offset))); } |
7033 |
}; |
7034 |
} |
7035 |
|
7036 |
static <U,W> IntAndDoubleToDouble indexedMapper |
7037 |
(final DoubleAndObjectToDouble<? super U> combiner, |
7038 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
7039 |
return new IntAndDoubleToDouble() { |
7040 |
final int offset = u.origin - origin; |
7041 |
public double op(int i, double a) { return combiner.op(a, (U)(u.oget(i+offset))); } |
7042 |
}; |
7043 |
} |
7044 |
|
7045 |
static <U,W> IntAndDoubleToLong indexedMapper |
7046 |
(final DoubleAndObjectToLong<? super U> combiner, |
7047 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
7048 |
return new IntAndDoubleToLong() { |
7049 |
final int offset = u.origin - origin; |
7050 |
public long op(int i, double a) { return combiner.op(a, (U)(u.oget(i+offset))); } |
7051 |
}; |
7052 |
} |
7053 |
|
7054 |
static <V> IntAndDoubleToObject<V> indexedMapper |
7055 |
(final DoubleAndDoubleToObject<? extends V> combiner, |
7056 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
7057 |
return new IntAndDoubleToObject<V>() { |
7058 |
final int offset = u.origin - origin; |
7059 |
public V op(int i, double a) { return combiner.op(a, u.dget(i+offset)); } |
7060 |
}; |
7061 |
} |
7062 |
|
7063 |
static IntAndDoubleToDouble indexedMapper |
7064 |
(final BinaryDoubleOp combiner, |
7065 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
7066 |
return new IntAndDoubleToDouble() { |
7067 |
final int offset = u.origin - origin; |
7068 |
public double op(int i, double a) { return combiner.op(a, u.dget(i+offset)); } |
7069 |
}; |
7070 |
} |
7071 |
|
7072 |
static IntAndDoubleToLong indexedMapper |
7073 |
(final DoubleAndDoubleToLong combiner, |
7074 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
7075 |
return new IntAndDoubleToLong() { |
7076 |
final int offset = u.origin - origin; |
7077 |
public long op(int i, double a) { return combiner.op(a, u.dget(i+offset)); } |
7078 |
}; |
7079 |
} |
7080 |
|
7081 |
static <V> IntAndDoubleToObject<V> indexedMapper |
7082 |
(final DoubleAndLongToObject<? extends V> combiner, |
7083 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7084 |
return new IntAndDoubleToObject<V>() { |
7085 |
final int offset = u.origin - origin; |
7086 |
public V op(int i, double a) { return combiner.op(a, u.lget(i+offset)); } |
7087 |
}; |
7088 |
} |
7089 |
|
7090 |
static IntAndDoubleToDouble indexedMapper |
7091 |
(final DoubleAndLongToDouble combiner, |
7092 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7093 |
return new IntAndDoubleToDouble() { |
7094 |
final int offset = u.origin - origin; |
7095 |
public double op(int i, double a) { return combiner.op(a, u.lget(i+offset)); } |
7096 |
}; |
7097 |
} |
7098 |
|
7099 |
static IntAndDoubleToLong indexedMapper |
7100 |
(final DoubleAndLongToLong combiner, |
7101 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7102 |
return new IntAndDoubleToLong() { |
7103 |
final int offset = u.origin - origin; |
7104 |
public long op(int i, double a) { return combiner.op(a, u.lget(i+offset)); } |
7105 |
}; |
7106 |
} |
7107 |
|
7108 |
static <U,V,W> IntAndLongToObject<V> indexedMapper |
7109 |
(final LongAndObjectToObject<? super U, ? extends V> combiner, |
7110 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
7111 |
return new IntAndLongToObject<V>() { |
7112 |
final int offset = u.origin - origin; |
7113 |
public V op(int i, long a) { return combiner.op(a, (U)(u.oget(i+offset))); } |
7114 |
}; |
7115 |
} |
7116 |
|
7117 |
static <U,W> IntAndLongToDouble indexedMapper |
7118 |
(final LongAndObjectToDouble<? super U> combiner, |
7119 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
7120 |
return new IntAndLongToDouble() { |
7121 |
final int offset = u.origin - origin; |
7122 |
public double op(int i, long a) { return combiner.op(a, (U)(u.oget(i+offset))); } |
7123 |
}; |
7124 |
} |
7125 |
|
7126 |
static <U,W> IntAndLongToLong indexedMapper |
7127 |
(final LongAndObjectToLong<? super U> combiner, |
7128 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
7129 |
return new IntAndLongToLong() { |
7130 |
final int offset = u.origin - origin; |
7131 |
public long op(int i, long a) { return combiner.op(a, (U)(u.oget(i+offset))); } |
7132 |
}; |
7133 |
} |
7134 |
|
7135 |
static <V> IntAndLongToObject<V> indexedMapper |
7136 |
(final LongAndDoubleToObject<? extends V> combiner, |
7137 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
7138 |
return new IntAndLongToObject<V>() { |
7139 |
final int offset = u.origin - origin; |
7140 |
public V op(int i, long a) { return combiner.op(a, u.dget(i+offset)); } |
7141 |
}; |
7142 |
} |
7143 |
|
7144 |
static IntAndLongToDouble indexedMapper |
7145 |
(final LongAndDoubleToDouble combiner, |
7146 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
7147 |
return new IntAndLongToDouble() { |
7148 |
final int offset = u.origin - origin; |
7149 |
public double op(int i, long a) { return combiner.op(a, u.dget(i+offset)); } |
7150 |
}; |
7151 |
} |
7152 |
|
7153 |
static IntAndLongToLong indexedMapper |
7154 |
(final LongAndDoubleToLong combiner, |
7155 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
7156 |
return new IntAndLongToLong() { |
7157 |
final int offset = u.origin - origin; |
7158 |
public long op(int i, long a) { return combiner.op(a, u.dget(i+offset)); } |
7159 |
}; |
7160 |
} |
7161 |
|
7162 |
static <V> IntAndLongToObject<V> indexedMapper |
7163 |
(final LongAndLongToObject<? extends V> combiner, |
7164 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7165 |
return new IntAndLongToObject<V>() { |
7166 |
final int offset = u.origin - origin; |
7167 |
public V op(int i, long a) { return combiner.op(a, u.lget(i+offset)); } |
7168 |
}; |
7169 |
} |
7170 |
|
7171 |
static IntAndLongToDouble indexedMapper |
7172 |
(final LongAndLongToDouble combiner, |
7173 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7174 |
return new IntAndLongToDouble() { |
7175 |
final int offset = u.origin - origin; |
7176 |
public double op(int i, long a) { return combiner.op(a, u.lget(i+offset)); } |
7177 |
}; |
7178 |
} |
7179 |
|
7180 |
static IntAndLongToLong indexedMapper |
7181 |
(final BinaryLongOp combiner, |
7182 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7183 |
return new IntAndLongToLong() { |
7184 |
final int offset = u.origin - origin; |
7185 |
public long op(int i, long a) { return combiner.op(a, u.lget(i+offset)); } |
7186 |
}; |
7187 |
} |
7188 |
|
7189 |
static <T,U,V> IntAndObjectToObject<T,V> compoundIndexedOp |
7190 |
(final IntAndObjectToObject<? super T, ? extends U> fst, |
7191 |
final IntAndObjectToObject<? super U, ? extends V> snd) { |
7192 |
return new IntAndObjectToObject<T,V>() { |
7193 |
public V op(int i, T a) { return snd.op(i, fst.op(i, a)); } |
7194 |
}; |
7195 |
} |
7196 |
|
7197 |
static <T,U> IntAndObjectToDouble<T> compoundIndexedOp |
7198 |
(final IntAndObjectToObject<? super T, ? extends U> fst, |
7199 |
final IntAndObjectToDouble<? super U> snd) { |
7200 |
return new IntAndObjectToDouble<T>() { |
7201 |
public double op(int i, T a) { return snd.op(i, fst.op(i, a)); } |
7202 |
}; |
7203 |
} |
7204 |
|
7205 |
static <T,U> IntAndObjectToLong<T> compoundIndexedOp |
7206 |
(final IntAndObjectToObject<? super T, ? extends U> fst, |
7207 |
final IntAndObjectToLong<? super U> snd) { |
7208 |
return new IntAndObjectToLong<T>() { |
7209 |
public long op(int i, T a) { return snd.op(i, fst.op(i, a)); } |
7210 |
}; |
7211 |
} |
7212 |
|
7213 |
static <U,V> IntAndDoubleToObject<V> compoundIndexedOp |
7214 |
(final IntAndDoubleToObject<? extends U> fst, |
7215 |
final IntAndObjectToObject<? super U, ? extends V> snd) { |
7216 |
return new IntAndDoubleToObject<V>() { |
7217 |
public V op(int i, double a) { return snd.op(i, fst.op(i, a)); } |
7218 |
}; |
7219 |
} |
7220 |
|
7221 |
static <U> IntAndDoubleToDouble compoundIndexedOp |
7222 |
(final IntAndDoubleToObject<? extends U> fst, |
7223 |
final IntAndObjectToDouble<? super U> snd) { |
7224 |
return new IntAndDoubleToDouble() { |
7225 |
public double op(int i, double a) { return snd.op(i, fst.op(i, a)); } |
7226 |
}; |
7227 |
} |
7228 |
|
7229 |
static <U> IntAndDoubleToLong compoundIndexedOp |
7230 |
(final IntAndDoubleToObject<? extends U> fst, |
7231 |
final IntAndObjectToLong<? super U> snd) { |
7232 |
return new IntAndDoubleToLong() { |
7233 |
public long op(int i, double a) { return snd.op(i, fst.op(i, a)); } |
7234 |
}; |
7235 |
} |
7236 |
|
7237 |
static <U,V> IntAndLongToObject<V> compoundIndexedOp |
7238 |
(final IntAndLongToObject<? extends U> fst, |
7239 |
final IntAndObjectToObject<? super U, ? extends V> snd) { |
7240 |
return new IntAndLongToObject<V>() { |
7241 |
public V op(int i, long a) { return snd.op(i, fst.op(i, a)); } |
7242 |
}; |
7243 |
} |
7244 |
|
7245 |
static <U> IntAndLongToDouble compoundIndexedOp |
7246 |
(final IntAndLongToObject<? extends U> fst, |
7247 |
final IntAndObjectToDouble<? super U> snd) { |
7248 |
return new IntAndLongToDouble() { |
7249 |
public double op(int i, long a) { return snd.op(i, fst.op(i, a)); } |
7250 |
}; |
7251 |
} |
7252 |
|
7253 |
static <U> IntAndLongToLong compoundIndexedOp |
7254 |
(final IntAndLongToObject<? extends U> fst, |
7255 |
final IntAndObjectToLong<? super U> snd) { |
7256 |
return new IntAndLongToLong() { |
7257 |
public long op(int i, long a) { return snd.op(i, fst.op(i, a)); } |
7258 |
}; |
7259 |
} |
7260 |
|
7261 |
static <T,V> IntAndObjectToObject<T,V> compoundIndexedOp |
7262 |
(final IntAndObjectToDouble<? super T> fst, |
7263 |
final IntAndDoubleToObject<? extends V> snd) { |
7264 |
return new IntAndObjectToObject<T,V>() { |
7265 |
public V op(int i, T a) { return snd.op(i, fst.op(i, a)); } |
7266 |
}; |
7267 |
} |
7268 |
|
7269 |
static <T> IntAndObjectToDouble<T> compoundIndexedOp |
7270 |
(final IntAndObjectToDouble<? super T> fst, |
7271 |
final IntAndDoubleToDouble snd) { |
7272 |
return new IntAndObjectToDouble<T>() { |
7273 |
public double op(int i, T a) { return snd.op(i, fst.op(i, a)); } |
7274 |
}; |
7275 |
} |
7276 |
|
7277 |
static <T> IntAndObjectToLong<T> compoundIndexedOp |
7278 |
(final IntAndObjectToLong<? super T> fst, |
7279 |
final IntAndLongToLong snd) { |
7280 |
return new IntAndObjectToLong<T>() { |
7281 |
public long op(int i, T a) { return snd.op(i, fst.op(i, a)); } |
7282 |
}; |
7283 |
} |
7284 |
|
7285 |
static <V> IntAndDoubleToObject<V> compoundIndexedOp |
7286 |
(final IntAndDoubleToLong fst, |
7287 |
final IntAndLongToObject<? extends V> snd) { |
7288 |
return new IntAndDoubleToObject<V>() { |
7289 |
public V op(int i, double a) { return snd.op(i, fst.op(i, a)); } |
7290 |
}; |
7291 |
} |
7292 |
|
7293 |
static IntAndDoubleToDouble compoundIndexedOp |
7294 |
(final IntAndDoubleToDouble fst, |
7295 |
final IntAndDoubleToDouble snd) { |
7296 |
return new IntAndDoubleToDouble() { |
7297 |
public double op(int i, double a) { return snd.op(i, fst.op(i, a)); } |
7298 |
}; |
7299 |
} |
7300 |
|
7301 |
static IntAndDoubleToLong compoundIndexedOp |
7302 |
(final IntAndDoubleToDouble fst, |
7303 |
final IntAndDoubleToLong snd) { |
7304 |
return new IntAndDoubleToLong() { |
7305 |
public long op(int i, double a) { return snd.op(i, fst.op(i, a)); } |
7306 |
}; |
7307 |
} |
7308 |
|
7309 |
static <V> IntAndLongToObject<V> compoundIndexedOp |
7310 |
(final IntAndLongToDouble fst, |
7311 |
final IntAndDoubleToObject<? extends V> snd) { |
7312 |
return new IntAndLongToObject<V>() { |
7313 |
public V op(int i, long a) { return snd.op(i, fst.op(i, a)); } |
7314 |
}; |
7315 |
} |
7316 |
|
7317 |
static IntAndLongToDouble compoundIndexedOp |
7318 |
(final IntAndLongToDouble fst, |
7319 |
final IntAndDoubleToDouble snd) { |
7320 |
return new IntAndLongToDouble() { |
7321 |
public double op(int i, long a) { return snd.op(i, fst.op(i, a)); } |
7322 |
}; |
7323 |
} |
7324 |
|
7325 |
static IntAndLongToLong compoundIndexedOp |
7326 |
(final IntAndLongToDouble fst, |
7327 |
final IntAndDoubleToLong snd) { |
7328 |
return new IntAndLongToLong() { |
7329 |
public long op(int i, long a) { return snd.op(i, fst.op(i, a)); } |
7330 |
}; |
7331 |
} |
7332 |
|
7333 |
static <T,V> IntAndObjectToObject<T,V> compoundIndexedOp |
7334 |
(final IntAndObjectToLong<? super T> fst, |
7335 |
final IntAndLongToObject<? extends V> snd) { |
7336 |
return new IntAndObjectToObject<T,V>() { |
7337 |
public V op(int i, T a) { return snd.op(i, fst.op(i, a)); } |
7338 |
}; |
7339 |
} |
7340 |
|
7341 |
static <T> IntAndObjectToDouble<T> compoundIndexedOp |
7342 |
(final IntAndObjectToLong<? super T> fst, |
7343 |
final IntAndLongToDouble snd) { |
7344 |
return new IntAndObjectToDouble<T>() { |
7345 |
public double op(int i, T a) { return snd.op(i, fst.op(i, a)); } |
7346 |
}; |
7347 |
} |
7348 |
|
7349 |
static <T> IntAndObjectToLong<T> compoundIndexedOp |
7350 |
(final IntAndObjectToDouble<? super T> fst, |
7351 |
final IntAndDoubleToLong snd) { |
7352 |
return new IntAndObjectToLong<T>() { |
7353 |
public long op(int i, T a) { return snd.op(i, fst.op(i, a)); } |
7354 |
}; |
7355 |
} |
7356 |
|
7357 |
static <V> IntAndDoubleToObject<V> compoundIndexedOp |
7358 |
(final IntAndDoubleToDouble fst, |
7359 |
final IntAndDoubleToObject<? extends V> snd) { |
7360 |
return new IntAndDoubleToObject<V>() { |
7361 |
public V op(int i, double a) { return snd.op(i, fst.op(i, a)); } |
7362 |
}; |
7363 |
} |
7364 |
|
7365 |
static IntAndDoubleToDouble compoundIndexedOp |
7366 |
(final IntAndDoubleToLong fst, |
7367 |
final IntAndLongToDouble snd) { |
7368 |
return new IntAndDoubleToDouble() { |
7369 |
public double op(int i, double a) { return snd.op(i, fst.op(i, a)); } |
7370 |
}; |
7371 |
} |
7372 |
|
7373 |
static IntAndDoubleToLong compoundIndexedOp |
7374 |
(final IntAndDoubleToLong fst, |
7375 |
final IntAndLongToLong snd) { |
7376 |
return new IntAndDoubleToLong() { |
7377 |
public long op(int i, double a) { return snd.op(i, fst.op(i, a)); } |
7378 |
}; |
7379 |
} |
7380 |
|
7381 |
static <V> IntAndLongToObject<V> compoundIndexedOp |
7382 |
(final IntAndLongToLong fst, |
7383 |
final IntAndLongToObject<? extends V> snd) { |
7384 |
return new IntAndLongToObject<V>() { |
7385 |
public V op(int i, long a) { return snd.op(i, fst.op(i, a)); } |
7386 |
}; |
7387 |
} |
7388 |
|
7389 |
static IntAndLongToDouble compoundIndexedOp |
7390 |
(final IntAndLongToLong fst, |
7391 |
final IntAndLongToDouble snd) { |
7392 |
return new IntAndLongToDouble() { |
7393 |
public double op(int i, long a) { return snd.op(i, fst.op(i, a)); } |
7394 |
}; |
7395 |
} |
7396 |
|
7397 |
static IntAndLongToLong compoundIndexedOp |
7398 |
(final IntAndLongToLong fst, |
7399 |
final IntAndLongToLong snd) { |
7400 |
return new IntAndLongToLong() { |
7401 |
public long op(int i, long a) { return snd.op(i, fst.op(i, a)); } |
7402 |
}; |
7403 |
} |
7404 |
|
7405 |
static <T,U,V> IntAndObjectToObject<T,V> compoundIndexedOp |
7406 |
(final IntAndObjectToObject<? super T, ? extends U> fst, |
7407 |
final Op<? super U, ? extends V> snd) { |
7408 |
return new IntAndObjectToObject<T,V>() { |
7409 |
public V op(int i, T a) { return snd.op(fst.op(i, a)); } |
7410 |
}; |
7411 |
} |
7412 |
|
7413 |
static <T,U> IntAndObjectToDouble<T> compoundIndexedOp |
7414 |
(final IntAndObjectToObject<? super T, ? extends U> fst, |
7415 |
final ObjectToDouble<? super U> snd) { |
7416 |
return new IntAndObjectToDouble<T>() { |
7417 |
public double op(int i, T a) { return snd.op(fst.op(i, a)); } |
7418 |
}; |
7419 |
} |
7420 |
|
7421 |
static <T,U> IntAndObjectToLong<T> compoundIndexedOp |
7422 |
(final IntAndObjectToObject<? super T, ? extends U> fst, |
7423 |
final ObjectToLong<? super U> snd) { |
7424 |
return new IntAndObjectToLong<T>() { |
7425 |
public long op(int i, T a) { return snd.op(fst.op(i, a)); } |
7426 |
}; |
7427 |
} |
7428 |
|
7429 |
static <U,V> IntAndDoubleToObject<V> compoundIndexedOp |
7430 |
(final IntAndDoubleToObject<? extends U> fst, |
7431 |
final Op<? super U, ? extends V> snd) { |
7432 |
return new IntAndDoubleToObject<V>() { |
7433 |
public V op(int i, double a) { return snd.op(fst.op(i, a)); } |
7434 |
}; |
7435 |
} |
7436 |
|
7437 |
static <U> IntAndDoubleToDouble compoundIndexedOp |
7438 |
(final IntAndDoubleToObject<? extends U> fst, |
7439 |
final ObjectToDouble<? super U> snd) { |
7440 |
return new IntAndDoubleToDouble() { |
7441 |
public double op(int i, double a) { return snd.op(fst.op(i, a)); } |
7442 |
}; |
7443 |
} |
7444 |
|
7445 |
static <U> IntAndDoubleToLong compoundIndexedOp |
7446 |
(final IntAndDoubleToObject<? extends U> fst, |
7447 |
final ObjectToLong<? super U> snd) { |
7448 |
return new IntAndDoubleToLong() { |
7449 |
public long op(int i, double a) { return snd.op(fst.op(i, a)); } |
7450 |
}; |
7451 |
} |
7452 |
|
7453 |
static <U,V> IntAndLongToObject<V> compoundIndexedOp |
7454 |
(final IntAndLongToObject<? extends U> fst, |
7455 |
final Op<? super U, ? extends V> snd) { |
7456 |
return new IntAndLongToObject<V>() { |
7457 |
public V op(int i, long a) { return snd.op(fst.op(i, a)); } |
7458 |
}; |
7459 |
} |
7460 |
|
7461 |
static <U> IntAndLongToDouble compoundIndexedOp |
7462 |
(final IntAndLongToObject<? extends U> fst, |
7463 |
final ObjectToDouble<? super U> snd) { |
7464 |
return new IntAndLongToDouble() { |
7465 |
public double op(int i, long a) { return snd.op(fst.op(i, a)); } |
7466 |
}; |
7467 |
} |
7468 |
|
7469 |
static <U> IntAndLongToLong compoundIndexedOp |
7470 |
(final IntAndLongToObject<? extends U> fst, |
7471 |
final ObjectToLong<? super U> snd) { |
7472 |
return new IntAndLongToLong() { |
7473 |
public long op(int i, long a) { return snd.op(fst.op(i, a)); } |
7474 |
}; |
7475 |
} |
7476 |
|
7477 |
static <T,V> IntAndObjectToObject<T,V> compoundIndexedOp |
7478 |
(final IntAndObjectToDouble<? super T> fst, |
7479 |
final DoubleToObject<? extends V> snd) { |
7480 |
return new IntAndObjectToObject<T,V>() { |
7481 |
public V op(int i, T a) { return snd.op(fst.op(i, a)); } |
7482 |
}; |
7483 |
} |
7484 |
|
7485 |
static <T> IntAndObjectToDouble<T> compoundIndexedOp |
7486 |
(final IntAndObjectToDouble<? super T> fst, final DoubleOp snd) { |
7487 |
return new IntAndObjectToDouble<T>() { |
7488 |
public double op(int i, T a) { return snd.op(fst.op(i, a)); } |
7489 |
}; |
7490 |
} |
7491 |
|
7492 |
static <T> IntAndObjectToLong<T> compoundIndexedOp |
7493 |
(final IntAndObjectToDouble<? super T> fst, final DoubleToLong snd) { |
7494 |
return new IntAndObjectToLong<T>() { |
7495 |
public long op(int i, T a) { return snd.op(fst.op(i, a)); } |
7496 |
}; |
7497 |
} |
7498 |
|
7499 |
static <V> IntAndDoubleToObject<V> compoundIndexedOp |
7500 |
(final IntAndDoubleToDouble fst, |
7501 |
final DoubleToObject<? extends V> snd) { |
7502 |
return new IntAndDoubleToObject<V>() { |
7503 |
public V op(int i, double a) { return snd.op(fst.op(i, a)); } |
7504 |
}; |
7505 |
} |
7506 |
|
7507 |
static IntAndDoubleToDouble compoundIndexedOp |
7508 |
(final IntAndDoubleToDouble fst, final DoubleOp snd) { |
7509 |
return new IntAndDoubleToDouble() { |
7510 |
public double op(int i, double a) { return snd.op(fst.op(i, a)); } |
7511 |
}; |
7512 |
} |
7513 |
|
7514 |
static IntAndDoubleToLong compoundIndexedOp |
7515 |
(final IntAndDoubleToDouble fst, final DoubleToLong snd) { |
7516 |
return new IntAndDoubleToLong() { |
7517 |
public long op(int i, double a) { return snd.op(fst.op(i, a)); } |
7518 |
}; |
7519 |
} |
7520 |
|
7521 |
static <V> IntAndLongToObject<V> compoundIndexedOp |
7522 |
(final IntAndLongToDouble fst, final DoubleToObject<? extends V> snd) { |
7523 |
return new IntAndLongToObject<V>() { |
7524 |
public V op(int i, long a) { return snd.op(fst.op(i, a)); } |
7525 |
}; |
7526 |
} |
7527 |
|
7528 |
static IntAndLongToDouble compoundIndexedOp |
7529 |
(final IntAndLongToDouble fst, final DoubleOp snd) { |
7530 |
return new IntAndLongToDouble() { |
7531 |
public double op(int i,long a) { return snd.op(fst.op(i, a)); } |
7532 |
}; |
7533 |
} |
7534 |
|
7535 |
static IntAndLongToLong compoundIndexedOp |
7536 |
(final IntAndLongToDouble fst, final DoubleToLong snd) { |
7537 |
return new IntAndLongToLong() { |
7538 |
public long op(int i, long a) { return snd.op(fst.op(i, a)); } |
7539 |
}; |
7540 |
} |
7541 |
|
7542 |
static <T,V> IntAndObjectToObject<T,V> compoundIndexedOp |
7543 |
(final IntAndObjectToLong<? super T> fst, |
7544 |
final LongToObject<? extends V> snd) { |
7545 |
return new IntAndObjectToObject<T,V>() { |
7546 |
public V op(int i, T a) { return snd.op(fst.op(i, a)); } |
7547 |
}; |
7548 |
} |
7549 |
|
7550 |
static <T> IntAndObjectToDouble<T> compoundIndexedOp |
7551 |
(final IntAndObjectToLong<? super T> fst, final LongToDouble snd) { |
7552 |
return new IntAndObjectToDouble<T>() { |
7553 |
public double op(int i, T a) { return snd.op(fst.op(i, a)); } |
7554 |
}; |
7555 |
} |
7556 |
|
7557 |
static <T> IntAndObjectToLong<T> compoundIndexedOp |
7558 |
(final IntAndObjectToLong<? super T> fst, final LongOp snd) { |
7559 |
return new IntAndObjectToLong<T>() { |
7560 |
public long op(int i, T a) { return snd.op(fst.op(i, a)); } |
7561 |
}; |
7562 |
} |
7563 |
|
7564 |
static <V> IntAndDoubleToObject<V> compoundIndexedOp |
7565 |
(final IntAndDoubleToLong fst, final LongToObject<? extends V> snd) { |
7566 |
return new IntAndDoubleToObject<V>() { |
7567 |
public V op(int i, double a) { return snd.op(fst.op(i, a)); } |
7568 |
}; |
7569 |
} |
7570 |
|
7571 |
static IntAndDoubleToDouble compoundIndexedOp |
7572 |
(final IntAndDoubleToLong fst, final LongToDouble snd) { |
7573 |
return new IntAndDoubleToDouble() { |
7574 |
public double op(int i, double a) { return snd.op(fst.op(i, a)); } |
7575 |
}; |
7576 |
} |
7577 |
|
7578 |
static IntAndDoubleToLong compoundIndexedOp |
7579 |
(final IntAndDoubleToLong fst, final LongOp snd) { |
7580 |
return new IntAndDoubleToLong() { |
7581 |
public long op(int i, double a) { return snd.op(fst.op(i, a)); } |
7582 |
}; |
7583 |
} |
7584 |
|
7585 |
static <V> IntAndLongToObject<V> compoundIndexedOp |
7586 |
(final IntAndLongToLong fst, final LongToObject<? extends V> snd) { |
7587 |
return new IntAndLongToObject<V>() { |
7588 |
public V op(int i, long a) { return snd.op(fst.op(i, a)); } |
7589 |
}; |
7590 |
} |
7591 |
|
7592 |
static IntAndLongToDouble compoundIndexedOp |
7593 |
(final IntAndLongToLong fst, final LongToDouble snd) { |
7594 |
return new IntAndLongToDouble() { |
7595 |
public double op(int i,long a) { return snd.op(fst.op(i, a)); } |
7596 |
}; |
7597 |
} |
7598 |
|
7599 |
static IntAndLongToLong compoundIndexedOp |
7600 |
(final IntAndLongToLong fst, |
7601 |
final LongOp snd) { |
7602 |
return new IntAndLongToLong() { |
7603 |
public long op(int i, long a) { return snd.op(fst.op(i, a)); } |
7604 |
}; |
7605 |
} |
7606 |
|
7607 |
static <T,U,V> IntAndObjectToObject<T,V> compoundIndexedOp |
7608 |
(final Op<? super T, ? extends U> fst, |
7609 |
final IntAndObjectToObject<? super U, ? extends V> snd) { |
7610 |
return new IntAndObjectToObject<T,V>() { |
7611 |
public V op(int i, T a) { return snd.op(i, fst.op(a)); } |
7612 |
}; |
7613 |
} |
7614 |
|
7615 |
static <T,U> IntAndObjectToDouble<T> compoundIndexedOp |
7616 |
(final Op<? super T, ? extends U> fst, |
7617 |
final IntAndObjectToDouble<? super U> snd) { |
7618 |
return new IntAndObjectToDouble<T>() { |
7619 |
public double op(int i, T a) { return snd.op(i, fst.op(a)); } |
7620 |
}; |
7621 |
} |
7622 |
|
7623 |
static <T,U> IntAndObjectToLong<T> compoundIndexedOp |
7624 |
(final Op<? super T, ? extends U> fst, |
7625 |
final IntAndObjectToLong<? super U> snd) { |
7626 |
return new IntAndObjectToLong<T>() { |
7627 |
public long op(int i, T a) { return snd.op(i, fst.op(a)); } |
7628 |
}; |
7629 |
} |
7630 |
|
7631 |
static <U,V> IntAndDoubleToObject<V> compoundIndexedOp |
7632 |
(final DoubleToObject<? extends U> fst, |
7633 |
final IntAndObjectToObject<? super U, ? extends V> snd) { |
7634 |
return new IntAndDoubleToObject<V>() { |
7635 |
public V op(int i, double a) { return snd.op(i, fst.op(a)); } |
7636 |
}; |
7637 |
} |
7638 |
|
7639 |
static <U> IntAndDoubleToDouble compoundIndexedOp |
7640 |
(final DoubleToObject<? extends U> fst, |
7641 |
final IntAndObjectToDouble<? super U> snd) { |
7642 |
return new IntAndDoubleToDouble() { |
7643 |
public double op(int i, double a) { return snd.op(i, fst.op(a)); } |
7644 |
}; |
7645 |
} |
7646 |
|
7647 |
static <U> IntAndDoubleToLong compoundIndexedOp |
7648 |
(final DoubleToObject<? extends U> fst, |
7649 |
final IntAndObjectToLong<? super U> snd) { |
7650 |
return new IntAndDoubleToLong() { |
7651 |
public long op(int i, double a) { return snd.op(i, fst.op(a)); } |
7652 |
}; |
7653 |
} |
7654 |
|
7655 |
static <U,V> IntAndLongToObject<V> compoundIndexedOp |
7656 |
(final LongToObject<? extends U> fst, |
7657 |
final IntAndObjectToObject<? super U, ? extends V> snd) { |
7658 |
return new IntAndLongToObject<V>() { |
7659 |
public V op(int i, long a) { return snd.op(i, fst.op(a)); } |
7660 |
}; |
7661 |
} |
7662 |
|
7663 |
static <U> IntAndLongToDouble compoundIndexedOp |
7664 |
(final LongToObject<? extends U> fst, |
7665 |
final IntAndObjectToDouble<? super U> snd) { |
7666 |
return new IntAndLongToDouble() { |
7667 |
public double op(int i, long a) { return snd.op(i, fst.op(a)); } |
7668 |
}; |
7669 |
} |
7670 |
|
7671 |
static <U> IntAndLongToLong compoundIndexedOp |
7672 |
(final LongToObject<? extends U> fst, |
7673 |
final IntAndObjectToLong<? super U> snd) { |
7674 |
return new IntAndLongToLong() { |
7675 |
public long op(int i, long a) { return snd.op(i, fst.op(a)); } |
7676 |
}; |
7677 |
} |
7678 |
|
7679 |
static <T,V> IntAndObjectToObject<T,V> compoundIndexedOp |
7680 |
(final ObjectToDouble<? super T> fst, |
7681 |
final IntAndDoubleToObject<? extends V> snd) { |
7682 |
return new IntAndObjectToObject<T,V>() { |
7683 |
public V op(int i, T a) { return snd.op(i, fst.op(a)); } |
7684 |
}; |
7685 |
} |
7686 |
|
7687 |
static <T> IntAndObjectToDouble<T> compoundIndexedOp |
7688 |
(final ObjectToDouble<? super T> fst, final IntAndDoubleToDouble snd) { |
7689 |
return new IntAndObjectToDouble<T>() { |
7690 |
public double op(int i, T a) { return snd.op(i, fst.op(a)); } |
7691 |
}; |
7692 |
} |
7693 |
|
7694 |
static <T> IntAndObjectToLong<T> compoundIndexedOp |
7695 |
(final ObjectToDouble<? super T> fst, final IntAndDoubleToLong snd) { |
7696 |
return new IntAndObjectToLong<T>() { |
7697 |
public long op(int i, T a) { return snd.op(i, fst.op(a)); } |
7698 |
}; |
7699 |
} |
7700 |
|
7701 |
static <V> IntAndDoubleToObject<V> compoundIndexedOp |
7702 |
(final DoubleOp fst, final IntAndDoubleToObject<? extends V> snd) { |
7703 |
return new IntAndDoubleToObject<V>() { |
7704 |
public V op(int i, double a) { return snd.op(i, fst.op(a)); } |
7705 |
}; |
7706 |
} |
7707 |
|
7708 |
static IntAndDoubleToDouble compoundIndexedOp |
7709 |
(final DoubleOp fst, final IntAndDoubleToDouble snd) { |
7710 |
return new IntAndDoubleToDouble() { |
7711 |
public double op(int i, double a) { return snd.op(i, fst.op(a)); } |
7712 |
}; |
7713 |
} |
7714 |
|
7715 |
static IntAndDoubleToLong compoundIndexedOp |
7716 |
(final DoubleOp fst, final IntAndDoubleToLong snd) { |
7717 |
return new IntAndDoubleToLong() { |
7718 |
public long op(int i, double a) { return snd.op(i, fst.op(a)); } |
7719 |
}; |
7720 |
} |
7721 |
|
7722 |
static <V> IntAndLongToObject<V> compoundIndexedOp |
7723 |
(final LongToDouble fst, final IntAndDoubleToObject<? extends V> snd) { |
7724 |
return new IntAndLongToObject<V>() { |
7725 |
public V op(int i, long a) { return snd.op(i, fst.op(a)); } |
7726 |
}; |
7727 |
} |
7728 |
|
7729 |
static IntAndLongToDouble compoundIndexedOp |
7730 |
(final LongToDouble fst, final IntAndDoubleToDouble snd) { |
7731 |
return new IntAndLongToDouble() { |
7732 |
public double op(int i, long a) { return snd.op(i, fst.op(a)); } |
7733 |
}; |
7734 |
} |
7735 |
|
7736 |
static IntAndLongToLong compoundIndexedOp |
7737 |
(final LongToDouble fst, final IntAndDoubleToLong snd) { |
7738 |
return new IntAndLongToLong() { |
7739 |
public long op(int i, long a) { return snd.op(i, fst.op(a)); } |
7740 |
}; |
7741 |
} |
7742 |
|
7743 |
static <T,V> IntAndObjectToObject<T,V> compoundIndexedOp |
7744 |
(final ObjectToLong<? super T> fst, |
7745 |
final IntAndLongToObject<? extends V> snd) { |
7746 |
return new IntAndObjectToObject<T,V>() { |
7747 |
public V op(int i, T a) { return snd.op(i, fst.op(a)); } |
7748 |
}; |
7749 |
} |
7750 |
|
7751 |
static <T> IntAndObjectToDouble<T> compoundIndexedOp |
7752 |
(final ObjectToLong<? super T> fst, final IntAndLongToDouble snd) { |
7753 |
return new IntAndObjectToDouble<T>() { |
7754 |
public double op(int i, T a) { return snd.op(i, fst.op(a)); } |
7755 |
}; |
7756 |
} |
7757 |
|
7758 |
static <T> IntAndObjectToLong<T> compoundIndexedOp |
7759 |
(final ObjectToLong<? super T> fst, final IntAndLongToLong snd) { |
7760 |
return new IntAndObjectToLong<T>() { |
7761 |
public long op(int i, T a) { return snd.op(i, fst.op(a)); } |
7762 |
}; |
7763 |
} |
7764 |
|
7765 |
static <V> IntAndDoubleToObject<V> compoundIndexedOp |
7766 |
(final DoubleToLong fst, final IntAndLongToObject<? extends V> snd) { |
7767 |
return new IntAndDoubleToObject<V>() { |
7768 |
public V op(int i, double a) { return snd.op(i, fst.op(a)); } |
7769 |
}; |
7770 |
} |
7771 |
|
7772 |
static IntAndDoubleToDouble compoundIndexedOp |
7773 |
(final DoubleToLong fst, final IntAndLongToDouble snd) { |
7774 |
return new IntAndDoubleToDouble() { |
7775 |
public double op(int i, double a) { return snd.op(i, fst.op(a)); } |
7776 |
}; |
7777 |
} |
7778 |
|
7779 |
static IntAndDoubleToLong compoundIndexedOp |
7780 |
(final DoubleToLong fst, final IntAndLongToLong snd) { |
7781 |
return new IntAndDoubleToLong() { |
7782 |
public long op(int i, double a) { return snd.op(i, fst.op(a)); } |
7783 |
}; |
7784 |
} |
7785 |
|
7786 |
static <V> IntAndLongToObject<V> compoundIndexedOp |
7787 |
(final LongOp fst, final IntAndLongToObject<? extends V> snd) { |
7788 |
return new IntAndLongToObject<V>() { |
7789 |
public V op(int i, long a) { return snd.op(i, fst.op(a)); } |
7790 |
}; |
7791 |
} |
7792 |
|
7793 |
static IntAndLongToDouble compoundIndexedOp |
7794 |
(final LongOp fst, final IntAndLongToDouble snd) { |
7795 |
return new IntAndLongToDouble() { |
7796 |
public double op(int i, long a) { return snd.op(i, fst.op(a)); } |
7797 |
}; |
7798 |
} |
7799 |
|
7800 |
static IntAndLongToLong compoundIndexedOp |
7801 |
(final LongOp fst, final IntAndLongToLong snd) { |
7802 |
return new IntAndLongToLong() { |
7803 |
public long op(int i, long a) { return snd.op(i, fst.op(a)); } |
7804 |
}; |
7805 |
} |
7806 |
|
7807 |
// binary predicates |
7808 |
|
7809 |
static <T,U,W> IntAndObjectPredicate<T> indexedSelector |
7810 |
(final BinaryPredicate<? super T, ? super U> bp, |
7811 |
final ParallelArrayWithMapping<W,U> u, final int origin) { |
7812 |
return new IntAndObjectPredicate<T>() { |
7813 |
final int offset = u.origin - origin; |
7814 |
public boolean op(int i, T a) { |
7815 |
int k = i + offset; |
7816 |
return u.isSelected(k) && bp.op(a, (U)(u.oget(k))); |
7817 |
} |
7818 |
}; |
7819 |
} |
7820 |
|
7821 |
static IntAndDoublePredicate indexedSelector |
7822 |
(final BinaryDoublePredicate bp, |
7823 |
final ParallelDoubleArrayWithDoubleMapping u, final int origin) { |
7824 |
return new IntAndDoublePredicate() { |
7825 |
final int offset = u.origin - origin; |
7826 |
public boolean op(int i, double a) { |
7827 |
int k = i + offset; |
7828 |
return u.isSelected(k) && bp.op(a, u.dget(k)); |
7829 |
} |
7830 |
}; |
7831 |
} |
7832 |
|
7833 |
static IntAndLongPredicate indexedSelector |
7834 |
(final BinaryLongPredicate bp, |
7835 |
final ParallelLongArrayWithLongMapping u, final int origin) { |
7836 |
return new IntAndLongPredicate() { |
7837 |
final int offset = u.origin - origin; |
7838 |
public boolean op(int i, long a) { |
7839 |
int k = i + offset; |
7840 |
return u.isSelected(k) && bp.op(a, u.lget(k)); |
7841 |
} |
7842 |
}; |
7843 |
} |
7844 |
|
7845 |
static <S, T extends S> IntAndObjectPredicate<T> compoundIndexedSelector |
7846 |
(final Predicate<S> fst, final IntAndObjectPredicate<? super T> snd) { |
7847 |
return new IntAndObjectPredicate<T>() { |
7848 |
public boolean op(int i, T a) { return fst.op(a) && snd.op(i, a); } |
7849 |
}; |
7850 |
} |
7851 |
|
7852 |
static <S, T extends S> IntAndObjectPredicate<T> compoundIndexedSelector |
7853 |
(final IntAndObjectPredicate<S> fst, |
7854 |
final IntAndObjectPredicate<? super T> snd) { |
7855 |
return new IntAndObjectPredicate<T>() { |
7856 |
public boolean op(int i, T a) { return fst.op(i, a) && snd.op(i, a); } |
7857 |
}; |
7858 |
} |
7859 |
|
7860 |
static <S, T extends S> IntAndObjectPredicate<T> compoundIndexedSelector |
7861 |
(final IntAndObjectPredicate<S> fst, final Predicate<? super T> snd) { |
7862 |
return new IntAndObjectPredicate<T>() { |
7863 |
public boolean op(int i, T a) { return fst.op(i, a) && snd.op(a); } |
7864 |
}; |
7865 |
} |
7866 |
|
7867 |
static IntAndDoublePredicate compoundIndexedSelector |
7868 |
(final DoublePredicate fst, final IntAndDoublePredicate snd) { |
7869 |
return new IntAndDoublePredicate() { |
7870 |
public boolean op(int i, double a) { return fst.op(a) && snd.op(i, a); } |
7871 |
}; |
7872 |
} |
7873 |
|
7874 |
static IntAndDoublePredicate compoundIndexedSelector |
7875 |
(final IntAndDoublePredicate fst, final IntAndDoublePredicate snd) { |
7876 |
return new IntAndDoublePredicate() { |
7877 |
public boolean op(int i, double a) { return fst.op(i, a) && snd.op(i, a); } |
7878 |
}; |
7879 |
} |
7880 |
|
7881 |
static IntAndDoublePredicate compoundIndexedSelector |
7882 |
(final IntAndDoublePredicate fst, final DoublePredicate snd) { |
7883 |
return new IntAndDoublePredicate() { |
7884 |
public boolean op(int i, double a) { return fst.op(i, a) && snd.op(a); } |
7885 |
}; |
7886 |
} |
7887 |
|
7888 |
static IntAndLongPredicate compoundIndexedSelector |
7889 |
(final LongPredicate fst, final IntAndLongPredicate snd) { |
7890 |
return new IntAndLongPredicate() { |
7891 |
public boolean op(int i, long a) { return fst.op(a) && snd.op(i, a); } |
7892 |
}; |
7893 |
} |
7894 |
|
7895 |
static IntAndLongPredicate compoundIndexedSelector |
7896 |
(final IntAndLongPredicate fst, final IntAndLongPredicate snd) { |
7897 |
return new IntAndLongPredicate() { |
7898 |
public boolean op(int i, long a) { return fst.op(i, a) && snd.op(i, a); } |
7899 |
}; |
7900 |
} |
7901 |
|
7902 |
static IntAndLongPredicate compoundIndexedSelector |
7903 |
(final IntAndLongPredicate fst, final LongPredicate snd) { |
7904 |
return new IntAndLongPredicate() { |
7905 |
public boolean op(int i, long a) { return fst.op(i, a) && snd.op(a); } |
7906 |
}; |
7907 |
} |
7908 |
|
7909 |
} |