ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelDoubleArrayWithDoubleMapping.java
Revision: 1.6
Committed: Thu Feb 26 06:53:34 2015 UTC (9 years, 2 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +0 -1 lines
Log Message:
delete unused imports

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