ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelDoubleArrayWithBounds.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

# 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.8
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     * only to elements within a given range.
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 ParallelDoubleArrayWithBounds extends ParallelDoubleArrayWithFilter {
22     ParallelDoubleArrayWithBounds
23     (ForkJoinPool ex, int origin, int fence, double[] 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 jsr166 1.6 * {@code pa.withBounds(2, 8).withBounds(3, 5)} indexes the
33 dl 1.1 * 5th (= 2+3) and 6th elements of pa. However, indices
34 jsr166 1.6 * returned by methods such as {@code indexOf} are
35 dl 1.1 * with respect to the underlying ParallelDoubleArray.
36     * @param firstIndex the lower bound (inclusive)
37     * @param upperBound the upper bound (exclusive)
38     * @return operation prefix
39     */
40     public abstract ParallelDoubleArrayWithBounds withBounds
41     (int firstIndex, int upperBound);
42    
43     /**
44     * Returns the index of some element equal to given target,
45 jsr166 1.5 * or -1 if not present.
46 dl 1.1 * @param target the element to search for
47     * @return the index or -1 if not present
48     */
49     public abstract int indexOf(double 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(double 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(double target,
70     DoubleComparator comparator);
71    
72     /**
73     * Replaces each element with the running cumulation of applying
74     * the given reducer.
75     * @param reducer the reducer
76     * @param base the result for an empty array
77     * @return this (to simplify use in expressions)
78     */
79     public abstract ParallelDoubleArrayWithBounds cumulate(DoubleReducer reducer, double base);
80    
81     /**
82 jsr166 1.5 * Replaces each element with the running sum.
83 dl 1.1 * @return this (to simplify use in expressions)
84     */
85     public abstract ParallelDoubleArrayWithBounds cumulateSum();
86    
87     /**
88     * Replaces each element with the cumulation of applying the given
89     * reducer to all previous values, and returns the total
90     * reduction.
91     * @param reducer the reducer
92     * @param base the result for an empty array
93     * @return the total reduction
94     */
95     public abstract double precumulate(DoubleReducer reducer, double base);
96    
97     /**
98 jsr166 1.5 * Replaces each element with its prefix sum.
99 dl 1.1 * @return the total sum
100     */
101     public abstract double precumulateSum();
102    
103     /**
104     * Sorts the elements.
105     * Unlike Arrays.sort, this sort does
106     * not guarantee that elements with equal keys maintain their
107     * relative position in the array.
108     * @param cmp the comparator to use
109     * @return this (to simplify use in expressions)
110     */
111     public abstract ParallelDoubleArrayWithBounds sort(DoubleComparator cmp);
112    
113     /**
114     * Sorts the elements, assuming all elements are
115     * Comparable. Unlike Arrays.sort, this sort does not
116     * guarantee that elements with equal keys maintain their relative
117     * position in the array.
118 jsr166 1.7 * @return this (to simplify use in expressions)
119 jsr166 1.4 * @throws ClassCastException if any element is not Comparable
120 dl 1.1 */
121     public abstract ParallelDoubleArrayWithBounds sort();
122     }