ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelLongArrayWithBounds.java
Revision: 1.8
Committed: Sun Jan 18 20:17:32 2015 UTC (9 years, 3 months ago) by jsr166
Branch: MAIN
Changes since 1.7: +1 -0 lines
Log Message:
exactly one blank line before and after package statements

File Contents

# Content
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/publicdomain/zero/1.0/
5 */
6
7 package extra166y;
8
9 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 * only to elements within a given range.
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 ParallelLongArrayWithBounds extends ParallelLongArrayWithFilter {
22 ParallelLongArrayWithBounds
23 (ForkJoinPool ex, int origin, int fence, long[] array) {
24 super(ex, origin, fence, array);
25 }
26
27 /**
28 * Returns an operation prefix that causes a method to operate
29 * only on the elements of the array between firstIndex
30 * (inclusive) and upperBound (exclusive). The bound
31 * arguments are relative to the current bounds. For example
32 * {@code pa.withBounds(2, 8).withBounds(3, 5)} indexes the
33 * 5th (= 2+3) and 6th elements of pa. However, indices
34 * returned by methods such as {@code indexOf} are
35 * with respect to the underlying ParallelLongArray.
36 * @param firstIndex the lower bound (inclusive)
37 * @param upperBound the upper bound (exclusive)
38 * @return operation prefix
39 */
40 public abstract ParallelLongArrayWithBounds withBounds
41 (int firstIndex, int upperBound);
42
43 /**
44 * Returns the index of some element equal to given target, or
45 * -1 if not present.
46 * @param target the element to search for
47 * @return the index or -1 if not present
48 */
49 public abstract int indexOf(long target);
50
51 /**
52 * Assuming this array is sorted, returns the index of an
53 * element equal to given target, or -1 if not present. If the
54 * array is not sorted, the results are undefined.
55 * @param target the element to search for
56 * @return the index or -1 if not present
57 */
58 public abstract int binarySearch(long target);
59
60 /**
61 * Assuming this array is sorted with respect to the given
62 * comparator, returns the index of an element equal to given
63 * target, or -1 if not present. If the array is not sorted,
64 * the results are undefined.
65 * @param target the element to search for
66 * @param comparator the comparator
67 * @return the index or -1 if not present
68 */
69 public abstract int binarySearch(long target, LongComparator comparator);
70
71 /**
72 * Replaces each element with the running cumulation of applying
73 * the given reducer.
74 * @param reducer the reducer
75 * @param base the result for an empty array
76 * @return this (to simplify use in expressions)
77 */
78 public abstract ParallelLongArrayWithBounds cumulate(LongReducer reducer, long base);
79
80 /**
81 * Replaces each element with the running sum.
82 * @return this (to simplify use in expressions)
83 */
84 public abstract ParallelLongArrayWithBounds cumulateSum();
85
86 /**
87 * Replaces each element with the cumulation of applying the given
88 * reducer to all previous values, and returns the total
89 * reduction.
90 * @param reducer the reducer
91 * @param base the result for an empty array
92 * @return the total reduction
93 */
94 public abstract long precumulate(LongReducer reducer, long base);
95
96 /**
97 * Replaces each element with its prefix sum.
98 * @return the total sum
99 */
100 public abstract long precumulateSum();
101
102 /**
103 * Sorts the elements.
104 * Unlike Arrays.sort, this sort does
105 * not guarantee that elements with equal keys maintain their
106 * relative position in the array.
107 * @param cmp the comparator to use
108 * @return this (to simplify use in expressions)
109 */
110 public abstract ParallelLongArrayWithBounds sort(LongComparator cmp);
111
112 /**
113 * Sorts the elements, assuming all elements are
114 * Comparable. Unlike Arrays.sort, this sort does not
115 * guarantee that elements with equal keys maintain their relative
116 * position in the array.
117 * @return this (to simplify use in expressions)
118 * @throws ClassCastException if any element is not Comparable
119 */
120 public abstract ParallelLongArrayWithBounds sort();
121
122 }