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