ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/AbstractParallelAnyArray.java
Revision: 1.18
Committed: Sun Jan 18 20:17:32 2015 UTC (9 years, 3 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.17: +1 -0 lines
Log Message:
exactly one blank line before and after package statements

File Contents

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