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

Comparing jsr166/src/extra166y/ParallelDoubleArray.java (file contents):
Revision 1.1 by dl, Tue Jan 6 14:30:58 2009 UTC vs.
Revision 1.14 by jsr166, Sun Jan 18 20:17:32 2015 UTC

# Line 1 | Line 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 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   package extra166y;
8 +
9   import jsr166y.*;
10   import static extra166y.Ops.*;
11   import java.util.*;
# Line 61 | Line 62 | public class ParallelDoubleArray extends
62  
63      /**
64       * Creates a new ParallelDoubleArray using the given executor and
65 <     * an array of the given size
65 >     * an array of the given size.
66       * @param size the array size
67       * @param executor the executor
68       */
# Line 137 | Line 138 | public class ParallelDoubleArray extends
138       * mapped ParallelDoubleArray.
139       */
140      public static interface SummaryStatistics {
141 <        /** Return the number of elements */
141 >        /** Returns the number of elements */
142          public int size();
143 <        /** Return the minimum element, or Double.MAX_VALUE if empty */
143 >        /** Returns the minimum element, or Double.MAX_VALUE if empty */
144          public double min();
145 <        /** Return the maximum element, or -Double.MAX_VALUE if empty */
145 >        /** Returns the maximum element, or -Double.MAX_VALUE if empty */
146          public double max();
147 <        /** Return the index of the minimum element, or -1 if empty */
147 >        /** Returns the index of the minimum element, or -1 if empty */
148          public int indexOfMin();
149 <        /** Return the index of the maximum element, or -1 if empty */
149 >        /** Returns the index of the maximum element, or -1 if empty */
150          public int indexOfMax();
151 <        /** Return the sum of all elements */
151 >        /** Returns the sum of all elements */
152          public double sum();
153 <        /** Return the arithmetic average of all elements */
153 >        /** Returns the arithmetic average of all elements */
154          public double average();
155      }
156  
157      /**
158 <     * Returns the executor used for computations
158 >     * Returns the executor used for computations.
159       * @return the executor
160       */
161      public ForkJoinPool getExecutor() { return ex; }
162  
163      /**
164 <     * Applies the given procedure to elements
164 >     * Applies the given procedure to elements.
165       * @param procedure the procedure
166       */
167      public void apply(DoubleProcedure procedure) {
# Line 168 | Line 169 | public class ParallelDoubleArray extends
169      }
170  
171      /**
172 <     * Returns reduction of elements
172 >     * Returns reduction of elements.
173       * @param reducer the reducer
174       * @param base the result for an empty array
175       * @return reduction
# Line 178 | Line 179 | public class ParallelDoubleArray extends
179      }
180  
181      /**
182 <     * Returns a new ParallelDoubleArray holding all elements
182 >     * Returns a new ParallelDoubleArray holding all elements.
183       * @return a new ParallelDoubleArray holding all elements
184       */
185      public ParallelDoubleArray all() {
# Line 191 | Line 192 | public class ParallelDoubleArray extends
192       * @param op the op
193       * @return this (to simplify use in expressions)
194       */
195 <    public ParallelDoubleArray replaceWithMapping(DoubleOp  op) {
195 >    public ParallelDoubleArray replaceWithMapping(DoubleOp op) {
196          super.replaceWithMapping(op);
197          return this;
198      }
# Line 209 | Line 210 | public class ParallelDoubleArray extends
210  
211      /**
212       * Replaces elements with the results of applying the given
213 <     * mapping to each index and current element value
213 >     * mapping to each index and current element value.
214       * @param op the op
215       * @return this (to simplify use in expressions)
216       */
# Line 222 | Line 223 | public class ParallelDoubleArray extends
223       * Replaces elements with the results of applying the given
224       * generator. For example, to fill the array with uniform random
225       * values, use
226 <     * <tt>replaceWithGeneratedValue(Ops.doubleRandom())</tt>
226 >     * {@code replaceWithGeneratedValue(Ops.doubleRandom())}.
227       * @param generator the generator
228       * @return this (to simplify use in expressions)
229       */
# Line 243 | Line 244 | public class ParallelDoubleArray extends
244  
245      /**
246       * Replaces elements with results of applying
247 <     * <tt>op(thisElement, otherElement)</tt>
247 >     * {@code op(thisElement, otherElement)}.
248       * @param other the other array
249       * @param combiner the combiner
250       * @return this (to simplify use in expressions)
251       * @throws ArrayIndexOutOfBoundsException if other array has
252 <     * fewer elements than this array.
252 >     * fewer elements than this array
253       */
254      public ParallelDoubleArray replaceWithMapping
255          (BinaryDoubleOp combiner, ParallelDoubleArrayWithDoubleMapping other) {
# Line 258 | Line 259 | public class ParallelDoubleArray extends
259  
260      /**
261       * Replaces elements with results of applying
262 <     * <tt>op(thisElement, otherElement)</tt>
262 >     * {@code op(thisElement, otherElement)}.
263       * @param other the other array
264       * @param combiner the combiner
265       * @return this (to simplify use in expressions)
266       * @throws ArrayIndexOutOfBoundsException if other array has
267 <     * fewer elements than this array.
267 >     * fewer elements than this array
268       */
269      public ParallelDoubleArray replaceWithMapping(BinaryDoubleOp combiner,
270                                                    double[] other) {
# Line 273 | Line 274 | public class ParallelDoubleArray extends
274  
275      /**
276       * Returns the index of some element equal to given target, or -1
277 <     * if not present
277 >     * if not present.
278       * @param target the element to search for
279       * @return the index or -1 if not present
280       */
# Line 310 | Line 311 | public class ParallelDoubleArray extends
311       * to locate minimum and maximum elements.
312       * @param comparator the comparator to use for
313       * locating minimum and maximum elements
314 <     * @return the summary.
314 >     * @return the summary
315       */
316      public ParallelDoubleArray.SummaryStatistics summary
317          (DoubleComparator comparator) {
# Line 318 | Line 319 | public class ParallelDoubleArray extends
319      }
320  
321      /**
322 <     * Returns summary statistics, using natural comparator
323 <     * @return the summary.
322 >     * Returns summary statistics, using natural comparator.
323 >     * @return the summary
324       */
325      public ParallelDoubleArray.SummaryStatistics summary() {
326          return super.summary();
327      }
328  
329      /**
330 <     * Returns the minimum element, or Double.MAX_VALUE if empty
330 >     * Returns the minimum element, or Double.MAX_VALUE if empty.
331       * @param comparator the comparator
332       * @return minimum element, or Double.MAX_VALUE if empty
333       */
# Line 335 | Line 336 | public class ParallelDoubleArray extends
336      }
337  
338      /**
339 <     * Returns the minimum element, or Double.MAX_VALUE if empty,
339 >     * Returns the minimum element, or Double.MAX_VALUE if empty.
340       * @return minimum element, or Double.MAX_VALUE if empty
341       */
342      public double min() {
# Line 343 | Line 344 | public class ParallelDoubleArray extends
344      }
345  
346      /**
347 <     * Returns the maximum element, or -Double.MAX_VALUE if empty
347 >     * Returns the maximum element, or -Double.MAX_VALUE if empty.
348       * @param comparator the comparator
349       * @return maximum element, or -Double.MAX_VALUE if empty
350       */
# Line 352 | Line 353 | public class ParallelDoubleArray extends
353      }
354  
355      /**
356 <     * Returns the maximum element, or -Double.MAX_VALUE if empty
356 >     * Returns the maximum element, or -Double.MAX_VALUE if empty.
357       * @return maximum element, or -Double.MAX_VALUE if empty
358       */
359      public double max() {
# Line 362 | Line 363 | public class ParallelDoubleArray extends
363      /**
364       * Replaces each element with the running cumulation of applying
365       * the given reducer. For example, if the contents are the numbers
366 <     * <tt>1, 2, 3</tt>, and the reducer operation adds numbers, then
367 <     * after invocation of this method, the contents would be <tt>1,
368 <     * 3, 6</tt> (that is, <tt>1, 1+2, 1+2+3</tt>);
366 >     * {@code 1, 2, 3}, and the reducer operation adds numbers, then
367 >     * after invocation of this method, the contents would be {@code 1,
368 >     * 3, 6} (that is, {@code 1, 1+2, 1+2+3}).
369       * @param reducer the reducer
370       * @param base the result for an empty array
371       * @return this (to simplify use in expressions)
# Line 377 | Line 378 | public class ParallelDoubleArray extends
378      /**
379       * Replaces each element with the cumulation of applying the given
380       * reducer to all previous values, and returns the total
381 <     * reduction. For example, if the contents are the numbers <tt>1,
382 <     * 2, 3</tt>, and the reducer operation adds numbers, then after
383 <     * invocation of this method, the contents would be <tt>0, 1,
384 <     * 3</tt> (that is, <tt>0, 0+1, 0+1+2</tt>, and the return value
385 <     * would be 6 (that is, <tt> 1+2+3</tt>);
381 >     * reduction. For example, if the contents are the numbers {@code 1,
382 >     * 2, 3}, and the reducer operation adds numbers, then after
383 >     * invocation of this method, the contents would be {@code 0, 1,
384 >     * 3} (that is, {@code 0, 0+1, 0+1+2}, and the return value
385 >     * would be 6 (that is, {@code 1+2+3}).
386       * @param reducer the reducer
387       * @param base the result for an empty array
388       * @return the total reduction
# Line 406 | Line 407 | public class ParallelDoubleArray extends
407       * Sorts the array, assuming all elements are Comparable. Unlike
408       * Arrays.sort, this sort does not guarantee that elements
409       * with equal keys maintain their relative position in the array.
409     * @throws ClassCastException if any element is not Comparable.
410       * @return this (to simplify use in expressions)
411 +     * @throws ClassCastException if any element is not Comparable
412       */
413      public ParallelDoubleArray sort() {
414          super.sort();
# Line 439 | Line 440 | public class ParallelDoubleArray extends
440      }
441  
442      /**
443 <     * Equivalent to <tt>asList().addAll</tt> but specialized for
443 >     * Equivalent to {@code asList().addAll} but specialized for
444       * array arguments and likely to be more efficient.
445       * @param other the elements to add
446       * @return this (to simplify use in expressions)
# Line 502 | Line 503 | public class ParallelDoubleArray extends
503          removeSlotsAt(f.offset, fence);
504          return this;
505      }
506 +
507      /**
508       * Returns true if all elements at the same relative positions
509       * of this and other array are equal.
# Line 514 | Line 516 | public class ParallelDoubleArray extends
516      }
517  
518      /**
519 <     * Returns the sum of elements
519 >     * Returns the sum of elements.
520       * @return the sum of elements
521       */
522      public double sum() {
# Line 522 | Line 524 | public class ParallelDoubleArray extends
524      }
525  
526      /**
527 <     * Replaces each element with the running sum
527 >     * Replaces each element with the running sum.
528       * @return this (to simplify use in expressions)
529       */
530      public ParallelDoubleArray cumulateSum() {
# Line 531 | Line 533 | public class ParallelDoubleArray extends
533      }
534  
535      /**
536 <     * Replaces each element with its prefix sum
536 >     * Replaces each element with its prefix sum.
537       * @return the total sum
538       */
539      public double precumulateSum() {
# Line 554 | Line 556 | public class ParallelDoubleArray extends
556      /**
557       * Returns an operation prefix that causes a method to operate
558       * only on the elements of the array for which the given selector
559 <     * returns true
559 >     * returns true.
560       * @param selector the selector
561       * @return operation prefix
562       */
# Line 565 | Line 567 | public class ParallelDoubleArray extends
567      /**
568       * Returns an operation prefix that causes a method to operate
569       * only on elements for which the given binary selector returns
570 <     * true
570 >     * true.
571       * @param selector the selector
572       * @return operation prefix
573       */
# Line 578 | Line 580 | public class ParallelDoubleArray extends
580      /**
581       * Returns an operation prefix that causes a method to operate
582       * only on elements for which the given indexed selector returns
583 <     * true
583 >     * true.
584       * @param selector the selector
585       * @return operation prefix
586       */
# Line 625 | Line 627 | public class ParallelDoubleArray extends
627       * @param other the other array
628       * @return operation prefix
629       * @throws IllegalArgumentException if other array is a
630 <     * filtered view (all filters must precede all mappings).
630 >     * filtered view (all filters must precede all mappings)
631       */
632      public <V,W,X> ParallelDoubleArrayWithMapping<W> withMapping
633          (DoubleAndObjectToObject<? super V, ? extends W> combiner,
# Line 640 | Line 642 | public class ParallelDoubleArray extends
642       * @param other the other array
643       * @return operation prefix
644       * @throws IllegalArgumentException if other array is a
645 <     * filtered view (all filters must precede all mappings).
645 >     * filtered view (all filters must precede all mappings)
646       */
647      public <V> ParallelDoubleArrayWithMapping<V> withMapping
648          (DoubleAndDoubleToObject<? extends V> combiner,
# Line 655 | Line 657 | public class ParallelDoubleArray extends
657       * @param other the other array
658       * @return operation prefix
659       * @throws IllegalArgumentException if other array is a
660 <     * filtered view (all filters must precede all mappings).
660 >     * filtered view (all filters must precede all mappings)
661       */
662      public <V> ParallelDoubleArrayWithMapping<V> withMapping
663          (DoubleAndLongToObject<? extends V> combiner,
# Line 670 | Line 672 | public class ParallelDoubleArray extends
672       * @param other the other array
673       * @return operation prefix
674       * @throws IllegalArgumentException if other array is a
675 <     * filtered view (all filters must precede all mappings).
675 >     * filtered view (all filters must precede all mappings)
676       */
677      public <V,W> ParallelDoubleArrayWithDoubleMapping withMapping
678          (DoubleAndObjectToDouble<? super V> combiner,
# Line 685 | Line 687 | public class ParallelDoubleArray extends
687       * @param other the other array
688       * @return operation prefix
689       * @throws IllegalArgumentException if other array is a
690 <     * filtered view (all filters must precede all mappings).
690 >     * filtered view (all filters must precede all mappings)
691       */
692      public ParallelDoubleArrayWithDoubleMapping withMapping
693          (BinaryDoubleOp combiner,
# Line 700 | Line 702 | public class ParallelDoubleArray extends
702       * @param other the other array
703       * @return operation prefix
704       * @throws IllegalArgumentException if other array is a
705 <     * filtered view (all filters must precede all mappings).
705 >     * filtered view (all filters must precede all mappings)
706       */
707      public ParallelDoubleArrayWithDoubleMapping withMapping
708          (DoubleAndLongToDouble combiner,
# Line 715 | Line 717 | public class ParallelDoubleArray extends
717       * @param other the other array
718       * @return operation prefix
719       * @throws IllegalArgumentException if other array is a
720 <     * filtered view (all filters must precede all mappings).
720 >     * filtered view (all filters must precede all mappings)
721       */
722      public <V,W> ParallelDoubleArrayWithLongMapping withMapping
723          (DoubleAndObjectToLong<? super V> combiner,
# Line 730 | Line 732 | public class ParallelDoubleArray extends
732       * @param other the other array
733       * @return operation prefix
734       * @throws IllegalArgumentException if other array is a
735 <     * filtered view (all filters must precede all mappings).
735 >     * filtered view (all filters must precede all mappings)
736       */
737      public ParallelDoubleArrayWithLongMapping withMapping
738          (DoubleAndDoubleToLong combiner,
# Line 745 | Line 747 | public class ParallelDoubleArray extends
747       * @param other the other array
748       * @return operation prefix
749       * @throws IllegalArgumentException if other array is a
750 <     * filtered view (all filters must precede all mappings).
750 >     * filtered view (all filters must precede all mappings)
751       */
752      public ParallelDoubleArrayWithLongMapping withMapping
753          (DoubleAndLongToLong combiner,
# Line 796 | Line 798 | public class ParallelDoubleArray extends
798       * Returns an iterator stepping through each element of the array
799       * up to the current limit. This iterator does <em>not</em>
800       * support the remove operation. However, a full
801 <     * <tt>ListIterator</tt> supporting add, remove, and set
801 >     * {@code ListIterator} supporting add, remove, and set
802       * operations is available via {@link #asList}.
803 <     * @return an iterator stepping through each element.
803 >     * @return an iterator stepping through each element
804       */
805      public Iterator<Double> iterator() {
806          return new ParallelDoubleArrayIterator(array, fence);
# Line 851 | Line 853 | public class ParallelDoubleArray extends
853      public int size() { return fence; }
854  
855      /**
856 <     * Returns the underlying array used for computations
856 >     * Returns the underlying array used for computations.
857       * @return the array
858       */
859      public double[] getArray() { return array; }
860  
861      /**
862 <     * Returns the element of the array at the given index
862 >     * Returns the element of the array at the given index.
863       * @param i the index
864       * @return the element of the array at the given index
865       */
866      public double get(int i) { return array[i]; }
867  
868      /**
869 <     * Sets the element of the array at the given index to the given value
869 >     * Sets the element of the array at the given index to the given value.
870       * @param i the index
871       * @param x the value
872       */
873      public void set(int i, double x) { array[i] = x; }
874  
875      /**
876 <     * Equivalent to <tt>asList().toString()</tt>
876 >     * Equivalent to {@code asList().toString()}.
877       * @return a string representation
878       */
879      public String toString() {
# Line 885 | Line 887 | public class ParallelDoubleArray extends
887       * than the length of the underlying array, causes computations to
888       * ignore elements past the given limit.
889       * @param newLimit the new upper bound
890 <     * @throws IllegalArgumentException if newLimit less than zero.
890 >     * @throws IllegalArgumentException if newLimit less than zero
891       */
892      public final void setLimit(int newLimit) {
893          if (newLimit < 0)
# Line 922 | Line 924 | public class ParallelDoubleArray extends
924      }
925  
926      /**
927 <     * Make len slots available at index
927 >     * Makes len slots available at index.
928       */
929      final void insertSlotsAt(int index, int len) {
930          if (len <= 0)
# Line 1164 | Line 1166 | public class ParallelDoubleArray extends
1166      }
1167  
1168   }
1167

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines