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

Comparing jsr166/src/extra166y/ParallelArray.java (file contents):
Revision 1.8 by jsr166, Sun Dec 30 02:05:53 2012 UTC vs.
Revision 1.18 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 42 | Line 43 | import java.lang.reflect.Array;
43   * <p>A ParallelArray is not a List. It relies on random access across
44   * array elements to support efficient parallel operations.  However,
45   * a ParallelArray can be viewed and manipulated as a List, via method
46 < * {@link ParallelArray#asList}. The <tt>asList</tt> view allows
46 > * {@link ParallelArray#asList}. The {@code asList} view allows
47   * incremental insertion and modification of elements while setting up
48   * a ParallelArray, generally before using it for parallel
49   * operations. Similarly, the list view may be useful when accessing
50   * the results of computations in sequential contexts.  A
51   * ParallelArray may also be created using the elements of any other
52   * Collection, by constructing from the array returned by the
53 < * Collection's <tt>toArray</tt> method. The effects of mutative
54 < * <tt>asList</tt> operations may also be achieved directly using
53 > * Collection's {@code toArray} method. The effects of mutative
54 > * {@code asList} operations may also be achieved directly using
55   * method {@link #setLimit} along with element-by-element access
56   * methods {@link #get}</tt> and {@link #set}.
57   *
# Line 61 | Line 62 | import java.lang.reflect.Array;
62   * {@link ParallelDoubleArray} are also supplied, and designed to
63   * smoothly interoperate with ParallelArrays. You should also use a
64   * ParallelLongArray for processing other integral scalar data
65 < * (<tt>int</tt>, <tt>short</tt>, etc).  And similarly use a
66 < * ParallelDoubleArray for <tt>float</tt> data.  (Further
65 > * ({@code int}, {@code short}, etc).  And similarly use a
66 > * ParallelDoubleArray for {@code float} data.  (Further
67   * specializations for these other types would add clutter without
68   * significantly improving performance beyond that of the Long and
69   * Double versions.)
# Line 70 | Line 71 | import java.lang.reflect.Array;
71   * <p>Most usages of ParallelArray involve sets of operations prefixed
72   * with range bounds, filters, and mappings (including mappings that
73   * combine elements from other ParallelArrays), using
74 < * <tt>withBounds</tt>, <tt>withFilter</tt>, and <tt>withMapping</tt>,
74 > * {@code withBounds}, {@code withFilter}, and {@code withMapping},
75   * respectively. For example,
76 < * <tt>aParallelArray.withFilter(aPredicate).all()</tt> creates a new
76 > * {@code aParallelArray.withFilter(aPredicate).all()} creates a new
77   * ParallelArray containing only those elements matching the
78   * predicate. And for ParallelLongArrays a, b, and c,
79 < * <tt>a.withMapping(CommonOps.longAdder(),b).withMapping(CommonOps.longAdder(),c).min()</tt>
79 > * {@code a.withMapping(CommonOps.longAdder(),b).withMapping(CommonOps.longAdder(),c).min()}
80   * returns the minimum value of a[i]+b[i]+c[i] for all i.  As
81   * illustrated below, a <em>mapping</em> often represents accessing
82   * some field or invoking some method of an element.  These versions
# Line 87 | Line 88 | import java.lang.reflect.Array;
88   * be cascaded, but all filter prefixes must precede all mapping
89   * prefixes, to ensure efficient execution in a single parallel step.
90   * In cases of combined mapping expressions, this rule is only
91 < * dynamically enforced. For example, <tt>pa.withMapping(op,
92 < * pb.withFilter(f))</tt> will compile but throw an exception upon
91 > * dynamically enforced. For example, {@code pa.withMapping(op,
92 > * pb.withFilter(f))} will compile but throw an exception upon
93   * execution because the filter precedes the mapping.
94   *
95   * <p>While series of filters and mappings are allowed, it is
96   * usually more efficient to combine them into single filters or
97   * mappings when possible. For example
98 < * <tt>pa.withMapping(addOne).withMapping(addOne)</tt> is generally
99 < * less efficient than <tt>pa.withMapping(addTwo)</tt>. Methods
100 < * <tt>withIndexedFilter</tt> and <tt>withIndexedMapping</tt> may be
98 > * {@code pa.withMapping(addOne).withMapping(addOne)} is generally
99 > * less efficient than {@code pa.withMapping(addTwo)}. Methods
100 > * {@code withIndexedFilter} and {@code withIndexedMapping} may be
101   * useful when combining such expressions.
102   *
103 < * <p>This class includes some reductions, such as <tt>min</tt>, that
103 > * <p>This class includes some reductions, such as {@code min}, that
104   * are commonly useful for most element types, as well as a combined
105 < * version, <tt>summary</tt>, that computes all of them in a single
105 > * version, {@code summary}, that computes all of them in a single
106   * parallel step, which is normally more efficient than computing each
107   * in turn.
108   *
# Line 117 | Line 118 | import java.lang.reflect.Array;
118   * programming with aggregates is that you must separately define each
119   * of the component functions on elements. For example, the following
120   * returns the maximum Grade Point Average across all senior students,
121 < * given a (fictional) <tt>Student</tt> class:
121 > * given a (fictional) {@code Student} class:
122   *
123   * <pre>
124   * import static Ops.*;
# Line 133 | Line 134 | import java.lang.reflect.Array;
134   *     public boolean op(Student s) { return s.credits &gt; 90; }
135   *   }
136   *   static final IsSenior isSenior = new IsSenior();
137 < *   static final class GpaField implements ObjectToDouble&lt;Student&gt {
137 > *   static final class GpaField implements ObjectToDouble&lt;Student&gt; {
138   *     public double op(Student s) { return s.gpa; }
139   *   }
140   *   static final GpaField gpaField = new GpaField();
# Line 386 | Line 387 | public class ParallelArray<T> extends Ab
387  
388      /**
389       * Replaces elements with results of applying
390 <     * <tt>op(thisElement, otherElement)</tt>.
390 >     * {@code op(thisElement, otherElement)}.
391       * @param other the other array
392       * @param combiner the combiner
393       * @return this (to simplify use in expressions)
# Line 400 | Line 401 | public class ParallelArray<T> extends Ab
401  
402      /**
403       * Replaces elements with results of applying
404 <     * <tt>op(thisElement, otherElement)</tt>.
404 >     * {@code op(thisElement, otherElement)}.
405       * @param other the other array
406       * @param combiner the combiner
407       * @return this (to simplify use in expressions)
# Line 507 | Line 508 | public class ParallelArray<T> extends Ab
508      /**
509       * Replaces each element with the running cumulation of applying
510       * the given reducer. For example, if the contents are the numbers
511 <     * <tt>1, 2, 3</tt>, and the reducer operation adds numbers, then
512 <     * after invocation of this method, the contents would be <tt>1,
513 <     * 3, 6</tt> (that is, <tt>1, 1+2, 1+2+3</tt>);
511 >     * {@code 1, 2, 3}, and the reducer operation adds numbers, then
512 >     * after invocation of this method, the contents would be {@code 1,
513 >     * 3, 6} (that is, {@code 1, 1+2, 1+2+3}).
514       * @param reducer the reducer
515       * @param base the result for an empty array
516       * @return this (to simplify use in expressions)
# Line 522 | Line 523 | public class ParallelArray<T> extends Ab
523      /**
524       * Replaces each element with the cumulation of applying the given
525       * reducer to all previous values, and returns the total
526 <     * reduction. For example, if the contents are the numbers <tt>1,
527 <     * 2, 3</tt>, and the reducer operation adds numbers, then after
528 <     * invocation of this method, the contents would be <tt>0, 1,
529 <     * 3</tt> (that is, <tt>0, 0+1, 0+1+2</tt>, and the return value
530 <     * would be 6 (that is, <tt> 1+2+3</tt>);
526 >     * reduction. For example, if the contents are the numbers {@code 1,
527 >     * 2, 3}, and the reducer operation adds numbers, then after
528 >     * invocation of this method, the contents would be {@code 0, 1,
529 >     * 3} (that is, {@code 0, 0+1, 0+1+2}, and the return value
530 >     * would be 6 (that is, {@code 1+2+3}).
531       * @param reducer the reducer
532       * @param base the result for an empty array
533       * @return the total reduction
534       */
535      public T precumulate(Reducer<T> reducer, T base) {
536 <        return (T)(super.precumulate(reducer, base));
536 >        return super.precumulate(reducer, base);
537      }
538  
539      /**
# Line 551 | Line 552 | public class ParallelArray<T> extends Ab
552       * Sorts the array, assuming all elements are Comparable. Unlike
553       * Arrays.sort, this sort does not guarantee that elements
554       * with equal keys maintain their relative position in the array.
554     * @throws ClassCastException if any element is not Comparable
555       * @return this (to simplify use in expressions)
556 +     * @throws ClassCastException if any element is not Comparable
557       */
558      public ParallelArray<T> sort() {
559          super.sort();
# Line 562 | Line 563 | public class ParallelArray<T> extends Ab
563      /**
564       * Returns a new ParallelArray containing only the non-null unique
565       * elements of this array (that is, without any duplicates), using
566 <     * each element's <tt>equals</tt> method to test for duplication.
566 >     * each element's {@code equals} method to test for duplication.
567       * @return the new ParallelArray
568       */
569      public ParallelArray<T> allUniqueElements() {
# Line 657 | Line 658 | public class ParallelArray<T> extends Ab
658      }
659  
660      /**
661 <     * Equivalent to <tt>asList().addAll</tt> but specialized for array
661 >     * Equivalent to {@code asList().addAll} but specialized for array
662       * arguments and likely to be more efficient.
663       * @param other the elements to add
664       * @return this (to simplify use in expressions)
# Line 755 | Line 756 | public class ParallelArray<T> extends Ab
756       * @param op the op
757       * @return operation prefix
758       */
759 <    public <U> ParallelArrayWithMapping<T, U> withMapping
759 >    public <U> ParallelArrayWithMapping<T,U> withMapping
760          (Op<? super T, ? extends U> op) {
761          return super.withMapping(op);
762      }
# Line 963 | Line 964 | public class ParallelArray<T> extends Ab
964       * Returns an iterator stepping through each element of the array
965       * up to the current limit. This iterator does <em>not</em>
966       * support the remove operation. However, a full
967 <     * <tt>ListIterator</tt> supporting add, remove, and set
967 >     * {@code ListIterator} supporting add, remove, and set
968       * operations is available via {@link #asList}.
969       * @return an iterator stepping through each element
970       */
# Line 1037 | Line 1038 | public class ParallelArray<T> extends Ab
1038      public T[] getArray() { return array; }
1039  
1040      /**
1041 <     * Equivalent to <tt>asList().toString()</tt>
1041 >     * Equivalent to {@code asList().toString()}.
1042       * @return a string representation
1043       */
1044      public String toString() {
# Line 1352 | Line 1353 | public class ParallelArray<T> extends Ab
1353              return a;
1354          }
1355  
1356 <        public <V> V[] toArray(V a[]) {
1356 >        public <V> V[] toArray(V[] a) {
1357              int len = fence;
1358              if (a.length < len) {
1359                  Class elementType = a.getClass().getComponentType();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines