ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelArrayWithDoubleMapping.java
Revision: 1.6
Committed: Sun Jan 18 20:17:32 2015 UTC (9 years, 3 months ago) by jsr166
Branch: MAIN
Changes since 1.5: +1 -0 lines
Log Message:
exactly one blank line before and after package statements

File Contents

# User Rev Content
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.2 * http://creativecommons.org/publicdomain/zero/1.0/
5 dl 1.1 */
6    
7     package extra166y;
8 jsr166 1.6
9 dl 1.1 import jsr166y.*;
10     import static extra166y.Ops.*;
11     import java.util.*;
12     import java.util.concurrent.atomic.*;
13     import java.lang.reflect.Array;
14    
15     /**
16     * A prefix view of ParallelArray that causes operations to apply
17     * to mappings of elements, not to the elements themselves.
18     * Instances of this class may be constructed only via prefix
19     * methods of ParallelArray or its other prefix classes.
20     */
21     public abstract class ParallelArrayWithDoubleMapping<T> extends AbstractParallelAnyArray.OPap<T> {
22     ParallelArrayWithDoubleMapping
23     (ForkJoinPool ex, int origin, int fence, T[] array) {
24     super(ex, origin, fence, array);
25     }
26    
27     /**
28 jsr166 1.4 * Applies the given procedure.
29 dl 1.1 * @param procedure the procedure
30     */
31     public void apply(DoubleProcedure procedure) {
32     ex.invoke(new PAS.FJDApply(this, origin, fence, null, procedure));
33     }
34    
35     /**
36 jsr166 1.4 * Returns reduction of mapped elements.
37 dl 1.1 * @param reducer the reducer
38     * @param base the result for an empty array
39     * @return reduction
40     */
41     public double reduce(DoubleReducer reducer, double base) {
42     PAS.FJDReduce f = new PAS.FJDReduce
43     (this, origin, fence, null, reducer, base);
44     ex.invoke(f);
45     return f.result;
46     }
47    
48     /**
49 jsr166 1.4 * Returns the minimum element, or Double.MAX_VALUE if empty.
50 dl 1.1 * @return minimum element, or Double.MAX_VALUE if empty
51     */
52     public double min() {
53     return reduce(CommonOps.naturalDoubleMinReducer(), Double.MAX_VALUE);
54     }
55    
56     /**
57 jsr166 1.4 * Returns the minimum element, or Double.MAX_VALUE if empty.
58 dl 1.1 * @param comparator the comparator
59     * @return minimum element, or Double.MAX_VALUE if empty
60     */
61     public double min(DoubleComparator comparator) {
62     return reduce(CommonOps.doubleMinReducer(comparator), Double.MAX_VALUE);
63     }
64    
65     /**
66 jsr166 1.4 * Returns the maximum element, or -Double.MAX_VALUE if empty.
67 dl 1.1 * @return maximum element, or -Double.MAX_VALUE if empty
68     */
69     public double max() {
70     return reduce(CommonOps.naturalDoubleMaxReducer(), -Double.MAX_VALUE);
71     }
72    
73     /**
74 jsr166 1.4 * Returns the maximum element, or -Double.MAX_VALUE if empty.
75 dl 1.1 * @param comparator the comparator
76     * @return maximum element, or -Double.MAX_VALUE if empty
77     */
78     public double max(DoubleComparator comparator) {
79     return reduce(CommonOps.doubleMaxReducer(comparator), -Double.MAX_VALUE);
80     }
81    
82     /**
83 jsr166 1.4 * Returns the sum of elements.
84 dl 1.1 * @return the sum of elements
85     */
86     public double sum() {
87     return reduce(CommonOps.doubleAdder(), 0.0);
88     }
89    
90     /**
91 jsr166 1.4 * Returns summary statistics.
92 dl 1.1 * @param comparator the comparator to use for
93     * locating minimum and maximum elements
94 jsr166 1.4 * @return the summary
95 dl 1.1 */
96     public ParallelDoubleArray.SummaryStatistics summary
97     (DoubleComparator comparator) {
98     PAS.FJDStats f = new PAS.FJDStats
99     (this, origin, fence, null, comparator);
100     ex.invoke(f);
101     return f;
102     }
103    
104     /**
105 jsr166 1.4 * Returns summary statistics, using natural comparator.
106     * @return the summary
107 dl 1.1 */
108     public ParallelDoubleArray.SummaryStatistics summary() {
109     return summary(CommonOps.naturalDoubleComparator());
110     }
111    
112     /**
113 jsr166 1.4 * Returns a new ParallelDoubleArray holding mappings.
114 dl 1.1 * @return a new ParallelDoubleArray holding mappings
115     */
116     public ParallelDoubleArray all() {
117     return new ParallelDoubleArray(ex, allDoubles());
118     }
119    
120     /**
121     * Returns an operation prefix that causes a method to operate
122     * on mapped elements of the array using the given op.
123     * @param op the op
124     * @return operation prefix
125     */
126     public abstract ParallelArrayWithDoubleMapping<T> withMapping(DoubleOp op);
127    
128     /**
129     * Returns an operation prefix that causes a method to operate
130     * on mapped elements of the array using the given op.
131     * @param op the op
132     * @return operation prefix
133     */
134     public abstract ParallelArrayWithLongMapping<T> withMapping(DoubleToLong op);
135    
136     /**
137     * Returns an operation prefix that causes a method to operate
138     * on mapped elements of the array using the given op.
139     * @param op the op
140     * @return operation prefix
141     */
142 jsr166 1.5 public abstract <U> ParallelArrayWithMapping<T,U> withMapping
143 dl 1.1 (DoubleToObject<? extends U> op);
144    
145     /**
146     * Returns an operation prefix that causes a method to operate
147     * on binary mappings of this array and the other array.
148     * @param combiner the combiner
149     * @param other the other array
150     * @return operation prefix
151     */
152     public <V,W,X> ParallelArrayWithMapping<T,W> withMapping
153     (DoubleAndObjectToObject<? super V, ? extends W> combiner,
154     ParallelArrayWithMapping<X,V> other) {
155     return withIndexedMapping
156     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
157     }
158    
159     /**
160     * Returns an operation prefix that causes a method to operate
161     * on binary mappings of this array and the other array.
162     * @param combiner the combiner
163     * @param other the other array
164     * @return operation prefix
165     */
166     public <V> ParallelArrayWithMapping<T,V> withMapping
167     (DoubleAndDoubleToObject<? extends V> combiner,
168     ParallelDoubleArrayWithDoubleMapping other) {
169     return withIndexedMapping
170     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
171     }
172    
173     /**
174     * Returns an operation prefix that causes a method to operate
175     * on binary mappings of this array and the other array.
176     * @param combiner the combiner
177     * @param other the other array
178     * @return operation prefix
179     */
180     public <V> ParallelArrayWithMapping<T,V> withMapping
181     (DoubleAndLongToObject<? extends V> combiner,
182     ParallelLongArrayWithLongMapping other) {
183     return withIndexedMapping
184     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
185     }
186    
187     /**
188     * Returns an operation prefix that causes a method to operate
189     * on binary mappings of this array and the other array.
190     * @param combiner the combiner
191     * @param other the other array
192     * @return operation prefix
193     */
194     public <V,W> ParallelArrayWithDoubleMapping<T> withMapping
195     (DoubleAndObjectToDouble<? super V> combiner,
196     ParallelArrayWithMapping<W,V> other) {
197     return withIndexedMapping
198     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
199     }
200    
201     /**
202     * Returns an operation prefix that causes a method to operate
203     * on binary mappings of this array and the other array.
204     * @param combiner the combiner
205     * @param other the other array
206     * @return operation prefix
207     */
208     public ParallelArrayWithDoubleMapping<T> withMapping
209     (BinaryDoubleOp combiner,
210     ParallelDoubleArrayWithDoubleMapping other) {
211     return withIndexedMapping
212     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
213     }
214    
215     /**
216     * Returns an operation prefix that causes a method to operate
217     * on binary mappings of this array and the other array.
218     * @param combiner the combiner
219     * @param other the other array
220     * @return operation prefix
221     */
222     public ParallelArrayWithDoubleMapping<T> withMapping
223     (DoubleAndLongToDouble combiner,
224     ParallelLongArrayWithLongMapping other) {
225     return withIndexedMapping
226     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
227     }
228    
229     /**
230     * Returns an operation prefix that causes a method to operate
231     * on binary mappings of this array and the other array.
232     * @param combiner the combiner
233     * @param other the other array
234     * @return operation prefix
235     */
236     public <V,W> ParallelArrayWithLongMapping<T> withMapping
237     (DoubleAndObjectToLong<? super V> combiner,
238     ParallelArrayWithMapping<W,V> other) {
239     return withIndexedMapping
240     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
241     }
242    
243     /**
244     * Returns an operation prefix that causes a method to operate
245     * on binary mappings of this array and the other array.
246     * @param combiner the combiner
247     * @param other the other array
248     * @return operation prefix
249     */
250     public ParallelArrayWithLongMapping<T> withMapping
251     (DoubleAndDoubleToLong combiner,
252     ParallelDoubleArrayWithDoubleMapping other) {
253     return withIndexedMapping
254     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
255     }
256    
257     /**
258     * Returns an operation prefix that causes a method to operate
259     * on binary mappings of this array and the other array.
260     * @param combiner the combiner
261     * @param other the other array
262     * @return operation prefix
263     */
264     public ParallelArrayWithLongMapping<T> withMapping
265     (DoubleAndLongToLong combiner,
266     ParallelLongArrayWithLongMapping other) {
267     return withIndexedMapping
268     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
269     }
270    
271     /**
272     * Returns an operation prefix that causes a method to operate
273     * on mappings of this array using the given mapper that
274     * accepts as arguments an element's current index and value
275     * (as mapped by preceding mappings, if any), and produces a
276     * new value.
277     * @param mapper the mapper
278     * @return operation prefix
279     */
280     public abstract <V> ParallelArrayWithMapping<T,V> withIndexedMapping
281     (IntAndDoubleToObject<? extends V> mapper);
282    
283     /**
284     * Returns an operation prefix that causes a method to operate
285     * on mappings of this array using the given mapper that
286     * accepts as arguments an element's current index and value
287     * (as mapped by preceding mappings, if any), and produces a
288     * new value.
289     * @param mapper the mapper
290     * @return operation prefix
291     */
292     public abstract ParallelArrayWithDoubleMapping<T> withIndexedMapping
293     (IntAndDoubleToDouble mapper);
294    
295     /**
296     * Returns an operation prefix that causes a method to operate
297     * on mappings of this array using the given mapper that
298     * accepts as arguments an element's current index and value
299     * (as mapped by preceding mappings, if any), and produces a
300     * new value.
301     * @param mapper the mapper
302     * @return operation prefix
303     */
304     public abstract ParallelArrayWithLongMapping<T> withIndexedMapping
305     (IntAndDoubleToLong mapper);
306    
307     /**
308     * Returns an Iterable view to sequentially step through mapped
309     * elements also obeying bound and filter constraints, without
310 jsr166 1.4 * performing computations to evaluate them in parallel.
311 dl 1.1 * @return the Iterable view
312     */
313     public Iterable<Double> sequentially() {
314     return new SequentiallyAsDouble();
315     }
316     }