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