propane 3.11.0-java → 4.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -1
- data/CHANGELOG.md +2 -0
- data/README.md +5 -5
- data/Rakefile +1 -1
- data/lib/propane/app.rb +2 -2
- data/lib/propane/version.rb +1 -1
- data/lib/propane-4.0.0.jar +0 -0
- data/library/slider/slider.rb +1 -1
- data/pom.rb +8 -8
- data/pom.xml +8 -8
- data/propane.gemspec +3 -3
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/MathToolModule.java +1 -1
- data/src/main/java/monkstone/PropaneLibrary.java +1 -1
- data/src/main/java/monkstone/fastmath/DegLutTables.java +10 -11
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
- data/src/main/java/monkstone/noise/LICENSE +121 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +92 -68
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +0 -1
- data/src/main/java/processing/awt/PImageAWT.java +2 -4
- data/src/main/java/processing/core/PApplet.java +4 -4
- data/src/main/java/processing/core/PImage.java +3025 -3047
- data/src/main/java/processing/core/PMatrix.java +5 -2
- data/src/main/java/processing/data/DoubleDict.java +72 -43
- data/src/main/java/processing/data/DoubleList.java +6 -2
- data/src/main/java/processing/data/FloatDict.java +744 -756
- data/src/main/java/processing/data/FloatList.java +68 -26
- data/src/main/java/processing/data/IntDict.java +72 -45
- data/src/main/java/processing/data/IntList.java +63 -26
- data/src/main/java/processing/data/JSONArray.java +892 -931
- data/src/main/java/processing/data/JSONObject.java +1169 -1262
- data/src/main/java/processing/data/JSONTokener.java +30 -49
- data/src/main/java/processing/data/LongDict.java +699 -712
- data/src/main/java/processing/data/LongList.java +676 -700
- data/src/main/java/processing/data/Sort.java +1 -0
- data/src/main/java/processing/data/Table.java +4040 -3661
- data/src/main/java/processing/data/TableRow.java +16 -0
- data/src/main/java/processing/data/XML.java +1041 -956
- data/src/main/java/processing/event/TouchEvent.java +1 -1
- data/src/main/java/processing/opengl/FontTexture.java +2 -2
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +15 -18
- data/src/main/java/processing/opengl/PJOGL.java +2 -2
- data/src/main/java/processing/opengl/PShapeOpenGL.java +23 -24
- data/test/vecmath_spec_test.rb +14 -3
- data/vendors/Rakefile +1 -1
- metadata +9 -8
- data/lib/propane-3.11.0.jar +0 -0
@@ -8,298 +8,291 @@ import java.util.Random;
|
|
8
8
|
|
9
9
|
import processing.core.PApplet;
|
10
10
|
|
11
|
-
|
12
11
|
// splice, slice, subset, concat, reverse
|
13
|
-
|
14
12
|
// trim, join for String versions
|
15
|
-
|
16
|
-
|
17
13
|
/**
|
18
14
|
* Helper class for a list of ints. Lists are designed to have some of the
|
19
15
|
* features of ArrayLists, but to maintain the simplicity and efficiency of
|
20
16
|
* working with arrays.
|
21
17
|
*
|
22
|
-
* Functions like sort() and shuffle() always act on the list itself. To get
|
23
|
-
*
|
18
|
+
* Functions like sort() and shuffle() always act on the list itself. To get a
|
19
|
+
* sorted copy, use list.copy().sort().
|
24
20
|
*
|
25
21
|
* @nowebref
|
26
22
|
* @see FloatList
|
27
23
|
* @see StringList
|
28
24
|
*/
|
29
25
|
public class LongList implements Iterable<Long> {
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
26
|
+
|
27
|
+
protected int count;
|
28
|
+
protected long[] data;
|
29
|
+
|
30
|
+
public LongList() {
|
31
|
+
data = new long[10];
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @param length
|
36
|
+
* @nowebref
|
37
|
+
*/
|
38
|
+
public LongList(int length) {
|
39
|
+
data = new long[length];
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* @param source
|
44
|
+
* @nowebref
|
45
|
+
*/
|
46
|
+
public LongList(int[] source) {
|
47
|
+
count = source.length;
|
48
|
+
data = new long[count];
|
49
|
+
System.arraycopy(source, 0, data, 0, count);
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Construct an IntList from an iterable pile of objects.For instance, a
|
54
|
+
* float array, an array of strings, who knows). Un-parseable or null values
|
55
|
+
* will be set to 0.
|
56
|
+
*
|
57
|
+
* @param iter
|
58
|
+
* @nowebref
|
59
|
+
*/
|
60
|
+
public LongList(Iterable<Object> iter) {
|
61
|
+
this(10);
|
62
|
+
for (Object o : iter) {
|
63
|
+
if (o == null) {
|
64
|
+
append(0); // missing value default
|
65
|
+
} else if (o instanceof Number number) {
|
66
|
+
append(number.intValue());
|
67
|
+
} else {
|
68
|
+
append(PApplet.parseInt(o.toString().trim()));
|
69
|
+
}
|
70
|
+
}
|
71
|
+
crop();
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Construct an IntList from a random pile of objects.Un-parseable or null
|
76
|
+
values will be set to zero.
|
77
|
+
* @param items
|
78
|
+
*/
|
79
|
+
public LongList(Object... items) {
|
80
|
+
final int missingValue = 0; // nuts, can't be last/final/second arg
|
81
|
+
|
82
|
+
count = items.length;
|
83
|
+
data = new long[count];
|
84
|
+
int index = 0;
|
85
|
+
for (Object o : items) {
|
86
|
+
int value = missingValue;
|
87
|
+
if (o != null) {
|
88
|
+
if (o instanceof Number number) {
|
89
|
+
value = number.intValue();
|
90
|
+
} else {
|
91
|
+
value = PApplet.parseInt(o.toString().trim(), missingValue);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
data[index++] = value;
|
95
95
|
}
|
96
|
-
}
|
97
|
-
data[index++] = value;
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
|
102
|
-
static public LongList fromRange(int stop) {
|
103
|
-
return fromRange(0, stop);
|
104
|
-
}
|
105
|
-
|
106
|
-
|
107
|
-
static public LongList fromRange(int start, int stop) {
|
108
|
-
int count = stop - start;
|
109
|
-
LongList newbie = new LongList(count);
|
110
|
-
for (int i = 0; i < count; i++) {
|
111
|
-
newbie.set(i, start+i);
|
112
|
-
}
|
113
|
-
return newbie;
|
114
|
-
}
|
115
|
-
|
116
|
-
|
117
|
-
/**
|
118
|
-
* Improve efficiency by removing allocated but unused entries from the
|
119
|
-
* internal array used to store the data. Set to private, though it could
|
120
|
-
* be useful to have this public if lists are frequently making drastic
|
121
|
-
* size changes (from very large to very small).
|
122
|
-
*/
|
123
|
-
private void crop() {
|
124
|
-
if (count != data.length) {
|
125
|
-
data = PApplet.subset(data, 0, count);
|
126
|
-
}
|
127
|
-
}
|
128
|
-
|
129
|
-
|
130
|
-
/**
|
131
|
-
* Get the length of the list.
|
132
|
-
*
|
133
|
-
* @webref intlist:method
|
134
|
-
* @brief Get the length of the list
|
135
|
-
*/
|
136
|
-
public int size() {
|
137
|
-
return count;
|
138
|
-
}
|
139
|
-
|
140
|
-
|
141
|
-
public void resize(int length) {
|
142
|
-
if (length > data.length) {
|
143
|
-
long[] temp = new long[length];
|
144
|
-
System.arraycopy(data, 0, temp, 0, count);
|
145
|
-
data = temp;
|
146
|
-
|
147
|
-
} else if (length > count) {
|
148
|
-
Arrays.fill(data, count, length, 0);
|
149
|
-
}
|
150
|
-
count = length;
|
151
|
-
}
|
152
|
-
|
153
|
-
|
154
|
-
/**
|
155
|
-
* Remove all entries from the list.
|
156
|
-
*
|
157
|
-
* @webref intlist:method
|
158
|
-
* @brief Remove all entries from the list
|
159
|
-
*/
|
160
|
-
public void clear() {
|
161
|
-
count = 0;
|
162
|
-
}
|
163
|
-
|
164
|
-
|
165
|
-
/**
|
166
|
-
* Get an entry at a particular index.
|
167
|
-
*
|
168
|
-
* @webref intlist:method
|
169
|
-
* @brief Get an entry at a particular index
|
170
|
-
*/
|
171
|
-
public long get(int index) {
|
172
|
-
if (index >= this.count) {
|
173
|
-
throw new ArrayIndexOutOfBoundsException(index);
|
174
|
-
}
|
175
|
-
return data[index];
|
176
|
-
}
|
177
|
-
|
178
|
-
|
179
|
-
/**
|
180
|
-
* Set the entry at a particular index. If the index is past the length of
|
181
|
-
* the list, it'll expand the list to accommodate, and fill the intermediate
|
182
|
-
* entries with 0s.
|
183
|
-
*
|
184
|
-
* @webref intlist:method
|
185
|
-
* @brief Set the entry at a particular index
|
186
|
-
*/
|
187
|
-
public void set(int index, int what) {
|
188
|
-
if (index >= count) {
|
189
|
-
data = PApplet.expand(data, index+1);
|
190
|
-
for (int i = count; i < index; i++) {
|
191
|
-
data[i] = 0;
|
192
|
-
}
|
193
|
-
count = index+1;
|
194
96
|
}
|
195
|
-
data[index] = what;
|
196
|
-
}
|
197
|
-
|
198
97
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
}
|
98
|
+
static public LongList fromRange(int stop) {
|
99
|
+
return fromRange(0, stop);
|
100
|
+
}
|
203
101
|
|
102
|
+
static public LongList fromRange(int start, int stop) {
|
103
|
+
int count = stop - start;
|
104
|
+
LongList newbie = new LongList(count);
|
105
|
+
for (int i = 0; i < count; i++) {
|
106
|
+
newbie.set(i, start + i);
|
107
|
+
}
|
108
|
+
return newbie;
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Improve efficiency by removing allocated but unused entries from the
|
113
|
+
* internal array used to store the data. Set to private, though it could be
|
114
|
+
* useful to have this public if lists are frequently making drastic size
|
115
|
+
* changes (from very large to very small).
|
116
|
+
*/
|
117
|
+
private void crop() {
|
118
|
+
if (count != data.length) {
|
119
|
+
data = PApplet.subset(data, 0, count);
|
120
|
+
}
|
121
|
+
}
|
204
122
|
|
205
|
-
|
206
|
-
|
207
|
-
|
123
|
+
/**
|
124
|
+
* Get the length of the list.
|
125
|
+
*
|
126
|
+
* @return
|
127
|
+
* @webref intlist:method
|
128
|
+
* @brief Get the length of the list
|
129
|
+
*/
|
130
|
+
public int size() {
|
131
|
+
return count;
|
208
132
|
}
|
209
|
-
long value = get(count-1);
|
210
|
-
count--;
|
211
|
-
return value;
|
212
|
-
}
|
213
133
|
|
134
|
+
public void resize(int length) {
|
135
|
+
if (length > data.length) {
|
136
|
+
long[] temp = new long[length];
|
137
|
+
System.arraycopy(data, 0, temp, 0, count);
|
138
|
+
data = temp;
|
139
|
+
|
140
|
+
} else if (length > count) {
|
141
|
+
Arrays.fill(data, count, length, 0);
|
142
|
+
}
|
143
|
+
count = length;
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Remove all entries from the list.
|
148
|
+
*
|
149
|
+
* @webref intlist:method
|
150
|
+
* @brief Remove all entries from the list
|
151
|
+
*/
|
152
|
+
public void clear() {
|
153
|
+
count = 0;
|
154
|
+
}
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Get an entry at a particular index.
|
158
|
+
*
|
159
|
+
* @param index
|
160
|
+
* @return
|
161
|
+
* @webref intlist:method
|
162
|
+
* @brief Get an entry at a particular index
|
163
|
+
*/
|
164
|
+
public long get(int index) {
|
165
|
+
if (index >= this.count) {
|
166
|
+
throw new ArrayIndexOutOfBoundsException(index);
|
167
|
+
}
|
168
|
+
return data[index];
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Set the entry at a particular index.If the index is past the length of
|
173
|
+
the list, it'll expand the list to accommodate, and fill the intermediate
|
174
|
+
entries with 0s.
|
175
|
+
*
|
176
|
+
* @param index
|
177
|
+
* @param what
|
178
|
+
* @webref intlist:method
|
179
|
+
* @brief Set the entry at a particular index
|
180
|
+
*/
|
181
|
+
public void set(int index, int what) {
|
182
|
+
if (index >= count) {
|
183
|
+
data = PApplet.expand(data, index + 1);
|
184
|
+
for (int i = count; i < index; i++) {
|
185
|
+
data[i] = 0;
|
186
|
+
}
|
187
|
+
count = index + 1;
|
188
|
+
}
|
189
|
+
data[index] = what;
|
190
|
+
}
|
214
191
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
public long remove(int index) {
|
222
|
-
if (index < 0 || index >= count) {
|
223
|
-
throw new ArrayIndexOutOfBoundsException(index);
|
192
|
+
/**
|
193
|
+
* Just an alias for append(), but matches pop()
|
194
|
+
* @param value
|
195
|
+
*/
|
196
|
+
public void push(int value) {
|
197
|
+
append(value);
|
224
198
|
}
|
225
|
-
|
199
|
+
|
200
|
+
public long pop() {
|
201
|
+
if (count == 0) {
|
202
|
+
throw new RuntimeException("Can't call pop() on an empty list");
|
203
|
+
}
|
204
|
+
long value = get(count - 1);
|
205
|
+
count--;
|
206
|
+
return value;
|
207
|
+
}
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Remove an element from the specified index
|
211
|
+
*
|
212
|
+
* @param index
|
213
|
+
* @return
|
214
|
+
* @webref intlist:method
|
215
|
+
* @brief Remove an element from the specified index
|
216
|
+
*/
|
217
|
+
public long remove(int index) {
|
218
|
+
if (index < 0 || index >= count) {
|
219
|
+
throw new ArrayIndexOutOfBoundsException(index);
|
220
|
+
}
|
221
|
+
long entry = data[index];
|
226
222
|
// int[] outgoing = new int[count - 1];
|
227
223
|
// System.arraycopy(data, 0, outgoing, 0, index);
|
228
224
|
// count--;
|
229
225
|
// System.arraycopy(data, index + 1, outgoing, 0, count - index);
|
230
226
|
// data = outgoing;
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
}
|
239
|
-
|
240
|
-
|
241
|
-
// Remove the first instance of a particular value,
|
242
|
-
// and return the index at which it was found.
|
243
|
-
public int removeValue(int value) {
|
244
|
-
int index = index(value);
|
245
|
-
if (index != -1) {
|
246
|
-
remove(index);
|
247
|
-
return index;
|
248
|
-
}
|
249
|
-
return -1;
|
250
|
-
}
|
251
|
-
|
252
|
-
|
253
|
-
// Remove all instances of a particular value,
|
254
|
-
// and return the number of values found and removed
|
255
|
-
public int removeValues(int value) {
|
256
|
-
int ii = 0;
|
257
|
-
for (int i = 0; i < count; i++) {
|
258
|
-
if (data[i] != value) {
|
259
|
-
data[ii++] = data[i];
|
260
|
-
}
|
227
|
+
// For most cases, this actually appears to be faster
|
228
|
+
// than arraycopy() on an array copying into itself.
|
229
|
+
for (int i = index; i < count - 1; i++) {
|
230
|
+
data[i] = data[i + 1];
|
231
|
+
}
|
232
|
+
count--;
|
233
|
+
return entry;
|
261
234
|
}
|
262
|
-
int removed = count - ii;
|
263
|
-
count = ii;
|
264
|
-
return removed;
|
265
|
-
}
|
266
235
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
data = PApplet.expand(data);
|
236
|
+
// Remove the first instance of a particular value,
|
237
|
+
// and return the index at which it was found.
|
238
|
+
public int removeValue(int value) {
|
239
|
+
int index = index(value);
|
240
|
+
if (index != -1) {
|
241
|
+
remove(index);
|
242
|
+
return index;
|
243
|
+
}
|
244
|
+
return -1;
|
277
245
|
}
|
278
|
-
data[count++] = value;
|
279
|
-
}
|
280
|
-
|
281
246
|
|
282
|
-
|
283
|
-
|
284
|
-
|
247
|
+
// Remove all instances of a particular value,
|
248
|
+
// and return the number of values found and removed
|
249
|
+
public int removeValues(int value) {
|
250
|
+
int ii = 0;
|
251
|
+
for (int i = 0; i < count; i++) {
|
252
|
+
if (data[i] != value) {
|
253
|
+
data[ii++] = data[i];
|
254
|
+
}
|
255
|
+
}
|
256
|
+
int removed = count - ii;
|
257
|
+
count = ii;
|
258
|
+
return removed;
|
259
|
+
}
|
260
|
+
|
261
|
+
/**
|
262
|
+
* Add a new entry to the list.
|
263
|
+
*
|
264
|
+
* @param value
|
265
|
+
* @webref intlist:method
|
266
|
+
* @brief Add a new entry to the list
|
267
|
+
*/
|
268
|
+
public void append(long value) {
|
269
|
+
if (count == data.length) {
|
270
|
+
data = PApplet.expand(data);
|
271
|
+
}
|
272
|
+
data[count++] = value;
|
285
273
|
}
|
286
|
-
}
|
287
|
-
|
288
274
|
|
289
|
-
|
290
|
-
|
291
|
-
|
275
|
+
public void append(int[] values) {
|
276
|
+
for (int v : values) {
|
277
|
+
append(v);
|
278
|
+
}
|
292
279
|
}
|
293
|
-
}
|
294
|
-
|
295
280
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
281
|
+
public void append(LongList list) {
|
282
|
+
for (long v : list.values()) { // will concat the list...
|
283
|
+
append(v);
|
284
|
+
}
|
300
285
|
}
|
301
|
-
}
|
302
286
|
|
287
|
+
/**
|
288
|
+
* Add this value, but only if it's not already in the list.
|
289
|
+
* @param value
|
290
|
+
*/
|
291
|
+
public void appendUnique(int value) {
|
292
|
+
if (!hasValue(value)) {
|
293
|
+
append(value);
|
294
|
+
}
|
295
|
+
}
|
303
296
|
|
304
297
|
// public void insert(int index, int value) {
|
305
298
|
// if (index+1 > count) {
|
@@ -329,50 +322,44 @@ public class LongList implements Iterable<Long> {
|
|
329
322
|
// count++;
|
330
323
|
// }
|
331
324
|
// }
|
332
|
-
|
333
|
-
|
334
|
-
public void insert(int index, long value) {
|
335
|
-
insert(index, new long[] { value });
|
336
|
-
}
|
337
|
-
|
338
|
-
|
339
|
-
// same as splice
|
340
|
-
public void insert(int index, long[] values) {
|
341
|
-
if (index < 0) {
|
342
|
-
throw new IllegalArgumentException("insert() index cannot be negative: it was " + index);
|
343
|
-
}
|
344
|
-
if (index >= data.length) {
|
345
|
-
throw new IllegalArgumentException("insert() index " + index + " is past the end of this list");
|
325
|
+
public void insert(int index, long value) {
|
326
|
+
insert(index, new long[]{value});
|
346
327
|
}
|
347
328
|
|
348
|
-
|
329
|
+
// same as splice
|
330
|
+
public void insert(int index, long[] values) {
|
331
|
+
if (index < 0) {
|
332
|
+
throw new IllegalArgumentException("insert() index cannot be negative: it was " + index);
|
333
|
+
}
|
334
|
+
if (index >= data.length) {
|
335
|
+
throw new IllegalArgumentException("insert() index " + index + " is past the end of this list");
|
336
|
+
}
|
349
337
|
|
350
|
-
|
351
|
-
System.arraycopy(data, 0, temp, 0, Math.min(count, index));
|
338
|
+
long[] temp = new long[count + values.length];
|
352
339
|
|
353
|
-
|
354
|
-
|
340
|
+
// Copy the old values, but not more than already exist
|
341
|
+
System.arraycopy(data, 0, temp, 0, Math.min(count, index));
|
342
|
+
|
343
|
+
// Copy the new values into the proper place
|
344
|
+
System.arraycopy(values, 0, temp, index, values.length);
|
355
345
|
|
356
346
|
// if (index < count) {
|
357
|
-
|
358
|
-
|
359
|
-
|
347
|
+
// The index was inside count, so it's a true splice/insert
|
348
|
+
System.arraycopy(data, index, temp, index + values.length, count - index);
|
349
|
+
count = count + values.length;
|
360
350
|
// } else {
|
361
351
|
// // The index was past 'count', so the new count is weirder
|
362
352
|
// count = index + values.length;
|
363
353
|
// }
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
public void insert(int index, LongList list) {
|
369
|
-
insert(index, list.values());
|
370
|
-
}
|
354
|
+
data = temp;
|
355
|
+
}
|
371
356
|
|
357
|
+
public void insert(int index, LongList list) {
|
358
|
+
insert(index, list.values());
|
359
|
+
}
|
372
360
|
|
373
361
|
// below are aborted attempts at more optimized versions of the code
|
374
362
|
// that are harder to read and debug...
|
375
|
-
|
376
363
|
// if (index + values.length >= count) {
|
377
364
|
// // We're past the current 'count', check to see if we're still allocated
|
378
365
|
// // index 9, data.length = 10, values.length = 1
|
@@ -411,11 +398,13 @@ public class LongList implements Iterable<Long> {
|
|
411
398
|
// data[index] = value;
|
412
399
|
// count++;
|
413
400
|
// }
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
401
|
+
/**
|
402
|
+
* Return the first index of a particular value.
|
403
|
+
* @param what
|
404
|
+
* @return
|
405
|
+
*/
|
406
|
+
public int index(int what) {
|
407
|
+
/*
|
419
408
|
if (indexCache != null) {
|
420
409
|
try {
|
421
410
|
return indexCache.get(what);
|
@@ -423,246 +412,245 @@ public class LongList implements Iterable<Long> {
|
|
423
412
|
return -1;
|
424
413
|
}
|
425
414
|
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
415
|
+
*/
|
416
|
+
for (int i = 0; i < count; i++) {
|
417
|
+
if (data[i] == what) {
|
418
|
+
return i;
|
419
|
+
}
|
420
|
+
}
|
421
|
+
return -1;
|
431
422
|
}
|
432
|
-
return -1;
|
433
|
-
}
|
434
423
|
|
435
|
-
|
436
|
-
|
437
|
-
// the rest of the entries are changed
|
424
|
+
// !!! TODO this is not yet correct, because it's not being reset when
|
425
|
+
// the rest of the entries are changed
|
438
426
|
// protected void cacheIndices() {
|
439
427
|
// indexCache = new HashMap<Integer, Integer>();
|
440
428
|
// for (int i = 0; i < count; i++) {
|
441
429
|
// indexCache.put(data[i], i);
|
442
430
|
// }
|
443
431
|
// }
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
432
|
+
/**
|
433
|
+
* @param value
|
434
|
+
* @return
|
435
|
+
* @webref intlist:method
|
436
|
+
* @brief Check if a number is a part of the list
|
437
|
+
*/
|
438
|
+
public boolean hasValue(int value) {
|
450
439
|
// if (indexCache == null) {
|
451
440
|
// cacheIndices();
|
452
441
|
// }
|
453
442
|
// return index(what) != -1;
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
}
|
461
|
-
|
462
|
-
/**
|
463
|
-
* @webref intlist:method
|
464
|
-
* @brief Add one to a value
|
465
|
-
*/
|
466
|
-
public void increment(int index) {
|
467
|
-
if (count <= index) {
|
468
|
-
resize(index + 1);
|
469
|
-
}
|
470
|
-
data[index]++;
|
471
|
-
}
|
472
|
-
|
473
|
-
|
474
|
-
private void boundsProblem(int index, String method) {
|
475
|
-
final String msg = String.format("The list size is %d. " +
|
476
|
-
"You cannot %s() to element %d.", count, method, index);
|
477
|
-
throw new ArrayIndexOutOfBoundsException(msg);
|
478
|
-
}
|
479
|
-
|
480
|
-
|
481
|
-
/**
|
482
|
-
* @webref intlist:method
|
483
|
-
* @brief Add to a value
|
484
|
-
*/
|
485
|
-
public void add(int index, int amount) {
|
486
|
-
if (index < count) {
|
487
|
-
data[index] += amount;
|
488
|
-
} else {
|
489
|
-
boundsProblem(index, "add");
|
490
|
-
}
|
491
|
-
}
|
492
|
-
|
493
|
-
/**
|
494
|
-
* @webref intlist:method
|
495
|
-
* @brief Subtract from a value
|
496
|
-
*/
|
497
|
-
public void sub(int index, int amount) {
|
498
|
-
if (index < count) {
|
499
|
-
data[index] -= amount;
|
500
|
-
} else {
|
501
|
-
boundsProblem(index, "sub");
|
502
|
-
}
|
503
|
-
}
|
504
|
-
|
505
|
-
/**
|
506
|
-
* @webref intlist:method
|
507
|
-
* @brief Multiply a value
|
508
|
-
*/
|
509
|
-
public void mult(int index, int amount) {
|
510
|
-
if (index < count) {
|
511
|
-
data[index] *= amount;
|
512
|
-
} else {
|
513
|
-
boundsProblem(index, "mult");
|
514
|
-
}
|
515
|
-
}
|
516
|
-
|
517
|
-
/**
|
518
|
-
* @webref intlist:method
|
519
|
-
* @brief Divide a value
|
520
|
-
*/
|
521
|
-
public void div(int index, int amount) {
|
522
|
-
if (index < count) {
|
523
|
-
data[index] /= amount;
|
524
|
-
} else {
|
525
|
-
boundsProblem(index, "div");
|
526
|
-
}
|
527
|
-
}
|
528
|
-
|
529
|
-
|
530
|
-
private void checkMinMax(String functionName) {
|
531
|
-
if (count == 0) {
|
532
|
-
String msg =
|
533
|
-
String.format("Cannot use %s() on an empty %s.",
|
534
|
-
functionName, getClass().getSimpleName());
|
535
|
-
throw new RuntimeException(msg);
|
536
|
-
}
|
537
|
-
}
|
538
|
-
|
539
|
-
|
540
|
-
/**
|
541
|
-
* @webref intlist:method
|
542
|
-
* @brief Return the smallest value
|
543
|
-
*/
|
544
|
-
public long min() {
|
545
|
-
checkMinMax("min");
|
546
|
-
long outgoing = data[0];
|
547
|
-
for (int i = 1; i < count; i++) {
|
548
|
-
if (data[i] < outgoing) outgoing = data[i];
|
549
|
-
}
|
550
|
-
return outgoing;
|
551
|
-
}
|
552
|
-
|
553
|
-
|
554
|
-
// returns the index of the minimum value.
|
555
|
-
// if there are ties, it returns the first one found.
|
556
|
-
public int minIndex() {
|
557
|
-
checkMinMax("minIndex");
|
558
|
-
long value = data[0];
|
559
|
-
int index = 0;
|
560
|
-
for (int i = 1; i < count; i++) {
|
561
|
-
if (data[i] < value) {
|
562
|
-
value = data[i];
|
563
|
-
index = i;
|
564
|
-
}
|
565
|
-
}
|
566
|
-
return index;
|
567
|
-
}
|
568
|
-
|
569
|
-
|
570
|
-
/**
|
571
|
-
* @webref intlist:method
|
572
|
-
* @brief Return the largest value
|
573
|
-
*/
|
574
|
-
public long max() {
|
575
|
-
checkMinMax("max");
|
576
|
-
long outgoing = data[0];
|
577
|
-
for (int i = 1; i < count; i++) {
|
578
|
-
if (data[i] > outgoing) outgoing = data[i];
|
579
|
-
}
|
580
|
-
return outgoing;
|
581
|
-
}
|
582
|
-
|
583
|
-
|
584
|
-
// returns the index of the maximum value.
|
585
|
-
// if there are ties, it returns the first one found.
|
586
|
-
public int maxIndex() {
|
587
|
-
checkMinMax("maxIndex");
|
588
|
-
long value = data[0];
|
589
|
-
int index = 0;
|
590
|
-
for (int i = 1; i < count; i++) {
|
591
|
-
if (data[i] > value) {
|
592
|
-
value = data[i];
|
593
|
-
index = i;
|
594
|
-
}
|
443
|
+
for (int i = 0; i < count; i++) {
|
444
|
+
if (data[i] == value) {
|
445
|
+
return true;
|
446
|
+
}
|
447
|
+
}
|
448
|
+
return false;
|
595
449
|
}
|
596
|
-
return index;
|
597
|
-
}
|
598
|
-
|
599
450
|
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
451
|
+
/**
|
452
|
+
* @param index
|
453
|
+
* @webref intlist:method
|
454
|
+
* @brief Add one to a value
|
455
|
+
*/
|
456
|
+
public void increment(int index) {
|
457
|
+
if (count <= index) {
|
458
|
+
resize(index + 1);
|
459
|
+
}
|
460
|
+
data[index]++;
|
607
461
|
}
|
608
|
-
return (int) amount;
|
609
|
-
}
|
610
|
-
|
611
462
|
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
463
|
+
private void boundsProblem(int index, String method) {
|
464
|
+
final String msg = String.format("The list size is %d. "
|
465
|
+
+ "You cannot %s() to element %d.", count, method, index);
|
466
|
+
throw new ArrayIndexOutOfBoundsException(msg);
|
616
467
|
}
|
617
|
-
return sum;
|
618
|
-
}
|
619
468
|
|
469
|
+
/**
|
470
|
+
* @param index
|
471
|
+
* @param amount
|
472
|
+
* @webref intlist:method
|
473
|
+
* @brief Add to a value
|
474
|
+
*/
|
475
|
+
public void add(int index, int amount) {
|
476
|
+
if (index < count) {
|
477
|
+
data[index] += amount;
|
478
|
+
} else {
|
479
|
+
boundsProblem(index, "add");
|
480
|
+
}
|
481
|
+
}
|
620
482
|
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
483
|
+
/**
|
484
|
+
* @param index
|
485
|
+
* @param amount
|
486
|
+
* @webref intlist:method
|
487
|
+
* @brief Subtract from a value
|
488
|
+
*/
|
489
|
+
public void sub(int index, int amount) {
|
490
|
+
if (index < count) {
|
491
|
+
data[index] -= amount;
|
492
|
+
} else {
|
493
|
+
boundsProblem(index, "sub");
|
494
|
+
}
|
495
|
+
}
|
630
496
|
|
497
|
+
/**
|
498
|
+
* @param index
|
499
|
+
* @param amount
|
500
|
+
* @webref intlist:method
|
501
|
+
* @brief Multiply a value
|
502
|
+
*/
|
503
|
+
public void mult(int index, int amount) {
|
504
|
+
if (index < count) {
|
505
|
+
data[index] *= amount;
|
506
|
+
} else {
|
507
|
+
boundsProblem(index, "mult");
|
508
|
+
}
|
509
|
+
}
|
631
510
|
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
511
|
+
/**
|
512
|
+
* @param index
|
513
|
+
* @param amount
|
514
|
+
* @webref intlist:method
|
515
|
+
* @brief Divide a value
|
516
|
+
*/
|
517
|
+
public void div(int index, int amount) {
|
518
|
+
if (index < count) {
|
519
|
+
data[index] /= amount;
|
520
|
+
} else {
|
521
|
+
boundsProblem(index, "div");
|
522
|
+
}
|
523
|
+
}
|
644
524
|
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
525
|
+
private void checkMinMax(String functionName) {
|
526
|
+
if (count == 0) {
|
527
|
+
String msg
|
528
|
+
= String.format("Cannot use %s() on an empty %s.",
|
529
|
+
functionName, getClass().getSimpleName());
|
530
|
+
throw new RuntimeException(msg);
|
531
|
+
}
|
532
|
+
}
|
650
533
|
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
534
|
+
/**
|
535
|
+
* @return @webref intlist:method
|
536
|
+
* @brief Return the smallest value
|
537
|
+
*/
|
538
|
+
public long min() {
|
539
|
+
checkMinMax("min");
|
540
|
+
long outgoing = data[0];
|
541
|
+
for (int i = 1; i < count; i++) {
|
542
|
+
if (data[i] < outgoing) {
|
543
|
+
outgoing = data[i];
|
544
|
+
}
|
545
|
+
}
|
546
|
+
return outgoing;
|
547
|
+
}
|
548
|
+
|
549
|
+
// returns the index of the minimum value.
|
550
|
+
// if there are ties, it returns the first one found.
|
551
|
+
public int minIndex() {
|
552
|
+
checkMinMax("minIndex");
|
553
|
+
long value = data[0];
|
554
|
+
int index = 0;
|
555
|
+
for (int i = 1; i < count; i++) {
|
556
|
+
if (data[i] < value) {
|
557
|
+
value = data[i];
|
558
|
+
index = i;
|
559
|
+
}
|
560
|
+
}
|
561
|
+
return index;
|
562
|
+
}
|
563
|
+
|
564
|
+
/**
|
565
|
+
* @return @webref intlist:method
|
566
|
+
* @brief Return the largest value
|
567
|
+
*/
|
568
|
+
public long max() {
|
569
|
+
checkMinMax("max");
|
570
|
+
long outgoing = data[0];
|
571
|
+
for (int i = 1; i < count; i++) {
|
572
|
+
if (data[i] > outgoing) {
|
573
|
+
outgoing = data[i];
|
574
|
+
}
|
575
|
+
}
|
576
|
+
return outgoing;
|
577
|
+
}
|
578
|
+
|
579
|
+
// returns the index of the maximum value.
|
580
|
+
// if there are ties, it returns the first one found.
|
581
|
+
public int maxIndex() {
|
582
|
+
checkMinMax("maxIndex");
|
583
|
+
long value = data[0];
|
584
|
+
int index = 0;
|
585
|
+
for (int i = 1; i < count; i++) {
|
586
|
+
if (data[i] > value) {
|
587
|
+
value = data[i];
|
588
|
+
index = i;
|
589
|
+
}
|
590
|
+
}
|
591
|
+
return index;
|
592
|
+
}
|
659
593
|
|
594
|
+
public int sum() {
|
595
|
+
long amount = sumLong();
|
596
|
+
if (amount > Integer.MAX_VALUE) {
|
597
|
+
throw new RuntimeException("sum() exceeds " + Integer.MAX_VALUE + ", use sumLong()");
|
598
|
+
}
|
599
|
+
if (amount < Integer.MIN_VALUE) {
|
600
|
+
throw new RuntimeException("sum() less than " + Integer.MIN_VALUE + ", use sumLong()");
|
601
|
+
}
|
602
|
+
return (int) amount;
|
603
|
+
}
|
660
604
|
|
661
|
-
|
605
|
+
public long sumLong() {
|
606
|
+
long sum = 0;
|
607
|
+
for (int i = 0; i < count; i++) {
|
608
|
+
sum += data[i];
|
609
|
+
}
|
610
|
+
return sum;
|
611
|
+
}
|
612
|
+
|
613
|
+
/**
|
614
|
+
* Sorts the array in place.
|
615
|
+
*
|
616
|
+
* @webref intlist:method
|
617
|
+
* @brief Sorts the array, lowest to highest
|
618
|
+
*/
|
619
|
+
public void sort() {
|
620
|
+
Arrays.sort(data, 0, count);
|
621
|
+
}
|
622
|
+
|
623
|
+
/**
|
624
|
+
* Reverse sort, orders values from highest to lowest.
|
625
|
+
*
|
626
|
+
* @webref intlist:method
|
627
|
+
* @brief Reverse sort, orders values from highest to lowest
|
628
|
+
*/
|
629
|
+
public void sortReverse() {
|
630
|
+
new Sort() {
|
631
|
+
@Override
|
632
|
+
public int size() {
|
633
|
+
return count;
|
634
|
+
}
|
635
|
+
|
636
|
+
@Override
|
637
|
+
public int compare(int a, int b) {
|
638
|
+
long diff = data[b] - data[a];
|
639
|
+
return diff == 0 ? 0 : (diff < 0 ? -1 : 1);
|
640
|
+
}
|
641
|
+
|
642
|
+
@Override
|
643
|
+
public void swap(int a, int b) {
|
644
|
+
long temp = data[a];
|
645
|
+
data[a] = data[b];
|
646
|
+
data[b] = temp;
|
647
|
+
}
|
648
|
+
}.run();
|
649
|
+
}
|
650
|
+
|
651
|
+
// use insert()
|
662
652
|
// public void splice(int index, int value) {
|
663
653
|
// }
|
664
|
-
|
665
|
-
|
666
654
|
// public void subset(int start) {
|
667
655
|
// subset(start, count - start);
|
668
656
|
// }
|
@@ -674,123 +662,123 @@ public class LongList implements Iterable<Long> {
|
|
674
662
|
// }
|
675
663
|
// count = num;
|
676
664
|
// }
|
665
|
+
/**
|
666
|
+
* @webref intlist:method
|
667
|
+
* @brief Reverse the order of the list elements
|
668
|
+
*/
|
669
|
+
public void reverse() {
|
670
|
+
int ii = count - 1;
|
671
|
+
for (int i = 0; i < count / 2; i++) {
|
672
|
+
long t = data[i];
|
673
|
+
data[i] = data[ii];
|
674
|
+
data[ii] = t;
|
675
|
+
--ii;
|
676
|
+
}
|
677
|
+
}
|
677
678
|
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
*
|
697
|
-
* @webref intlist:method
|
698
|
-
* @brief Randomize the order of the list elements
|
699
|
-
*/
|
700
|
-
public void shuffle() {
|
701
|
-
Random r = new Random();
|
702
|
-
int num = count;
|
703
|
-
while (num > 1) {
|
704
|
-
int value = r.nextInt(num);
|
705
|
-
num--;
|
706
|
-
long temp = data[num];
|
707
|
-
data[num] = data[value];
|
708
|
-
data[value] = temp;
|
709
|
-
}
|
710
|
-
}
|
711
|
-
|
712
|
-
|
713
|
-
/**
|
714
|
-
* Randomize the list order using the random() function from the specified
|
715
|
-
* sketch, allowing shuffle() to use its current randomSeed() setting.
|
716
|
-
*/
|
717
|
-
public void shuffle(PApplet sketch) {
|
718
|
-
int num = count;
|
719
|
-
while (num > 1) {
|
720
|
-
int value = (int) sketch.random(num);
|
721
|
-
num--;
|
722
|
-
long temp = data[num];
|
723
|
-
data[num] = data[value];
|
724
|
-
data[value] = temp;
|
725
|
-
}
|
726
|
-
}
|
727
|
-
|
728
|
-
|
729
|
-
public LongList copy() {
|
730
|
-
LongList outgoing = new LongList(data);
|
731
|
-
outgoing.count = count;
|
732
|
-
return outgoing;
|
733
|
-
}
|
734
|
-
|
735
|
-
|
736
|
-
/**
|
737
|
-
* Returns the actual array being used to store the data. For advanced users,
|
738
|
-
* this is the fastest way to access a large list. Suitable for iterating
|
739
|
-
* with a for() loop, but modifying the list will have terrible consequences.
|
740
|
-
*/
|
741
|
-
public long[] values() {
|
742
|
-
crop();
|
743
|
-
return data;
|
744
|
-
}
|
745
|
-
|
746
|
-
|
747
|
-
@Override
|
748
|
-
public Iterator<Long> iterator() {
|
749
|
-
// public Iterator<Integer> valueIterator() {
|
750
|
-
return new Iterator<Long>() {
|
751
|
-
int index = -1;
|
752
|
-
|
753
|
-
public void remove() {
|
754
|
-
LongList.this.remove(index);
|
755
|
-
index--;
|
756
|
-
}
|
757
|
-
|
758
|
-
public Long next() {
|
759
|
-
return data[++index];
|
760
|
-
}
|
761
|
-
|
762
|
-
public boolean hasNext() {
|
763
|
-
return index+1 < count;
|
764
|
-
}
|
765
|
-
};
|
766
|
-
}
|
767
|
-
|
679
|
+
/**
|
680
|
+
* Randomize the order of the list elements. Note that this does not obey
|
681
|
+
* the randomSeed() function in PApplet.
|
682
|
+
*
|
683
|
+
* @webref intlist:method
|
684
|
+
* @brief Randomize the order of the list elements
|
685
|
+
*/
|
686
|
+
public void shuffle() {
|
687
|
+
Random r = new Random();
|
688
|
+
int num = count;
|
689
|
+
while (num > 1) {
|
690
|
+
int value = r.nextInt(num);
|
691
|
+
num--;
|
692
|
+
long temp = data[num];
|
693
|
+
data[num] = data[value];
|
694
|
+
data[value] = temp;
|
695
|
+
}
|
696
|
+
}
|
768
697
|
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
698
|
+
/**
|
699
|
+
* Randomize the list order using the random() function from the specified
|
700
|
+
* sketch, allowing shuffle() to use its current randomSeed() setting.
|
701
|
+
*
|
702
|
+
* @param sketch
|
703
|
+
*/
|
704
|
+
public void shuffle(PApplet sketch) {
|
705
|
+
int num = count;
|
706
|
+
while (num > 1) {
|
707
|
+
int value = (int) sketch.random(num);
|
708
|
+
num--;
|
709
|
+
long temp = data[num];
|
710
|
+
data[num] = data[value];
|
711
|
+
data[value] = temp;
|
712
|
+
}
|
713
|
+
}
|
779
714
|
|
715
|
+
public LongList copy() {
|
716
|
+
LongList outgoing = new LongList(data);
|
717
|
+
outgoing.count = count;
|
718
|
+
return outgoing;
|
719
|
+
}
|
780
720
|
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
721
|
+
/**
|
722
|
+
* Returns the actual array being used to store the data.For advanced
|
723
|
+
users, this is the fastest way to access a large list. Suitable for
|
724
|
+
iterating with a for() loop, but modifying the list will have terrible
|
725
|
+
consequences.
|
726
|
+
* @return
|
727
|
+
*/
|
728
|
+
public long[] values() {
|
729
|
+
crop();
|
730
|
+
return data;
|
789
731
|
}
|
790
|
-
System.arraycopy(data, 0, array, 0, count);
|
791
|
-
return array;
|
792
|
-
}
|
793
732
|
|
733
|
+
@Override
|
734
|
+
public Iterator<Long> iterator() {
|
735
|
+
// public Iterator<Integer> valueIterator() {
|
736
|
+
return new Iterator<Long>() {
|
737
|
+
int index = -1;
|
738
|
+
|
739
|
+
@Override
|
740
|
+
public void remove() {
|
741
|
+
LongList.this.remove(index);
|
742
|
+
index--;
|
743
|
+
}
|
744
|
+
|
745
|
+
@Override
|
746
|
+
public Long next() {
|
747
|
+
return data[++index];
|
748
|
+
}
|
749
|
+
|
750
|
+
@Override
|
751
|
+
public boolean hasNext() {
|
752
|
+
return index + 1 < count;
|
753
|
+
}
|
754
|
+
};
|
755
|
+
}
|
756
|
+
|
757
|
+
/**
|
758
|
+
* Create a new array with a copy of all the values.
|
759
|
+
*
|
760
|
+
* @return an array sized by the length of the list with each of the values.
|
761
|
+
* @webref intlist:method
|
762
|
+
* @brief Create a new array with a copy of all the values
|
763
|
+
*/
|
764
|
+
public int[] array() {
|
765
|
+
return array(null);
|
766
|
+
}
|
767
|
+
|
768
|
+
/**
|
769
|
+
* Copy values into the specified array.If the specified array is null or
|
770
|
+
* not the same size, a new array will be allocated.
|
771
|
+
*
|
772
|
+
* @param array
|
773
|
+
* @return
|
774
|
+
*/
|
775
|
+
public int[] array(int[] array) {
|
776
|
+
if (array == null || array.length != count) {
|
777
|
+
array = new int[count];
|
778
|
+
}
|
779
|
+
System.arraycopy(data, 0, array, 0, count);
|
780
|
+
return array;
|
781
|
+
}
|
794
782
|
|
795
783
|
// public int[] toIntArray() {
|
796
784
|
// int[] outgoing = new int[count];
|
@@ -799,8 +787,6 @@ public class LongList implements Iterable<Long> {
|
|
799
787
|
// }
|
800
788
|
// return outgoing;
|
801
789
|
// }
|
802
|
-
|
803
|
-
|
804
790
|
// public long[] toLongArray() {
|
805
791
|
// long[] outgoing = new long[count];
|
806
792
|
// for (int i = 0; i < count; i++) {
|
@@ -808,15 +794,11 @@ public class LongList implements Iterable<Long> {
|
|
808
794
|
// }
|
809
795
|
// return outgoing;
|
810
796
|
// }
|
811
|
-
|
812
|
-
|
813
797
|
// public float[] toFloatArray() {
|
814
798
|
// float[] outgoing = new float[count];
|
815
799
|
// System.arraycopy(data, 0, outgoing, 0, count);
|
816
800
|
// return outgoing;
|
817
801
|
// }
|
818
|
-
|
819
|
-
|
820
802
|
// public double[] toDoubleArray() {
|
821
803
|
// double[] outgoing = new double[count];
|
822
804
|
// for (int i = 0; i < count; i++) {
|
@@ -824,8 +806,6 @@ public class LongList implements Iterable<Long> {
|
|
824
806
|
// }
|
825
807
|
// return outgoing;
|
826
808
|
// }
|
827
|
-
|
828
|
-
|
829
809
|
// public String[] toStringArray() {
|
830
810
|
// String[] outgoing = new String[count];
|
831
811
|
// for (int i = 0; i < count; i++) {
|
@@ -833,27 +813,26 @@ public class LongList implements Iterable<Long> {
|
|
833
813
|
// }
|
834
814
|
// return outgoing;
|
835
815
|
// }
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
816
|
+
/**
|
817
|
+
* Returns a normalized version of this array.Called getPercent() for
|
818
|
+
* consistency with the Dict classes. It's a getter method because it needs
|
819
|
+
* to returns a new list (because IntList/Dict can't do percentages or
|
820
|
+
* normalization in place on int values).
|
821
|
+
*
|
822
|
+
* @return
|
823
|
+
*/
|
824
|
+
public FloatList getPercent() {
|
825
|
+
double sum = 0;
|
826
|
+
for (float value : array()) {
|
827
|
+
sum += value;
|
828
|
+
}
|
829
|
+
FloatList outgoing = new FloatList(count);
|
830
|
+
for (int i = 0; i < count; i++) {
|
831
|
+
double percent = data[i] / sum;
|
832
|
+
outgoing.set(i, (float) percent);
|
833
|
+
}
|
834
|
+
return outgoing;
|
853
835
|
}
|
854
|
-
return outgoing;
|
855
|
-
}
|
856
|
-
|
857
836
|
|
858
837
|
// /**
|
859
838
|
// * Count the number of times each entry is found in this list.
|
@@ -866,72 +845,69 @@ public class LongList implements Iterable<Long> {
|
|
866
845
|
// }
|
867
846
|
// return outgoing;
|
868
847
|
// }
|
869
|
-
|
870
|
-
|
871
|
-
public LongList getSubset(int start) {
|
872
|
-
return getSubset(start, count - start);
|
873
|
-
}
|
874
|
-
|
875
|
-
|
876
|
-
public LongList getSubset(int start, int num) {
|
877
|
-
int[] subset = new int[num];
|
878
|
-
System.arraycopy(data, start, subset, 0, num);
|
879
|
-
return new LongList(subset);
|
880
|
-
}
|
881
|
-
|
882
|
-
|
883
|
-
public String join(String separator) {
|
884
|
-
if (count == 0) {
|
885
|
-
return "";
|
886
|
-
}
|
887
|
-
StringBuilder sb = new StringBuilder();
|
888
|
-
sb.append(data[0]);
|
889
|
-
for (int i = 1; i < count; i++) {
|
890
|
-
sb.append(separator);
|
891
|
-
sb.append(data[i]);
|
848
|
+
public LongList getSubset(int start) {
|
849
|
+
return getSubset(start, count - start);
|
892
850
|
}
|
893
|
-
return sb.toString();
|
894
|
-
}
|
895
851
|
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
852
|
+
public LongList getSubset(int start, int num) {
|
853
|
+
int[] subset = new int[num];
|
854
|
+
System.arraycopy(data, start, subset, 0, num);
|
855
|
+
return new LongList(subset);
|
900
856
|
}
|
901
|
-
}
|
902
|
-
|
903
|
-
|
904
|
-
/**
|
905
|
-
* Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
|
906
|
-
*/
|
907
|
-
public void save(File file) {
|
908
|
-
PrintWriter writer = PApplet.createWriter(file);
|
909
|
-
write(writer);
|
910
|
-
writer.close();
|
911
|
-
}
|
912
857
|
|
858
|
+
public String join(String separator) {
|
859
|
+
if (count == 0) {
|
860
|
+
return "";
|
861
|
+
}
|
862
|
+
StringBuilder sb = new StringBuilder();
|
863
|
+
sb.append(data[0]);
|
864
|
+
for (int i = 1; i < count; i++) {
|
865
|
+
sb.append(separator);
|
866
|
+
sb.append(data[i]);
|
867
|
+
}
|
868
|
+
return sb.toString();
|
869
|
+
}
|
913
870
|
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
for (int i = 0; i < count; i++) {
|
919
|
-
writer.println(data[i]);
|
871
|
+
public void print() {
|
872
|
+
for (int i = 0; i < count; i++) {
|
873
|
+
System.out.format("[%d] %d%n", i, data[i]);
|
874
|
+
}
|
920
875
|
}
|
921
|
-
writer.flush();
|
922
|
-
}
|
923
876
|
|
877
|
+
/**
|
878
|
+
* Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
|
879
|
+
*
|
880
|
+
* @param file
|
881
|
+
*/
|
882
|
+
public void save(File file) {
|
883
|
+
try (PrintWriter writer = PApplet.createWriter(file)) {
|
884
|
+
write(writer);
|
885
|
+
}
|
886
|
+
}
|
924
887
|
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
888
|
+
/**
|
889
|
+
* Write entries to a PrintWriter, one per line
|
890
|
+
*
|
891
|
+
* @param writer
|
892
|
+
*/
|
893
|
+
public void write(PrintWriter writer) {
|
894
|
+
for (int i = 0; i < count; i++) {
|
895
|
+
writer.println(data[i]);
|
896
|
+
}
|
897
|
+
writer.flush();
|
898
|
+
}
|
931
899
|
|
900
|
+
/**
|
901
|
+
* Return this dictionary as a String in JSON format.
|
902
|
+
*
|
903
|
+
* @return
|
904
|
+
*/
|
905
|
+
public String toJSON() {
|
906
|
+
return "[ " + join(", ") + " ]";
|
907
|
+
}
|
932
908
|
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
909
|
+
@Override
|
910
|
+
public String toString() {
|
911
|
+
return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
|
912
|
+
}
|
937
913
|
}
|