move NaN values to the end of the list when sorting

This commit is contained in:
Ben Fry
2014-07-30 20:42:40 -04:00
parent 26b60b4a69
commit 76dedb1d5b
5 changed files with 46 additions and 14 deletions
+16 -1
View File
@@ -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