ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelLongArrayWithLongMapping.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 ParallelLongArray 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 ParallelLongArray or its other prefix classes.
19     */
20     public abstract class ParallelLongArrayWithLongMapping extends AbstractParallelAnyArray.LPap {
21     ParallelLongArrayWithLongMapping
22     (ForkJoinPool ex, int origin, int fence, long[] 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(LongProcedure procedure) {
31     ex.invoke(new PAS.FJLApply(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 long reduce(LongReducer reducer, long base) {
41     PAS.FJLReduce f = new PAS.FJLReduce
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 Long.MAX_VALUE if empty.
49 dl 1.1 * @return minimum element, or Long.MAX_VALUE if empty
50     */
51     public long min() {
52     return reduce(CommonOps.naturalLongMinReducer(), Long.MAX_VALUE);
53     }
54    
55     /**
56 jsr166 1.4 * Returns the minimum element, or Long.MAX_VALUE if empty.
57 dl 1.1 * @param comparator the comparator
58     * @return minimum element, or Long.MAX_VALUE if empty
59     */
60     public long min(LongComparator comparator) {
61     return reduce(CommonOps.longMinReducer(comparator), Long.MAX_VALUE);
62     }
63    
64     /**
65 jsr166 1.4 * Returns the maximum element, or Long.MIN_VALUE if empty.
66 dl 1.1 * @return maximum element, or Long.MIN_VALUE if empty
67     */
68     public long max() {
69     return reduce(CommonOps.naturalLongMaxReducer(), Long.MIN_VALUE);
70     }
71    
72     /**
73 jsr166 1.4 * Returns the maximum element, or Long.MIN_VALUE if empty.
74 dl 1.1 * @param comparator the comparator
75     * @return maximum element, or Long.MIN_VALUE if empty
76     */
77     public long max(LongComparator comparator) {
78     return reduce(CommonOps.longMaxReducer(comparator), Long.MIN_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 long sum() {
86     return reduce(CommonOps.longAdder(), 0L);
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 ParallelLongArray.SummaryStatistics summary
96     (LongComparator comparator) {
97     PAS.FJLStats f = new PAS.FJLStats
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 ParallelLongArray.SummaryStatistics summary() {
108     return summary(CommonOps.naturalLongComparator());
109     }
110    
111     /**
112 jsr166 1.4 * Returns a new ParallelLongArray holding elements.
113 dl 1.1 * @return a new ParallelLongArray holding elements
114     */
115     public ParallelLongArray all() {
116     return new ParallelLongArray(ex, allLongs());
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 ParallelLongArrayWithLongMapping withMapping(LongOp 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     public abstract ParallelLongArrayWithDoubleMapping withMapping
134     (LongToDouble 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     public abstract <U> ParallelLongArrayWithMapping<U> withMapping
143     (LongToObject<? 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     * @throws IllegalArgumentException if other array is a
152 jsr166 1.4 * filtered view (all filters must precede all mappings)
153 dl 1.1 */
154     public <V,W,X> ParallelLongArrayWithMapping<W> withMapping
155     (LongAndObjectToObject<? super V, ? extends W> combiner,
156     ParallelArrayWithMapping<X,V> other) {
157     if (other.hasFilter()) throw new IllegalArgumentException();
158     return withIndexedMapping
159     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
160     }
161    
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     * @throws IllegalArgumentException if other array is a
169 jsr166 1.4 * filtered view (all filters must precede all mappings)
170 dl 1.1 */
171     public <V> ParallelLongArrayWithMapping<V> withMapping
172     (LongAndDoubleToObject<? extends V> combiner,
173     ParallelDoubleArrayWithDoubleMapping other) {
174     if (other.hasFilter()) throw new IllegalArgumentException();
175     return withIndexedMapping
176     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
177     }
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> ParallelLongArrayWithMapping<V> withMapping
190     (LongAndLongToObject<? 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> ParallelLongArrayWithDoubleMapping withMapping
207     (LongAndObjectToDouble<? 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 ParallelLongArrayWithDoubleMapping withMapping
224     (LongAndDoubleToDouble 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 ParallelLongArrayWithDoubleMapping withMapping
241     (LongAndLongToDouble 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> ParallelLongArrayWithLongMapping withMapping
258     (LongAndObjectToLong<? 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 ParallelLongArrayWithLongMapping withMapping
275     (LongAndDoubleToLong 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 ParallelLongArrayWithLongMapping withMapping
292     (BinaryLongOp 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> ParallelLongArrayWithMapping<V> withIndexedMapping
309     (IntAndLongToObject<? 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 ParallelLongArrayWithDoubleMapping withIndexedMapping
321     (IntAndLongToDouble 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 ParallelLongArrayWithLongMapping withIndexedMapping
333     (IntAndLongToLong 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<Long> sequentially() {
342     return new SequentiallyAsLong();
343     }
344    
345     }