1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
package extra166y; |
65 |
|
// A few public methods exported across all subclasses |
66 |
|
|
67 |
|
/** |
68 |
< |
* Return the number of elements selected using bound or |
68 |
> |
* Returns the number of elements selected using bound or |
69 |
|
* filter restrictions. Note that this method must evaluate |
70 |
|
* all selectors to return its result. |
71 |
|
* @return the number of elements |
82 |
|
/** |
83 |
|
* Returns the index of some element matching bound and filter |
84 |
|
* constraints, or -1 if none. |
85 |
< |
* @return index of matching element, or -1 if none. |
85 |
> |
* @return index of matching element, or -1 if none |
86 |
|
*/ |
87 |
|
public int anyIndex() { |
88 |
|
if (!hasFilter()) |
89 |
< |
return (origin < fence)? origin : -1; |
89 |
> |
return (origin < fence) ? origin : -1; |
90 |
|
AtomicInteger result = new AtomicInteger(-1); |
91 |
|
PAS.FJSelectAny f = new PAS.FJSelectAny |
92 |
|
(this, origin, fence, null, result); |
95 |
|
} |
96 |
|
|
97 |
|
/** |
98 |
< |
* Returns true if there are no elements |
98 |
> |
* Returns true if there are no elements. |
99 |
|
* @return true if there are no elements |
100 |
|
*/ |
101 |
|
public boolean isEmpty() { |
965 |
|
|
966 |
|
public ParallelLongArrayWithLongMapping withIndexedMapping |
967 |
|
(IntAndLongToLong mapper) { |
968 |
< |
return new LULCPap(ex, origin, fence, array, mapper); |
968 |
> |
return new LULCPap(ex, origin, fence, array, mapper); |
969 |
|
} |
970 |
|
|
971 |
|
public int indexOf(long target) { |
1133 |
|
} |
1134 |
|
} |
1135 |
|
|
1136 |
+ |
static final class AndPredicate<T> implements Predicate<T> { |
1137 |
+ |
final Predicate<? super T> first; |
1138 |
+ |
final Predicate<? super T> second; |
1139 |
+ |
AndPredicate(Predicate<? super T> first, |
1140 |
+ |
Predicate<? super T> second) { |
1141 |
+ |
this.first = first; this.second = second; |
1142 |
+ |
} |
1143 |
+ |
public final boolean op(T x) { return first.op(x) && second.op(x); } |
1144 |
+ |
} |
1145 |
+ |
|
1146 |
|
// Filtered (but unmapped) classes |
1147 |
|
static final class OFPap<T> extends ParallelArrayWithFilter<T> { |
1148 |
|
final Predicate<? super T> selector; |
1159 |
|
public ParallelArrayWithFilter<T> withFilter |
1160 |
|
(Predicate<? super T> selector) { |
1161 |
|
return new OFPap<T>(ex, origin, fence, array, |
1162 |
< |
CommonOps.andPredicate(this.selector, selector)); |
1162 |
> |
new AndPredicate(this.selector, selector)); |
1163 |
|
} |
1164 |
|
|
1165 |
|
public ParallelArrayWithFilter<T> withIndexedFilter |
1199 |
|
return new OFLCPap<T>(ex, origin, fence, array, selector, mapper); |
1200 |
|
} |
1201 |
|
|
1202 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
1202 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
1203 |
|
final Predicate s = selector; |
1204 |
|
final Object[] a = this.array; |
1205 |
|
for (int i = lo; i < hi; ++i) { |
1377 |
|
return new DFLCPap(ex, origin, fence, array, selector, mapper); |
1378 |
|
} |
1379 |
|
|
1380 |
< |
final void leafApply(int lo, int hi, DoubleProcedure procedure) { |
1380 |
> |
final void leafApply(int lo, int hi, DoubleProcedure procedure) { |
1381 |
|
final DoublePredicate s = selector; |
1382 |
|
final double[] a = this.array; |
1383 |
|
for (int i = lo; i < hi; ++i) { |
1557 |
|
return new LFLCPap(ex, origin, fence, array, selector, mapper); |
1558 |
|
} |
1559 |
|
|
1560 |
< |
final void leafApply(int lo, int hi, LongProcedure procedure) { |
1560 |
> |
final void leafApply(int lo, int hi, LongProcedure procedure) { |
1561 |
|
final LongPredicate s = selector; |
1562 |
|
final long[] a = this.array; |
1563 |
|
for (int i = lo; i < hi; ++i) { |
1740 |
|
return new ORLCPap<T>(ex, origin, fence, array, selector, mapper); |
1741 |
|
} |
1742 |
|
|
1743 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
1743 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
1744 |
|
final IntAndObjectPredicate s = selector; |
1745 |
|
final Object[] a = this.array; |
1746 |
|
for (int i = lo; i < hi; ++i) { |
1920 |
|
return new DRLCPap(ex, origin, fence, array, selector, mapper); |
1921 |
|
} |
1922 |
|
|
1923 |
< |
final void leafApply(int lo, int hi, DoubleProcedure procedure) { |
1923 |
> |
final void leafApply(int lo, int hi, DoubleProcedure procedure) { |
1924 |
|
final IntAndDoublePredicate s = selector; |
1925 |
|
final double[] a = this.array; |
1926 |
|
for (int i = lo; i < hi; ++i) { |
2100 |
|
return new LRLCPap(ex, origin, fence, array, selector, mapper); |
2101 |
|
} |
2102 |
|
|
2103 |
< |
final void leafApply(int lo, int hi, LongProcedure procedure) { |
2103 |
> |
final void leafApply(int lo, int hi, LongProcedure procedure) { |
2104 |
|
final IntAndLongPredicate s = selector; |
2105 |
|
final long[] a = this.array; |
2106 |
|
for (int i = lo; i < hi; ++i) { |
2360 |
|
compoundIndexedOp(this.op, mapper)); |
2361 |
|
} |
2362 |
|
|
2363 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
2363 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
2364 |
|
final Op f = op; |
2365 |
|
final Object[] a = this.array; |
2366 |
|
for (int i = lo; i < hi; ++i) |
2422 |
|
compoundIndexedOp(this.op, mapper)); |
2423 |
|
} |
2424 |
|
|
2425 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
2425 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
2426 |
|
final double[] a = this.array; |
2427 |
|
final DoubleToObject f = op; |
2428 |
|
for (int i = lo; i < hi; ++i) |
2484 |
|
compoundIndexedOp(this.op, mapper)); |
2485 |
|
} |
2486 |
|
|
2487 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
2487 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
2488 |
|
final long[] a = this.array; |
2489 |
|
final LongToObject f = op; |
2490 |
|
for (int i = lo; i < hi; ++i) |
2555 |
|
compoundIndexedOp(this.op, mapper)); |
2556 |
|
} |
2557 |
|
|
2558 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
2558 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
2559 |
|
final Predicate s = selector; |
2560 |
|
final Object[] a = this.array; |
2561 |
|
final Op f = op; |
2643 |
|
compoundIndexedOp(this.op, mapper)); |
2644 |
|
} |
2645 |
|
|
2646 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
2646 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
2647 |
|
final DoublePredicate s = selector; |
2648 |
|
final DoubleToObject f = op; |
2649 |
|
final double[] a = this.array; |
2725 |
|
compoundIndexedOp(this.op, mapper)); |
2726 |
|
} |
2727 |
|
|
2728 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
2728 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
2729 |
|
final LongPredicate s = selector; |
2730 |
|
final LongToObject f = op; |
2731 |
|
final long[] a = this.array; |
2808 |
|
compoundIndexedOp(this.op, mapper)); |
2809 |
|
} |
2810 |
|
|
2811 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
2811 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
2812 |
|
final IntAndObjectPredicate s = selector; |
2813 |
|
final Object[] a = this.array; |
2814 |
|
final Op f = op; |
2896 |
|
compoundIndexedOp(this.op, mapper)); |
2897 |
|
} |
2898 |
|
|
2899 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
2899 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
2900 |
|
final IntAndDoublePredicate s = selector; |
2901 |
|
final DoubleToObject f = op; |
2902 |
|
final double[] a = this.array; |
2978 |
|
compoundIndexedOp(this.op, mapper)); |
2979 |
|
} |
2980 |
|
|
2981 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
2981 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
2982 |
|
final IntAndLongPredicate s = selector; |
2983 |
|
final LongToObject f = op; |
2984 |
|
final long[] a = this.array; |
3151 |
|
compoundIndexedOp(this.op, mapper)); |
3152 |
|
} |
3153 |
|
|
3154 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
3154 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
3155 |
|
final IntAndObjectToObject f = op; |
3156 |
|
final Object[] a = this.array; |
3157 |
|
for (int i = lo; i < hi; ++i) |
3213 |
|
compoundIndexedOp(this.op, mapper)); |
3214 |
|
} |
3215 |
|
|
3216 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
3216 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
3217 |
|
final IntAndDoubleToObject f = op; |
3218 |
|
final double[] a = this.array; |
3219 |
|
for (int i = lo; i < hi; ++i) |
3275 |
|
compoundIndexedOp(this.op, mapper)); |
3276 |
|
} |
3277 |
|
|
3278 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
3278 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
3279 |
|
final IntAndLongToObject f = op; |
3280 |
|
final long[] a = this.array; |
3281 |
|
for (int i = lo; i < hi; ++i) |
3297 |
|
|
3298 |
|
// object-combined filtered |
3299 |
|
|
3300 |
< |
static final class OFOCPap<T,U> extends OOCPap<T,U> { |
3300 |
> |
static final class OFOCPap<T,U> extends OOCPap<T,U> { |
3301 |
|
final Predicate<? super T> selector; |
3302 |
|
OFOCPap(ForkJoinPool ex, int origin, int fence, |
3303 |
|
T[] array, Predicate<? super T> selector, |
3347 |
|
(this.op, mapper)); |
3348 |
|
} |
3349 |
|
|
3350 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
3350 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
3351 |
|
final Predicate s = selector; |
3352 |
|
final Object[] a = this.array; |
3353 |
|
final IntAndObjectToObject f = op; |
3427 |
|
compoundIndexedOp(this.op, mapper)); |
3428 |
|
} |
3429 |
|
|
3430 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
3430 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
3431 |
|
final DoublePredicate s = selector; |
3432 |
|
final double[] a = this.array; |
3433 |
|
final IntAndDoubleToObject f = op; |
3507 |
|
compoundIndexedOp(this.op, mapper)); |
3508 |
|
} |
3509 |
|
|
3510 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
3510 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
3511 |
|
final LongPredicate s = selector; |
3512 |
|
final long[] a = this.array; |
3513 |
|
final IntAndLongToObject f = op; |
3540 |
|
} |
3541 |
|
|
3542 |
|
// Object-combined, relational |
3543 |
< |
static final class OROCPap<T,U> extends OOCPap<T,U> { |
3543 |
> |
static final class OROCPap<T,U> extends OOCPap<T,U> { |
3544 |
|
final IntAndObjectPredicate<? super T> selector; |
3545 |
|
OROCPap(ForkJoinPool ex, int origin, int fence, |
3546 |
|
T[] array, IntAndObjectPredicate<? super T> selector, |
3590 |
|
(this.op, mapper)); |
3591 |
|
} |
3592 |
|
|
3593 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
3593 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
3594 |
|
final IntAndObjectPredicate s = selector; |
3595 |
|
final Object[] a = this.array; |
3596 |
|
final IntAndObjectToObject f = op; |
3670 |
|
compoundIndexedOp(this.op, mapper)); |
3671 |
|
} |
3672 |
|
|
3673 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
3673 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
3674 |
|
final IntAndDoublePredicate s = selector; |
3675 |
|
final double[] a = this.array; |
3676 |
|
final IntAndDoubleToObject f = op; |
3750 |
|
compoundIndexedOp(this.op, mapper)); |
3751 |
|
} |
3752 |
|
|
3753 |
< |
void leafApply(int lo, int hi, Procedure procedure) { |
3753 |
> |
void leafApply(int lo, int hi, Procedure procedure) { |
3754 |
|
final IntAndLongPredicate s = selector; |
3755 |
|
final long[] a = this.array; |
3756 |
|
final IntAndLongToObject f = op; |
7882 |
|
}; |
7883 |
|
} |
7884 |
|
|
7885 |
< |
static IntAndDoublePredicate compoundIndexedSelector |
7885 |
> |
static IntAndDoublePredicate compoundIndexedSelector |
7886 |
|
(final IntAndDoublePredicate fst, final IntAndDoublePredicate snd) { |
7887 |
|
return new IntAndDoublePredicate() { |
7888 |
|
public boolean op(int i, double a) { return fst.op(i, a) && snd.op(i, a); } |
7889 |
|
}; |
7890 |
|
} |
7891 |
|
|
7892 |
< |
static IntAndDoublePredicate compoundIndexedSelector |
7892 |
> |
static IntAndDoublePredicate compoundIndexedSelector |
7893 |
|
(final IntAndDoublePredicate fst, final DoublePredicate snd) { |
7894 |
|
return new IntAndDoublePredicate() { |
7895 |
|
public boolean op(int i, double a) { return fst.op(i, a) && snd.op(a); } |
7903 |
|
}; |
7904 |
|
} |
7905 |
|
|
7906 |
< |
static IntAndLongPredicate compoundIndexedSelector |
7906 |
> |
static IntAndLongPredicate compoundIndexedSelector |
7907 |
|
(final IntAndLongPredicate fst, final IntAndLongPredicate snd) { |
7908 |
|
return new IntAndLongPredicate() { |
7909 |
|
public boolean op(int i, long a) { return fst.op(i, a) && snd.op(i, a); } |
7910 |
|
}; |
7911 |
|
} |
7912 |
|
|
7913 |
< |
static IntAndLongPredicate compoundIndexedSelector |
7913 |
> |
static IntAndLongPredicate compoundIndexedSelector |
7914 |
|
(final IntAndLongPredicate fst, final LongPredicate snd) { |
7915 |
|
return new IntAndLongPredicate() { |
7916 |
|
public boolean op(int i, long a) { return fst.op(i, a) && snd.op(a); } |