mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
move NaN values to the end of the list when sorting
This commit is contained in:
@@ -668,7 +668,22 @@ public class FloatDict {
|
||||
Sort s = new Sort() {
|
||||
@Override
|
||||
public int size() {
|
||||
return count;
|
||||
if (useKeys) {
|
||||
return count; // don't worry about NaN values
|
||||
|
||||
} else { // first move NaN values to the end of the list
|
||||
int right = count - 1;
|
||||
while (values[right] != values[right]) {
|
||||
right--;
|
||||
}
|
||||
for (int i = right; i >= 0; --i) {
|
||||
if (Float.isNaN(values[i])) {
|
||||
swap(i, right);
|
||||
--right;
|
||||
}
|
||||
}
|
||||
return right + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -566,7 +566,20 @@ public class FloatList implements Iterable<Float> {
|
||||
new Sort() {
|
||||
@Override
|
||||
public int size() {
|
||||
return count;
|
||||
// move NaN values to the end of the list and don't sort them
|
||||
int right = count - 1;
|
||||
while (data[right] != data[right]) {
|
||||
right--;
|
||||
}
|
||||
for (int i = right; i >= 0; --i) {
|
||||
float v = data[i];
|
||||
if (v != v) {
|
||||
data[i] = data[right];
|
||||
data[right] = v;
|
||||
--right;
|
||||
}
|
||||
}
|
||||
return right + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,8 +31,8 @@ public abstract class Sort implements Runnable {
|
||||
protected int partition(int left, int right) {
|
||||
int pivot = right;
|
||||
do {
|
||||
while (compare(++left, pivot) < 0) ;
|
||||
while ((right != 0) && (compare(--right, pivot) > 0)) ;
|
||||
while (compare(++left, pivot) < 0) { }
|
||||
while ((right != 0) && (compare(--right, pivot) > 0)) { }
|
||||
swap(left, right);
|
||||
} while (left < right);
|
||||
swap(left, right);
|
||||
|
||||
Reference in New Issue
Block a user