ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/ParallelDoubleArrayWithFilter.java
Revision: 1.8
Committed: Thu Feb 26 06:53:34 2015 UTC (9 years, 2 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +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.7
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 ParallelDoubleArray that causes operations to apply
16     * only to elements for which a selector returns true.
17     * Instances of this class may be constructed only via prefix
18     * methods of ParallelDoubleArray or its other prefix classes.
19     */
20     public abstract class ParallelDoubleArrayWithFilter extends ParallelDoubleArrayWithDoubleMapping {
21     ParallelDoubleArrayWithFilter
22     (ForkJoinPool ex, int origin, int fence, double[] array) {
23     super(ex, origin, fence, array);
24     }
25    
26     /**
27     * Replaces elements with the results of applying the given
28     * op to their current values.
29     * @param op the op
30     * @return this (to simplify use in expressions)
31     */
32 jsr166 1.3 public ParallelDoubleArrayWithFilter replaceWithMapping(DoubleOp op) {
33 dl 1.1 ex.invoke(new PAS.FJDTransform(this, origin,
34     fence, null, op));
35     return this;
36     }
37    
38     /**
39     * Replaces elements with the results of applying the given
40 jsr166 1.5 * op to their indices.
41 dl 1.1 * @param op the op
42     * @return this (to simplify use in expressions)
43     */
44     public ParallelDoubleArrayWithFilter replaceWithMappedIndex(IntToDouble op) {
45     ex.invoke(new PAS.FJDIndexMap(this, origin, fence,
46     null, op));
47     return this;
48     }
49    
50     /**
51     * Replaces elements with the results of applying the given
52 jsr166 1.5 * mapping to each index and current element value.
53 dl 1.1 * @param op the op
54     * @return this (to simplify use in expressions)
55     */
56     public ParallelDoubleArrayWithFilter replaceWithMappedIndex(IntAndDoubleToDouble op) {
57     ex.invoke(new PAS.FJDBinaryIndexMap
58     (this, origin, fence, null, op));
59     return this;
60     }
61    
62     /**
63 jsr166 1.5 * Replaces elements with results of applying the given generator.
64 dl 1.1 * @param generator the generator
65     * @return this (to simplify use in expressions)
66     */
67     public ParallelDoubleArrayWithFilter replaceWithGeneratedValue(DoubleGenerator generator) {
68     ex.invoke(new PAS.FJDGenerate
69     (this, origin, fence, null, generator));
70     return this;
71     }
72    
73     /**
74     * Replaces elements with the given value.
75     * @param value the value
76     * @return this (to simplify use in expressions)
77     */
78     public ParallelDoubleArrayWithFilter replaceWithValue(double value) {
79     ex.invoke(new PAS.FJDFill(this, origin, fence,
80     null, value));
81     return this;
82     }
83    
84     /**
85     * Replaces elements with results of applying
86 jsr166 1.6 * {@code op(thisElement, otherElement)}.
87 dl 1.1 * @param other the other array
88     * @param combiner the combiner
89     * @return this (to simplify use in expressions)
90     */
91     public ParallelDoubleArrayWithFilter replaceWithMapping(BinaryDoubleOp combiner,
92     ParallelDoubleArrayWithDoubleMapping other) {
93     ex.invoke(new PAS.FJDPACombineInPlace
94     (this, origin, fence, null,
95     other, other.origin - origin, combiner));
96     return this;
97     }
98    
99     /**
100     * Replaces elements with results of applying
101 jsr166 1.6 * {@code op(thisElement, otherElement)}.
102 dl 1.1 * @param other the other array
103     * @param combiner the combiner
104     * @return this (to simplify use in expressions)
105     */
106     public ParallelDoubleArrayWithFilter replaceWithMapping
107     (BinaryDoubleOp combiner,
108     double[] other) {
109     ex.invoke(new PAS.FJDCombineInPlace
110     (this, origin, fence, null, other,
111     -origin, combiner));
112     return this;
113     }
114    
115     /**
116     * Returns a new ParallelDoubleArray containing only unique
117     * elements (that is, without any duplicates).
118     * @return the new ParallelDoubleArray
119     */
120     public ParallelDoubleArray allUniqueElements() {
121     PAS.UniquifierTable tab = new PAS.UniquifierTable
122     (fence - origin, this, false);
123     PAS.FJDUniquifier f = new PAS.FJDUniquifier
124     (this, origin, fence, null, tab);
125     ex.invoke(f);
126     double[] res = tab.uniqueDoubles(f.count);
127     return new ParallelDoubleArray(ex, res);
128     }
129    
130    
131     /**
132     * Returns an operation prefix that causes a method to operate
133     * only on elements for which the current selector (if
134 jsr166 1.5 * present) and the given selector returns true.
135 dl 1.1 * @param selector the selector
136     * @return operation prefix
137     */
138     public abstract ParallelDoubleArrayWithFilter withFilter
139     (DoublePredicate selector);
140    
141     /**
142     * Returns an operation prefix that causes a method to operate
143     * only on elements for which the current selector (if
144 jsr166 1.5 * present) and the given binary selector returns true.
145 dl 1.1 * @param selector the selector
146     * @return operation prefix
147     */
148     public ParallelDoubleArrayWithFilter withFilter
149     (BinaryDoublePredicate selector,
150     ParallelDoubleArrayWithDoubleMapping other) {
151     return withIndexedFilter(AbstractParallelAnyArray.indexedSelector(selector, other, origin));
152     }
153    
154     /**
155     * Returns an operation prefix that causes a method to operate
156     * only on elements for which the current selector (if
157 jsr166 1.5 * present) and the given indexed selector returns true.
158 dl 1.1 * @param selector the selector
159     * @return operation prefix
160     */
161     public abstract ParallelDoubleArrayWithFilter withIndexedFilter
162     (IntAndDoublePredicate selector);
163    
164     /**
165     * Returns true if all elements at the same relative positions
166     * of this and other array are equal.
167     * @param other the other array
168     * @return true if equal
169     */
170     public boolean hasAllEqualElements
171     (ParallelDoubleArrayWithDoubleMapping other) {
172     return withFilter(CommonOps.doubleInequalityPredicate(),
173     other).anyIndex() < 0;
174     }
175    
176     final void leafTransfer(int lo, int hi, double[] dest, int offset) {
177     final double[] a = this.array;
178     for (int i = lo; i < hi; ++i)
179     dest[offset++] = (a[i]);
180     }
181    
182     final void leafTransferByIndex(int[] indices, int loIdx, int hiIdx,
183     double[] dest, int offset) {
184     final double[] a = this.array;
185     for (int i = loIdx; i < hiIdx; ++i)
186     dest[offset++] = (a[indices[i]]);
187     }
188    
189     final double dget(int i) { return this.array[i]; }
190    
191     }