ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelLongArray.java
(Generate patch)

Comparing jsr166/src/extra166y/ParallelLongArray.java (file contents):
Revision 1.5 by jsr166, Tue Feb 21 01:54:03 2012 UTC vs.
Revision 1.16 by jsr166, Sun Jan 18 20:17:32 2015 UTC

# Line 5 | Line 5
5   */
6  
7   package extra166y;
8 +
9   import jsr166y.*;
10   import static extra166y.Ops.*;
11   import java.util.*;
# Line 46 | Line 47 | import java.lang.reflect.Array;
47   *     public long op(int i) { return i + 2; } };
48   *   static LongPredicate notDivisibleBy(final long p) {
49   *     return new LongPredicate() {
50 < *        public boolean op(long n) { return n &lt;= p || (n % p) != 0; }
50 > *       public boolean op(long n) { return n &lt;= p || (n % p) != 0; }
51   *     }; }
52   *   static LongPredicate notProbablePrime = new LongPredicate() {
53   *     private static final int CERTAINTY = 8;
# Line 101 | Line 102 | public class ParallelLongArray extends A
102  
103      /**
104       * Creates a new ParallelLongArray using the given executor and
105 <     * an array of the given size
105 >     * an array of the given size.
106       * @param size the array size
107       * @param executor the executor
108       */
# Line 194 | Line 195 | public class ParallelLongArray extends A
195      }
196  
197      /**
198 <     * Returns the executor used for computations
198 >     * Returns the executor used for computations.
199       * @return the executor
200       */
201      public ForkJoinPool getExecutor() { return ex; }
202  
203      /**
204 <     * Applies the given procedure to elements
204 >     * Applies the given procedure to elements.
205       * @param procedure the procedure
206       */
207      public void apply(LongProcedure procedure) {
# Line 208 | Line 209 | public class ParallelLongArray extends A
209      }
210  
211      /**
212 <     * Returns reduction of elements
212 >     * Returns reduction of elements.
213       * @param reducer the reducer
214       * @param base the result for an empty array
215       * @return reduction
# Line 218 | Line 219 | public class ParallelLongArray extends A
219      }
220  
221      /**
222 <     * Returns a new ParallelLongArray holding all elements
222 >     * Returns a new ParallelLongArray holding all elements.
223       * @return a new ParallelLongArray holding all elements
224       */
225      public ParallelLongArray all() {
# Line 249 | Line 250 | public class ParallelLongArray extends A
250  
251      /**
252       * Replaces elements with the results of applying the given
253 <     * mapping to each index and current element value
253 >     * mapping to each index and current element value.
254       * @param op the op
255       * @return this (to simplify use in expressions)
256       */
# Line 262 | Line 263 | public class ParallelLongArray extends A
263       * Replaces elements with the results of applying the given
264       * generator. For example, to fill the array with uniform random
265       * values, use
266 <     * <tt>replaceWithGeneratedValue(Ops.longRandom())</tt>
266 >     * {@code replaceWithGeneratedValue(Ops.longRandom())}.
267       * @param generator the generator
268       * @return this (to simplify use in expressions)
269       */
# Line 283 | Line 284 | public class ParallelLongArray extends A
284  
285      /**
286       * Replaces elements with results of applying
287 <     * <tt>op(thisElement, otherElement)</tt>
287 >     * {@code op(thisElement, otherElement)}.
288       * @param other the other array
289       * @param combiner the combiner
290       * @return this (to simplify use in expressions)
# Line 297 | Line 298 | public class ParallelLongArray extends A
298  
299      /**
300       * Replaces elements with results of applying
301 <     * <tt>op(thisElement, otherElement)</tt>
301 >     * {@code op(thisElement, otherElement)}.
302       * @param other the other array
303       * @param combiner the combiner
304       * @return this (to simplify use in expressions)
305       * @throws ArrayIndexOutOfBoundsException if other array has
306 <     * fewer elements than this array.
306 >     * fewer elements than this array
307       */
308      public ParallelLongArray replaceWithMapping(BinaryLongOp combiner,
309                                                  long[] other) {
# Line 312 | Line 313 | public class ParallelLongArray extends A
313  
314      /**
315       * Returns the index of some element equal to given target, or -1
316 <     * if not present
316 >     * if not present.
317       * @param target the element to search for
318       * @return the index or -1 if not present
319       */
# Line 349 | Line 350 | public class ParallelLongArray extends A
350       * to locate minimum and maximum elements.
351       * @param comparator the comparator to use for
352       * locating minimum and maximum elements
353 <     * @return the summary.
353 >     * @return the summary
354       */
355      public ParallelLongArray.SummaryStatistics summary
356          (LongComparator comparator) {
# Line 357 | Line 358 | public class ParallelLongArray extends A
358      }
359  
360      /**
361 <     * Returns summary statistics, using natural comparator
362 <     * @return the summary.
361 >     * Returns summary statistics, using natural comparator.
362 >     * @return the summary
363       */
364      public ParallelLongArray.SummaryStatistics summary() {
365          return super.summary();
366      }
367  
368      /**
369 <     * Returns the minimum element, or Long.MAX_VALUE if empty
369 >     * Returns the minimum element, or Long.MAX_VALUE if empty.
370       * @param comparator the comparator
371       * @return minimum element, or Long.MAX_VALUE if empty
372       */
# Line 374 | Line 375 | public class ParallelLongArray extends A
375      }
376  
377      /**
378 <     * Returns the minimum element, or Long.MAX_VALUE if empty,
378 >     * Returns the minimum element, or Long.MAX_VALUE if empty.
379       * @return minimum element, or Long.MAX_VALUE if empty
380       */
381      public long min() {
# Line 382 | Line 383 | public class ParallelLongArray extends A
383      }
384  
385      /**
386 <     * Returns the maximum element, or Long.MIN_VALUE if empty
386 >     * Returns the maximum element, or Long.MIN_VALUE if empty.
387       * @param comparator the comparator
388       * @return maximum element, or Long.MIN_VALUE if empty
389       */
# Line 391 | Line 392 | public class ParallelLongArray extends A
392      }
393  
394      /**
395 <     * Returns the maximum element, or Long.MIN_VALUE if empty
395 >     * Returns the maximum element, or Long.MIN_VALUE if empty.
396       * @return maximum element, or Long.MIN_VALUE if empty
397       */
398      public long max() {
# Line 401 | Line 402 | public class ParallelLongArray extends A
402      /**
403       * Replaces each element with the running cumulation of applying
404       * the given reducer. For example, if the contents are the numbers
405 <     * <tt>1, 2, 3</tt>, and the reducer operation adds numbers, then
406 <     * after invocation of this method, the contents would be <tt>1,
407 <     * 3, 6</tt> (that is, <tt>1, 1+2, 1+2+3</tt>);
405 >     * {@code 1, 2, 3}, and the reducer operation adds numbers, then
406 >     * after invocation of this method, the contents would be {@code 1,
407 >     * 3, 6} (that is, {@code 1, 1+2, 1+2+3}).
408       * @param reducer the reducer
409       * @param base the result for an empty array
410       * @return this (to simplify use in expressions)
# Line 416 | Line 417 | public class ParallelLongArray extends A
417      /**
418       * Replaces each element with the cumulation of applying the given
419       * reducer to all previous values, and returns the total
420 <     * reduction. For example, if the contents are the numbers <tt>1,
421 <     * 2, 3</tt>, and the reducer operation adds numbers, then after
422 <     * invocation of this method, the contents would be <tt>0, 1,
423 <     * 3</tt> (that is, <tt>0, 0+1, 0+1+2</tt>, and the return value
424 <     * would be 6 (that is, <tt> 1+2+3</tt>);
420 >     * reduction. For example, if the contents are the numbers {@code 1,
421 >     * 2, 3}, and the reducer operation adds numbers, then after
422 >     * invocation of this method, the contents would be {@code 0, 1,
423 >     * 3} (that is, {@code 0, 0+1, 0+1+2}, and the return value
424 >     * would be 6 (that is, {@code 1+2+3}).
425       * @param reducer the reducer
426       * @param base the result for an empty array
427       * @return the total reduction
# Line 445 | Line 446 | public class ParallelLongArray extends A
446       * Sorts the array, assuming all elements are Comparable. Unlike
447       * Arrays.sort, this sort does not guarantee that elements
448       * with equal keys maintain their relative position in the array.
448     * @throws ClassCastException if any element is not Comparable.
449       * @return this (to simplify use in expressions)
450 +     * @throws ClassCastException if any element is not Comparable
451       */
452      public ParallelLongArray sort() {
453          super.sort();
# Line 478 | Line 479 | public class ParallelLongArray extends A
479      }
480  
481      /**
482 <     * Equivalent to <tt>asList().addAll</tt> but specialized for array
482 >     * Equivalent to {@code asList().addAll} but specialized for array
483       * arguments and likely to be more efficient.
484       * @param other the elements to add
485       * @return this (to simplify use in expressions)
# Line 552 | Line 553 | public class ParallelLongArray extends A
553      }
554  
555      /**
556 <     * Returns the sum of elements
556 >     * Returns the sum of elements.
557       * @return the sum of elements
558       */
559      public long sum() {
# Line 560 | Line 561 | public class ParallelLongArray extends A
561      }
562  
563      /**
564 <     * Replaces each element with the running sum
564 >     * Replaces each element with the running sum.
565       * @return this (to simplify use in expressions)
566       */
567      public ParallelLongArray cumulateSum() {
# Line 569 | Line 570 | public class ParallelLongArray extends A
570      }
571  
572      /**
573 <     * Replaces each element with its prefix sum
573 >     * Replaces each element with its prefix sum.
574       * @return the total sum
575       */
576      public long precumulateSum() {
# Line 592 | Line 593 | public class ParallelLongArray extends A
593      /**
594       * Returns an operation prefix that causes a method to operate
595       * only on the elements of the array for which the given selector
596 <     * returns true
596 >     * returns true.
597       * @param selector the selector
598       * @return operation prefix
599       */
# Line 603 | Line 604 | public class ParallelLongArray extends A
604      /**
605       * Returns an operation prefix that causes a method to operate
606       * only on elements for which the given binary selector returns
607 <     * true
607 >     * true.
608       * @param selector the selector
609       * @return operation prefix
610       */
# Line 616 | Line 617 | public class ParallelLongArray extends A
617      /**
618       * Returns an operation prefix that causes a method to operate
619       * only on elements for which the given indexed selector returns
620 <     * true
620 >     * true.
621       * @param selector the selector
622       * @return operation prefix
623       */
# Line 664 | Line 665 | public class ParallelLongArray extends A
665       * @param other the other array
666       * @return operation prefix
667       * @throws IllegalArgumentException if other array is a
668 <     * filtered view (all filters must precede all mappings).
668 >     * filtered view (all filters must precede all mappings)
669       */
670      public <V,W,X> ParallelLongArrayWithMapping<W> withMapping
671          (LongAndObjectToObject<? super V, ? extends W> combiner,
# Line 679 | Line 680 | public class ParallelLongArray extends A
680       * @param other the other array
681       * @return operation prefix
682       * @throws IllegalArgumentException if other array is a
683 <     * filtered view (all filters must precede all mappings).
683 >     * filtered view (all filters must precede all mappings)
684       */
685      public <V> ParallelLongArrayWithMapping<V> withMapping
686          (LongAndDoubleToObject<? extends V> combiner,
# Line 694 | Line 695 | public class ParallelLongArray extends A
695       * @param other the other array
696       * @return operation prefix
697       * @throws IllegalArgumentException if other array is a
698 <     * filtered view (all filters must precede all mappings).
698 >     * filtered view (all filters must precede all mappings)
699       */
700      public <V> ParallelLongArrayWithMapping<V> withMapping
701          (LongAndLongToObject<? extends V> combiner,
# Line 709 | Line 710 | public class ParallelLongArray extends A
710       * @param other the other array
711       * @return operation prefix
712       * @throws IllegalArgumentException if other array is a
713 <     * filtered view (all filters must precede all mappings).
713 >     * filtered view (all filters must precede all mappings)
714       */
715      public <V,W> ParallelLongArrayWithDoubleMapping withMapping
716          (LongAndObjectToDouble<? super V> combiner,
# Line 724 | Line 725 | public class ParallelLongArray extends A
725       * @param other the other array
726       * @return operation prefix
727       * @throws IllegalArgumentException if other array is a
728 <     * filtered view (all filters must precede all mappings).
728 >     * filtered view (all filters must precede all mappings)
729       */
730      public ParallelLongArrayWithDoubleMapping withMapping
731          (LongAndDoubleToDouble combiner,
# Line 739 | Line 740 | public class ParallelLongArray extends A
740       * @param other the other array
741       * @return operation prefix
742       * @throws IllegalArgumentException if other array is a
743 <     * filtered view (all filters must precede all mappings).
743 >     * filtered view (all filters must precede all mappings)
744       */
745      public ParallelLongArrayWithDoubleMapping withMapping
746          (LongAndLongToDouble combiner,
# Line 754 | Line 755 | public class ParallelLongArray extends A
755       * @param other the other array
756       * @return operation prefix
757       * @throws IllegalArgumentException if other array is a
758 <     * filtered view (all filters must precede all mappings).
758 >     * filtered view (all filters must precede all mappings)
759       */
760      public <V,W> ParallelLongArrayWithLongMapping withMapping
761          (LongAndObjectToLong<? super V> combiner,
# Line 769 | Line 770 | public class ParallelLongArray extends A
770       * @param other the other array
771       * @return operation prefix
772       * @throws IllegalArgumentException if other array is a
773 <     * filtered view (all filters must precede all mappings).
773 >     * filtered view (all filters must precede all mappings)
774       */
775      public ParallelLongArrayWithLongMapping withMapping
776          (LongAndDoubleToLong combiner,
# Line 784 | Line 785 | public class ParallelLongArray extends A
785       * @param other the other array
786       * @return operation prefix
787       * @throws IllegalArgumentException if other array is a
788 <     * filtered view (all filters must precede all mappings).
788 >     * filtered view (all filters must precede all mappings)
789       */
790      public ParallelLongArrayWithLongMapping withMapping
791          (BinaryLongOp combiner,
# Line 835 | Line 836 | public class ParallelLongArray extends A
836       * Returns an iterator stepping through each element of the array
837       * up to the current limit. This iterator does <em>not</em>
838       * support the remove operation. However, a full
839 <     * <tt>ListIterator</tt> supporting add, remove, and set
839 >     * {@code ListIterator} supporting add, remove, and set
840       * operations is available via {@link #asList}.
841 <     * @return an iterator stepping through each element.
841 >     * @return an iterator stepping through each element
842       */
843      public Iterator<Long> iterator() {
844          return new ParallelLongArrayIterator(array, fence);
# Line 889 | Line 890 | public class ParallelLongArray extends A
890      public int size() { return fence; }
891  
892      /**
893 <     * Returns the underlying array used for computations
893 >     * Returns the underlying array used for computations.
894       * @return the array
895       */
896      public long[] getArray() { return array; }
897  
898      /**
899 <     * Returns the element of the array at the given index
899 >     * Returns the element of the array at the given index.
900       * @param i the index
901       * @return the element of the array at the given index
902       */
903      public long get(int i) { return array[i]; }
904  
905      /**
906 <     * Sets the element of the array at the given index to the given value
906 >     * Sets the element of the array at the given index to the given value.
907       * @param i the index
908       * @param x the value
909       */
910      public void set(int i, long x) { array[i] = x; }
911  
912      /**
913 <     * Equivalent to <tt>asList().toString()</tt>
913 >     * Equivalent to {@code asList().toString()}.
914       * @return a string representation
915       */
916      public String toString() {
# Line 923 | Line 924 | public class ParallelLongArray extends A
924       * than the length of the underlying array, causes computations to
925       * ignore elements past the given limit.
926       * @param newLimit the new upper bound
927 <     * @throws IllegalArgumentException if newLimit less than zero.
927 >     * @throws IllegalArgumentException if newLimit less than zero
928       */
929      public final void setLimit(int newLimit) {
930          if (newLimit < 0)
# Line 1207 | Line 1208 | public class ParallelLongArray extends A
1208      }
1209  
1210   }
1210

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines