ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelDoubleArrayWithLongMapping.java
Revision: 1.5
Committed: Sun Jan 18 20:17:32 2015 UTC (9 years, 3 months ago) by jsr166
Branch: MAIN
Changes since 1.4: +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.5
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 ParallelDoubleArray 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 ParallelDoubleArray or its other prefix classes.
20     */
21     public abstract class ParallelDoubleArrayWithLongMapping extends AbstractParallelAnyArray.DPap {
22     ParallelDoubleArrayWithLongMapping
23     (ForkJoinPool ex, int origin, int fence, double[] 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(LongProcedure procedure) {
32     ex.invoke(new PAS.FJLApply(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 long reduce(LongReducer reducer, long base) {
42     PAS.FJLReduce f = new PAS.FJLReduce
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 Long.MAX_VALUE if empty.
50 dl 1.1 * @return minimum element, or Long.MAX_VALUE if empty
51     */
52     public long min() {
53     return reduce(CommonOps.naturalLongMinReducer(), Long.MAX_VALUE);
54     }
55    
56     /**
57 jsr166 1.4 * Returns the minimum element, or Long.MAX_VALUE if empty.
58 dl 1.1 * @param comparator the comparator
59     * @return minimum element, or Long.MAX_VALUE if empty
60     */
61     public long min(LongComparator comparator) {
62     return reduce(CommonOps.longMinReducer(comparator), Long.MAX_VALUE);
63     }
64    
65     /**
66 jsr166 1.4 * Returns the maximum element, or Long.MIN_VALUE if empty.
67 dl 1.1 * @return maximum element, or Long.MIN_VALUE if empty
68     */
69     public long max() {
70     return reduce(CommonOps.naturalLongMaxReducer(), Long.MIN_VALUE);
71     }
72    
73     /**
74 jsr166 1.4 * Returns the maximum element, or Long.MIN_VALUE if empty.
75 dl 1.1 * @param comparator the comparator
76     * @return maximum element, or Long.MIN_VALUE if empty
77     */
78     public long max(LongComparator comparator) {
79     return reduce(CommonOps.longMaxReducer(comparator), Long.MIN_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 long sum() {
87     return reduce(CommonOps.longAdder(), 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 ParallelLongArray.SummaryStatistics summary
97     (LongComparator comparator) {
98     PAS.FJLStats f = new PAS.FJLStats
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 ParallelLongArray.SummaryStatistics summary() {
109     return summary(CommonOps.naturalLongComparator());
110     }
111    
112     /**
113 jsr166 1.4 * Returns a new ParallelLongArray holding mappings.
114 dl 1.1 * @return a new ParallelLongArray holding mappings
115     */
116     public ParallelLongArray all() {
117     return new ParallelLongArray(ex, allLongs());
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 ParallelDoubleArrayWithDoubleMapping withMapping
127     (LongToDouble op);
128    
129     /**
130     * Returns an operation prefix that causes a method to operate
131     * on mapped elements of the array using the given op.
132     * @param op the op
133     * @return operation prefix
134     */
135     public abstract ParallelDoubleArrayWithLongMapping withMapping
136     (LongOp op);
137    
138     /**
139     * Returns an operation prefix that causes a method to operate
140     * on mapped elements of the array using the given op.
141     * @param op the op
142     * @return operation prefix
143     */
144     public abstract <U> ParallelDoubleArrayWithMapping<U> withMapping
145     (LongToObject<? extends U> op);
146    
147     /**
148     * Returns an operation prefix that causes a method to operate
149     * on binary mappings of this array and the other array.
150     * @param combiner the combiner
151     * @param other the other array
152     * @return operation prefix
153     * @throws IllegalArgumentException if other array is a
154 jsr166 1.4 * filtered view (all filters must precede all mappings)
155 dl 1.1 */
156     public <V,W,X> ParallelDoubleArrayWithMapping<W> withMapping
157     (LongAndObjectToObject<? super V, ? extends W> combiner,
158     ParallelArrayWithMapping<X,V> other) {
159     if (other.hasFilter()) throw new IllegalArgumentException();
160     return withIndexedMapping(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     (LongAndDoubleToObject<? extends V> combiner,
174     ParallelDoubleArrayWithDoubleMapping other) {
175     if (other.hasFilter()) throw new IllegalArgumentException();
176     return withIndexedMapping(AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
177     }
178    
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     * @throws IllegalArgumentException if other array is a
186 jsr166 1.4 * filtered view (all filters must precede all mappings)
187 dl 1.1 */
188     public <V> ParallelDoubleArrayWithMapping<V> withMapping
189     (LongAndLongToObject<? extends V> combiner,
190     ParallelLongArrayWithLongMapping other) {
191     if (other.hasFilter()) throw new IllegalArgumentException();
192     return withIndexedMapping(AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
193     }
194    
195     /**
196     * Returns an operation prefix that causes a method to operate
197     * on binary mappings of this array and the other array.
198     * @param combiner the combiner
199     * @param other the other array
200     * @return operation prefix
201     * @throws IllegalArgumentException if other array is a
202 jsr166 1.4 * filtered view (all filters must precede all mappings)
203 dl 1.1 */
204     public <V,W> ParallelDoubleArrayWithDoubleMapping withMapping
205     (LongAndObjectToDouble<? super V> combiner,
206     ParallelArrayWithMapping<W,V> other) {
207     if (other.hasFilter()) throw new IllegalArgumentException();
208     return withIndexedMapping(AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
209     }
210    
211     /**
212     * Returns an operation prefix that causes a method to operate
213     * on binary mappings of this array and the other array.
214     * @param combiner the combiner
215     * @param other the other array
216     * @return operation prefix
217     * @throws IllegalArgumentException if other array is a
218 jsr166 1.4 * filtered view (all filters must precede all mappings)
219 dl 1.1 */
220     public ParallelDoubleArrayWithDoubleMapping withMapping
221     (LongAndDoubleToDouble combiner,
222     ParallelDoubleArrayWithDoubleMapping other) {
223     if (other.hasFilter()) throw new IllegalArgumentException();
224     return withIndexedMapping(AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
225     }
226    
227     /**
228     * Returns an operation prefix that causes a method to operate
229     * on binary mappings of this array and the other array.
230     * @param combiner the combiner
231     * @param other the other array
232     * @return operation prefix
233     * @throws IllegalArgumentException if other array is a
234 jsr166 1.4 * filtered view (all filters must precede all mappings)
235 dl 1.1 */
236     public ParallelDoubleArrayWithDoubleMapping withMapping
237     (LongAndLongToDouble combiner,
238     ParallelLongArrayWithLongMapping other) {
239     if (other.hasFilter()) throw new IllegalArgumentException();
240     return withIndexedMapping(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     * @throws IllegalArgumentException if other array is a
250 jsr166 1.4 * filtered view (all filters must precede all mappings)
251 dl 1.1 */
252     public <V,W> ParallelDoubleArrayWithLongMapping withMapping
253     (LongAndObjectToLong<? super V> combiner,
254     ParallelArrayWithMapping<W,V> other) {
255     if (other.hasFilter()) throw new IllegalArgumentException();
256     return withIndexedMapping(AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
257     }
258    
259     /**
260     * Returns an operation prefix that causes a method to operate
261     * on binary mappings of this array and the other array.
262     * @param combiner the combiner
263     * @param other the other array
264     * @return operation prefix
265     * @throws IllegalArgumentException if other array is a
266 jsr166 1.4 * filtered view (all filters must precede all mappings)
267 dl 1.1 */
268     public ParallelDoubleArrayWithLongMapping withMapping
269     (LongAndDoubleToLong combiner,
270     ParallelDoubleArrayWithDoubleMapping other) {
271     if (other.hasFilter()) throw new IllegalArgumentException();
272     return withIndexedMapping(AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
273     }
274    
275     /**
276     * Returns an operation prefix that causes a method to operate
277     * on binary mappings of this array and the other array.
278     * @param combiner the combiner
279     * @param other the other array
280     * @return operation prefix
281     * @throws IllegalArgumentException if other array is a
282 jsr166 1.4 * filtered view (all filters must precede all mappings)
283 dl 1.1 */
284     public ParallelDoubleArrayWithLongMapping withMapping
285     (BinaryLongOp combiner,
286     ParallelLongArrayWithLongMapping other) {
287     if (other.hasFilter()) throw new IllegalArgumentException();
288     return withIndexedMapping(AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
289     }
290    
291     /**
292     * Returns an operation prefix that causes a method to operate
293     * on mappings of this array using the given mapper that
294     * accepts as arguments an element's current index and value
295     * (as mapped by preceding mappings, if any), and produces a
296     * new value.
297     * @param mapper the mapper
298     * @return operation prefix
299     */
300     public abstract <V> ParallelDoubleArrayWithMapping<V> withIndexedMapping
301     (IntAndLongToObject<? extends V> mapper);
302    
303     /**
304     * Returns an operation prefix that causes a method to operate
305     * on mappings of this array using the given mapper that
306     * accepts as arguments an element's current index and value
307     * (as mapped by preceding mappings, if any), and produces a
308     * new value.
309     * @param mapper the mapper
310     * @return operation prefix
311     */
312     public abstract ParallelDoubleArrayWithDoubleMapping withIndexedMapping
313     (IntAndLongToDouble mapper);
314    
315     /**
316     * Returns an operation prefix that causes a method to operate
317     * on mappings of this array using the given mapper that
318     * accepts as arguments an element's current index and value
319     * (as mapped by preceding mappings, if any), and produces a
320     * new value.
321     * @param mapper the mapper
322     * @return operation prefix
323     */
324     public abstract ParallelDoubleArrayWithLongMapping withIndexedMapping
325     (IntAndLongToLong mapper);
326    
327     /**
328     * Returns an Iterable view to sequentially step through mapped
329     * elements also obeying bound and filter constraints, without
330 jsr166 1.4 * performing computations to evaluate them in parallel.
331 dl 1.1 * @return the Iterable view
332     */
333     public Iterable<Long> sequentially() {
334     return new SequentiallyAsLong();
335     }
336     }