ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelLongArrayWithLongMapping.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 ParallelLongArray 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 ParallelLongArray or its other prefix classes.
20     */
21     public abstract class ParallelLongArrayWithLongMapping extends AbstractParallelAnyArray.LPap {
22     ParallelLongArrayWithLongMapping
23     (ForkJoinPool ex, int origin, int fence, long[] array) {
24     super(ex, origin, fence, array);
25     }
26    
27     /**
28 jsr166 1.4 * Applies the given procedure to elements.
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 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(), 0L);
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 elements.
114 dl 1.1 * @return a new ParallelLongArray holding elements
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 ParallelLongArrayWithLongMapping withMapping(LongOp 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 ParallelLongArrayWithDoubleMapping withMapping
135     (LongToDouble 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> ParallelLongArrayWithMapping<U> withMapping
144     (LongToObject<? 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> ParallelLongArrayWithMapping<W> withMapping
156     (LongAndObjectToObject<? 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> ParallelLongArrayWithMapping<V> withMapping
173     (LongAndDoubleToObject<? 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     /**
182     * Returns an operation prefix that causes a method to operate
183     * on binary mappings of this array and the other array.
184     * @param combiner the combiner
185     * @param other the other array
186     * @return operation prefix
187     * @throws IllegalArgumentException if other array is a
188 jsr166 1.4 * filtered view (all filters must precede all mappings)
189 dl 1.1 */
190     public <V> ParallelLongArrayWithMapping<V> withMapping
191     (LongAndLongToObject<? extends V> combiner,
192     ParallelLongArrayWithLongMapping other) {
193     if (other.hasFilter()) throw new IllegalArgumentException();
194     return withIndexedMapping
195     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
196     }
197    
198     /**
199     * Returns an operation prefix that causes a method to operate
200     * on binary mappings of this array and the other array.
201     * @param combiner the combiner
202     * @param other the other array
203     * @return operation prefix
204     * @throws IllegalArgumentException if other array is a
205 jsr166 1.4 * filtered view (all filters must precede all mappings)
206 dl 1.1 */
207     public <V,W> ParallelLongArrayWithDoubleMapping withMapping
208     (LongAndObjectToDouble<? super V> combiner,
209     ParallelArrayWithMapping<W,V> other) {
210     if (other.hasFilter()) throw new IllegalArgumentException();
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     * @throws IllegalArgumentException if other array is a
222 jsr166 1.4 * filtered view (all filters must precede all mappings)
223 dl 1.1 */
224     public ParallelLongArrayWithDoubleMapping withMapping
225     (LongAndDoubleToDouble combiner,
226     ParallelDoubleArrayWithDoubleMapping other) {
227     if (other.hasFilter()) throw new IllegalArgumentException();
228     return withIndexedMapping
229     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
230     }
231    
232     /**
233     * Returns an operation prefix that causes a method to operate
234     * on binary mappings of this array and the other array.
235     * @param combiner the combiner
236     * @param other the other array
237     * @return operation prefix
238     * @throws IllegalArgumentException if other array is a
239 jsr166 1.4 * filtered view (all filters must precede all mappings)
240 dl 1.1 */
241     public ParallelLongArrayWithDoubleMapping withMapping
242     (LongAndLongToDouble combiner,
243     ParallelLongArrayWithLongMapping other) {
244     if (other.hasFilter()) throw new IllegalArgumentException();
245     return withIndexedMapping
246     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
247     }
248    
249     /**
250     * Returns an operation prefix that causes a method to operate
251     * on binary mappings of this array and the other array.
252     * @param combiner the combiner
253     * @param other the other array
254     * @return operation prefix
255     * @throws IllegalArgumentException if other array is a
256 jsr166 1.4 * filtered view (all filters must precede all mappings)
257 dl 1.1 */
258     public <V,W> ParallelLongArrayWithLongMapping withMapping
259     (LongAndObjectToLong<? super V> combiner,
260     ParallelArrayWithMapping<W,V> other) {
261     if (other.hasFilter()) throw new IllegalArgumentException();
262     return withIndexedMapping
263     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
264     }
265    
266     /**
267     * Returns an operation prefix that causes a method to operate
268     * on binary mappings of this array and the other array.
269     * @param combiner the combiner
270     * @param other the other array
271     * @return operation prefix
272     * @throws IllegalArgumentException if other array is a
273 jsr166 1.4 * filtered view (all filters must precede all mappings)
274 dl 1.1 */
275     public ParallelLongArrayWithLongMapping withMapping
276     (LongAndDoubleToLong combiner,
277     ParallelDoubleArrayWithDoubleMapping other) {
278     if (other.hasFilter()) throw new IllegalArgumentException();
279     return withIndexedMapping
280     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
281     }
282    
283     /**
284     * Returns an operation prefix that causes a method to operate
285     * on binary mappings of this array and the other array.
286     * @param combiner the combiner
287     * @param other the other array
288     * @return operation prefix
289     * @throws IllegalArgumentException if other array is a
290 jsr166 1.4 * filtered view (all filters must precede all mappings)
291 dl 1.1 */
292     public ParallelLongArrayWithLongMapping withMapping
293     (BinaryLongOp combiner,
294     ParallelLongArrayWithLongMapping other) {
295     if (other.hasFilter()) throw new IllegalArgumentException();
296     return withIndexedMapping
297     (AbstractParallelAnyArray.indexedMapper(combiner, other, origin));
298     }
299    
300     /**
301     * Returns an operation prefix that causes a method to operate
302     * on mappings of this array using the given mapper that
303     * accepts as arguments an element's current index and value
304     * (as mapped by preceding mappings, if any), and produces a
305     * new value.
306     * @param mapper the mapper
307     * @return operation prefix
308     */
309     public abstract <V> ParallelLongArrayWithMapping<V> withIndexedMapping
310     (IntAndLongToObject<? extends V> mapper);
311    
312     /**
313     * Returns an operation prefix that causes a method to operate
314     * on mappings of this array using the given mapper that
315     * accepts as arguments an element's current index and value
316     * (as mapped by preceding mappings, if any), and produces a
317     * new value.
318     * @param mapper the mapper
319     * @return operation prefix
320     */
321     public abstract ParallelLongArrayWithDoubleMapping withIndexedMapping
322     (IntAndLongToDouble mapper);
323    
324     /**
325     * Returns an operation prefix that causes a method to operate
326     * on mappings of this array using the given mapper that
327     * accepts as arguments an element's current index and value
328     * (as mapped by preceding mappings, if any), and produces a
329     * new value.
330     * @param mapper the mapper
331     * @return operation prefix
332     */
333     public abstract ParallelLongArrayWithLongMapping withIndexedMapping
334     (IntAndLongToLong mapper);
335    
336     /**
337     * Returns an Iterable view to sequentially step through mapped
338     * elements also obeying bound and filter constraints, without
339 jsr166 1.4 * performing computations to evaluate them in parallel.
340 dl 1.1 * @return the Iterable view
341     */
342     public Iterable<Long> sequentially() {
343     return new SequentiallyAsLong();
344     }
345    
346     }