Skip to content

Commit 76dedb1

Browse files
committed
move NaN values to the end of the list when sorting
1 parent 26b60b4 commit 76dedb1

5 files changed

Lines changed: 46 additions & 14 deletions

File tree

core/src/processing/data/FloatDict.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,22 @@ protected void sortImpl(final boolean useKeys, final boolean reverse) {
668668
Sort s = new Sort() {
669669
@Override
670670
public int size() {
671-
return count;
671+
if (useKeys) {
672+
return count; // don't worry about NaN values
673+
674+
} else { // first move NaN values to the end of the list
675+
int right = count - 1;
676+
while (values[right] != values[right]) {
677+
right--;
678+
}
679+
for (int i = right; i >= 0; --i) {
680+
if (Float.isNaN(values[i])) {
681+
swap(i, right);
682+
--right;
683+
}
684+
}
685+
return right + 1;
686+
}
672687
}
673688

674689
@Override

core/src/processing/data/FloatList.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,20 @@ public void sortReverse() {
566566
new Sort() {
567567
@Override
568568
public int size() {
569-
return count;
569+
// move NaN values to the end of the list and don't sort them
570+
int right = count - 1;
571+
while (data[right] != data[right]) {
572+
right--;
573+
}
574+
for (int i = right; i >= 0; --i) {
575+
float v = data[i];
576+
if (v != v) {
577+
data[i] = data[right];
578+
data[right] = v;
579+
--right;
580+
}
581+
}
582+
return right + 1;
570583
}
571584

572585
@Override

core/src/processing/data/Sort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ protected void sort(int i, int j) {
3131
protected int partition(int left, int right) {
3232
int pivot = right;
3333
do {
34-
while (compare(++left, pivot) < 0) ;
35-
while ((right != 0) && (compare(--right, pivot) > 0)) ;
34+
while (compare(++left, pivot) < 0) { }
35+
while ((right != 0) && (compare(--right, pivot) > 0)) { }
3636
swap(left, right);
3737
} while (left < right);
3838
swap(left, right);

core/todo.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
0229 core (3.0a2)
2-
X add copy() method to Table
3-
X return null from getString() on NaN float and double values
4-
X affects how saveTable() works (writes blank entries instead of NaN)
5-
X get(5) with an empty Int/Float/StringList was returning 0
6-
X https://github.com/processing/processing/pull/2343
72
X PImage resize() causes images to not draw
83
X https://github.com/processing/processing/issues/2228
94
X https://github.com/processing/processing/pull/2324
105
X move to native OS X full screen (gets rid of native code)
116
X https://github.com/processing/processing/issues/2641
127

8+
data
9+
X add copy() method to Table
10+
X return null from getString() on NaN float and double values
11+
X affects how saveTable() works (writes blank entries instead of NaN)
12+
X get(5) with an empty Int/Float/StringList was returning 0
13+
X https://github.com/processing/processing/pull/2343
14+
o fix for maxValue() and minValue() when all entries are bad
15+
o on FloatDict it was NaN, check across the lists and other dict types
16+
X nothing else to do here
17+
X FloatDict and FloatList should always put NaN values at the end on sort
18+
X same for the other list and dict classes
19+
X (this is part of the point of having these easier versions)
1320

1421
pulls
1522
X implement A and a (elliptical arcs)
@@ -33,11 +40,6 @@ processing.data
3340
_ need a better method for "missing" data in Table
3441
_ if missing int is zero, can't just remove those values from saving a table
3542
_ but for NaN values, it's a necessity
36-
_ fix for maxValue() and minValue() when all entries are bad
37-
_ on FloatDict it was NaN, check across the lists and other dict types
38-
_ StringDict should always put NaN values at the end on sort
39-
_ same for the other list and dict classes
40-
_ (this is part of the point of having these easier versions)
4143
_ get() methods in List/Dict shouldn't allow you to get bad values
4244
_ but set() methods can automatically resize the arrays
4345
_ though that means insert() should allow you to insert past the end
@@ -54,6 +56,7 @@ _ match and iterators
5456
_ add match version that returns table that's only a pointer to original
5557
_ save the constructor for the version that actually copies data
5658
_ the table pointer version will be speedy and allow chaining
59+
_ add Double and Long versions of the classes?
5760

5861

5962
later

todo.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ X remove welcome message from the sound library
3131
X URL opening problem fixed by use of getCanonicalPath() on Windows
3232
X https://github.com/processing/processing/issues/2656
3333
X add a new pref for the 3.0 sketchbook location
34+
_ when renaming a tab, include the previous name to be edited
3435

3536
gsoc
3637
X clear status messages in the Contribution Manager

0 commit comments

Comments
 (0)