46 |
|
* public long op(int i) { return i + 2; } }; |
47 |
|
* static LongPredicate notDivisibleBy(final long p) { |
48 |
|
* return new LongPredicate() { |
49 |
< |
* public boolean op(long n) { return n <= p || (n % p) != 0; } |
49 |
> |
* public boolean op(long n) { return n <= p || (n % p) != 0; } |
50 |
|
* }; } |
51 |
|
* static LongPredicate notProbablePrime = new LongPredicate() { |
52 |
|
* private static final int CERTAINTY = 8; |
101 |
|
|
102 |
|
/** |
103 |
|
* Creates a new ParallelLongArray using the given executor and |
104 |
< |
* an array of the given size |
104 |
> |
* an array of the given size. |
105 |
|
* @param size the array size |
106 |
|
* @param executor the executor |
107 |
|
*/ |
177 |
|
* mapped ParallelLongArray. |
178 |
|
*/ |
179 |
|
public static interface SummaryStatistics { |
180 |
< |
/** Return the number of elements */ |
180 |
> |
/** Returns the number of elements */ |
181 |
|
public int size(); |
182 |
< |
/** Return the minimum element, or Long.MAX_VALUE if empty */ |
182 |
> |
/** Returns the minimum element, or Long.MAX_VALUE if empty */ |
183 |
|
public long min(); |
184 |
< |
/** Return the maximum element, or Long.MIN_VALUE if empty */ |
184 |
> |
/** Returns the maximum element, or Long.MIN_VALUE if empty */ |
185 |
|
public long max(); |
186 |
< |
/** Return the index of the minimum element, or -1 if empty */ |
186 |
> |
/** Returns the index of the minimum element, or -1 if empty */ |
187 |
|
public int indexOfMin(); |
188 |
< |
/** Return the index of the maximum element, or -1 if empty */ |
188 |
> |
/** Returns the index of the maximum element, or -1 if empty */ |
189 |
|
public int indexOfMax(); |
190 |
< |
/** Return the sum of all elements */ |
190 |
> |
/** Returns the sum of all elements */ |
191 |
|
public long sum(); |
192 |
< |
/** Return the arithmetic average of all elements */ |
192 |
> |
/** Returns the arithmetic average of all elements */ |
193 |
|
public double average(); |
194 |
|
} |
195 |
|
|
196 |
|
/** |
197 |
< |
* Returns the executor used for computations |
197 |
> |
* Returns the executor used for computations. |
198 |
|
* @return the executor |
199 |
|
*/ |
200 |
|
public ForkJoinPool getExecutor() { return ex; } |
201 |
|
|
202 |
|
/** |
203 |
< |
* Applies the given procedure to elements |
203 |
> |
* Applies the given procedure to elements. |
204 |
|
* @param procedure the procedure |
205 |
|
*/ |
206 |
|
public void apply(LongProcedure procedure) { |
208 |
|
} |
209 |
|
|
210 |
|
/** |
211 |
< |
* Returns reduction of elements |
211 |
> |
* Returns reduction of elements. |
212 |
|
* @param reducer the reducer |
213 |
|
* @param base the result for an empty array |
214 |
|
* @return reduction |
218 |
|
} |
219 |
|
|
220 |
|
/** |
221 |
< |
* Returns a new ParallelLongArray holding all elements |
221 |
> |
* Returns a new ParallelLongArray holding all elements. |
222 |
|
* @return a new ParallelLongArray holding all elements |
223 |
|
*/ |
224 |
|
public ParallelLongArray all() { |
231 |
|
* @param op the op |
232 |
|
* @return this (to simplify use in expressions) |
233 |
|
*/ |
234 |
< |
public ParallelLongArray replaceWithMapping(LongOp op) { |
234 |
> |
public ParallelLongArray replaceWithMapping(LongOp op) { |
235 |
|
super.replaceWithMapping(op); |
236 |
|
return this; |
237 |
|
} |
249 |
|
|
250 |
|
/** |
251 |
|
* Replaces elements with the results of applying the given |
252 |
< |
* mapping to each index and current element value |
252 |
> |
* mapping to each index and current element value. |
253 |
|
* @param op the op |
254 |
|
* @return this (to simplify use in expressions) |
255 |
|
*/ |
262 |
|
* Replaces elements with the results of applying the given |
263 |
|
* generator. For example, to fill the array with uniform random |
264 |
|
* values, use |
265 |
< |
* <tt>replaceWithGeneratedValue(Ops.longRandom())</tt> |
265 |
> |
* <tt>replaceWithGeneratedValue(Ops.longRandom())</tt>. |
266 |
|
* @param generator the generator |
267 |
|
* @return this (to simplify use in expressions) |
268 |
|
*/ |
283 |
|
|
284 |
|
/** |
285 |
|
* Replaces elements with results of applying |
286 |
< |
* <tt>op(thisElement, otherElement)</tt> |
286 |
> |
* <tt>op(thisElement, otherElement)</tt>. |
287 |
|
* @param other the other array |
288 |
|
* @param combiner the combiner |
289 |
|
* @return this (to simplify use in expressions) |
297 |
|
|
298 |
|
/** |
299 |
|
* Replaces elements with results of applying |
300 |
< |
* <tt>op(thisElement, otherElement)</tt> |
300 |
> |
* <tt>op(thisElement, otherElement)</tt>. |
301 |
|
* @param other the other array |
302 |
|
* @param combiner the combiner |
303 |
|
* @return this (to simplify use in expressions) |
312 |
|
|
313 |
|
/** |
314 |
|
* Returns the index of some element equal to given target, or -1 |
315 |
< |
* if not present |
315 |
> |
* if not present. |
316 |
|
* @param target the element to search for |
317 |
|
* @return the index or -1 if not present |
318 |
|
*/ |
349 |
|
* to locate minimum and maximum elements. |
350 |
|
* @param comparator the comparator to use for |
351 |
|
* locating minimum and maximum elements |
352 |
< |
* @return the summary. |
352 |
> |
* @return the summary |
353 |
|
*/ |
354 |
|
public ParallelLongArray.SummaryStatistics summary |
355 |
|
(LongComparator comparator) { |
357 |
|
} |
358 |
|
|
359 |
|
/** |
360 |
< |
* Returns summary statistics, using natural comparator |
361 |
< |
* @return the summary. |
360 |
> |
* Returns summary statistics, using natural comparator. |
361 |
> |
* @return the summary |
362 |
|
*/ |
363 |
|
public ParallelLongArray.SummaryStatistics summary() { |
364 |
|
return super.summary(); |
365 |
|
} |
366 |
|
|
367 |
|
/** |
368 |
< |
* Returns the minimum element, or Long.MAX_VALUE if empty |
368 |
> |
* Returns the minimum element, or Long.MAX_VALUE if empty. |
369 |
|
* @param comparator the comparator |
370 |
|
* @return minimum element, or Long.MAX_VALUE if empty |
371 |
|
*/ |
374 |
|
} |
375 |
|
|
376 |
|
/** |
377 |
< |
* Returns the minimum element, or Long.MAX_VALUE if empty, |
377 |
> |
* Returns the minimum element, or Long.MAX_VALUE if empty. |
378 |
|
* @return minimum element, or Long.MAX_VALUE if empty |
379 |
|
*/ |
380 |
|
public long min() { |
382 |
|
} |
383 |
|
|
384 |
|
/** |
385 |
< |
* Returns the maximum element, or Long.MIN_VALUE if empty |
385 |
> |
* Returns the maximum element, or Long.MIN_VALUE if empty. |
386 |
|
* @param comparator the comparator |
387 |
|
* @return maximum element, or Long.MIN_VALUE if empty |
388 |
|
*/ |
391 |
|
} |
392 |
|
|
393 |
|
/** |
394 |
< |
* Returns the maximum element, or Long.MIN_VALUE if empty |
394 |
> |
* Returns the maximum element, or Long.MIN_VALUE if empty. |
395 |
|
* @return maximum element, or Long.MIN_VALUE if empty |
396 |
|
*/ |
397 |
|
public long max() { |
445 |
|
* Sorts the array, assuming all elements are Comparable. Unlike |
446 |
|
* Arrays.sort, this sort does not guarantee that elements |
447 |
|
* with equal keys maintain their relative position in the array. |
448 |
< |
* @throws ClassCastException if any element is not Comparable. |
448 |
> |
* @throws ClassCastException if any element is not Comparable |
449 |
|
* @return this (to simplify use in expressions) |
450 |
|
*/ |
451 |
|
public ParallelLongArray sort() { |
552 |
|
} |
553 |
|
|
554 |
|
/** |
555 |
< |
* Returns the sum of elements |
555 |
> |
* Returns the sum of elements. |
556 |
|
* @return the sum of elements |
557 |
|
*/ |
558 |
|
public long sum() { |
560 |
|
} |
561 |
|
|
562 |
|
/** |
563 |
< |
* Replaces each element with the running sum |
563 |
> |
* Replaces each element with the running sum. |
564 |
|
* @return this (to simplify use in expressions) |
565 |
|
*/ |
566 |
|
public ParallelLongArray cumulateSum() { |
569 |
|
} |
570 |
|
|
571 |
|
/** |
572 |
< |
* Replaces each element with its prefix sum |
572 |
> |
* Replaces each element with its prefix sum. |
573 |
|
* @return the total sum |
574 |
|
*/ |
575 |
|
public long precumulateSum() { |
592 |
|
/** |
593 |
|
* Returns an operation prefix that causes a method to operate |
594 |
|
* only on the elements of the array for which the given selector |
595 |
< |
* returns true |
595 |
> |
* returns true. |
596 |
|
* @param selector the selector |
597 |
|
* @return operation prefix |
598 |
|
*/ |
603 |
|
/** |
604 |
|
* Returns an operation prefix that causes a method to operate |
605 |
|
* only on elements for which the given binary selector returns |
606 |
< |
* true |
606 |
> |
* true. |
607 |
|
* @param selector the selector |
608 |
|
* @return operation prefix |
609 |
|
*/ |
616 |
|
/** |
617 |
|
* Returns an operation prefix that causes a method to operate |
618 |
|
* only on elements for which the given indexed selector returns |
619 |
< |
* true |
619 |
> |
* true. |
620 |
|
* @param selector the selector |
621 |
|
* @return operation prefix |
622 |
|
*/ |
664 |
|
* @param other the other array |
665 |
|
* @return operation prefix |
666 |
|
* @throws IllegalArgumentException if other array is a |
667 |
< |
* filtered view (all filters must precede all mappings). |
667 |
> |
* filtered view (all filters must precede all mappings) |
668 |
|
*/ |
669 |
|
public <V,W,X> ParallelLongArrayWithMapping<W> withMapping |
670 |
|
(LongAndObjectToObject<? super V, ? extends W> combiner, |
679 |
|
* @param other the other array |
680 |
|
* @return operation prefix |
681 |
|
* @throws IllegalArgumentException if other array is a |
682 |
< |
* filtered view (all filters must precede all mappings). |
682 |
> |
* filtered view (all filters must precede all mappings) |
683 |
|
*/ |
684 |
|
public <V> ParallelLongArrayWithMapping<V> withMapping |
685 |
|
(LongAndDoubleToObject<? extends V> combiner, |
694 |
|
* @param other the other array |
695 |
|
* @return operation prefix |
696 |
|
* @throws IllegalArgumentException if other array is a |
697 |
< |
* filtered view (all filters must precede all mappings). |
697 |
> |
* filtered view (all filters must precede all mappings) |
698 |
|
*/ |
699 |
|
public <V> ParallelLongArrayWithMapping<V> withMapping |
700 |
|
(LongAndLongToObject<? extends V> combiner, |
709 |
|
* @param other the other array |
710 |
|
* @return operation prefix |
711 |
|
* @throws IllegalArgumentException if other array is a |
712 |
< |
* filtered view (all filters must precede all mappings). |
712 |
> |
* filtered view (all filters must precede all mappings) |
713 |
|
*/ |
714 |
|
public <V,W> ParallelLongArrayWithDoubleMapping withMapping |
715 |
|
(LongAndObjectToDouble<? super V> combiner, |
724 |
|
* @param other the other array |
725 |
|
* @return operation prefix |
726 |
|
* @throws IllegalArgumentException if other array is a |
727 |
< |
* filtered view (all filters must precede all mappings). |
727 |
> |
* filtered view (all filters must precede all mappings) |
728 |
|
*/ |
729 |
|
public ParallelLongArrayWithDoubleMapping withMapping |
730 |
|
(LongAndDoubleToDouble combiner, |
739 |
|
* @param other the other array |
740 |
|
* @return operation prefix |
741 |
|
* @throws IllegalArgumentException if other array is a |
742 |
< |
* filtered view (all filters must precede all mappings). |
742 |
> |
* filtered view (all filters must precede all mappings) |
743 |
|
*/ |
744 |
|
public ParallelLongArrayWithDoubleMapping withMapping |
745 |
|
(LongAndLongToDouble combiner, |
754 |
|
* @param other the other array |
755 |
|
* @return operation prefix |
756 |
|
* @throws IllegalArgumentException if other array is a |
757 |
< |
* filtered view (all filters must precede all mappings). |
757 |
> |
* filtered view (all filters must precede all mappings) |
758 |
|
*/ |
759 |
|
public <V,W> ParallelLongArrayWithLongMapping withMapping |
760 |
|
(LongAndObjectToLong<? super V> combiner, |
769 |
|
* @param other the other array |
770 |
|
* @return operation prefix |
771 |
|
* @throws IllegalArgumentException if other array is a |
772 |
< |
* filtered view (all filters must precede all mappings). |
772 |
> |
* filtered view (all filters must precede all mappings) |
773 |
|
*/ |
774 |
|
public ParallelLongArrayWithLongMapping withMapping |
775 |
|
(LongAndDoubleToLong combiner, |
784 |
|
* @param other the other array |
785 |
|
* @return operation prefix |
786 |
|
* @throws IllegalArgumentException if other array is a |
787 |
< |
* filtered view (all filters must precede all mappings). |
787 |
> |
* filtered view (all filters must precede all mappings) |
788 |
|
*/ |
789 |
|
public ParallelLongArrayWithLongMapping withMapping |
790 |
|
(BinaryLongOp combiner, |
837 |
|
* support the remove operation. However, a full |
838 |
|
* <tt>ListIterator</tt> supporting add, remove, and set |
839 |
|
* operations is available via {@link #asList}. |
840 |
< |
* @return an iterator stepping through each element. |
840 |
> |
* @return an iterator stepping through each element |
841 |
|
*/ |
842 |
|
public Iterator<Long> iterator() { |
843 |
|
return new ParallelLongArrayIterator(array, fence); |
889 |
|
public int size() { return fence; } |
890 |
|
|
891 |
|
/** |
892 |
< |
* Returns the underlying array used for computations |
892 |
> |
* Returns the underlying array used for computations. |
893 |
|
* @return the array |
894 |
|
*/ |
895 |
|
public long[] getArray() { return array; } |
896 |
|
|
897 |
|
/** |
898 |
< |
* Returns the element of the array at the given index |
898 |
> |
* Returns the element of the array at the given index. |
899 |
|
* @param i the index |
900 |
|
* @return the element of the array at the given index |
901 |
|
*/ |
902 |
|
public long get(int i) { return array[i]; } |
903 |
|
|
904 |
|
/** |
905 |
< |
* Sets the element of the array at the given index to the given value |
905 |
> |
* Sets the element of the array at the given index to the given value. |
906 |
|
* @param i the index |
907 |
|
* @param x the value |
908 |
|
*/ |
923 |
|
* than the length of the underlying array, causes computations to |
924 |
|
* ignore elements past the given limit. |
925 |
|
* @param newLimit the new upper bound |
926 |
< |
* @throws IllegalArgumentException if newLimit less than zero. |
926 |
> |
* @throws IllegalArgumentException if newLimit less than zero |
927 |
|
*/ |
928 |
|
public final void setLimit(int newLimit) { |
929 |
|
if (newLimit < 0) |
965 |
|
} |
966 |
|
|
967 |
|
/** |
968 |
< |
* Make len slots available at index |
968 |
> |
* Makes len slots available at index. |
969 |
|
*/ |
970 |
|
final void insertSlotsAt(int index, int len) { |
971 |
|
if (len <= 0) |
1207 |
|
} |
1208 |
|
|
1209 |
|
} |
1210 |
– |
|