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