ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/forkjoin/ParallelLongArrayWithDoubleMapping.java
Revision: 1.3
Committed: Fri Jul 25 18:29:00 2008 UTC (15 years, 11 months ago) by jsr166
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
whitespace

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