MCPcopy Index your code
hub / github.com/benfry/processing4 / sortReverse

Method sortReverse

core/src/processing/data/FloatList.java:605–645  ·  view source on GitHub ↗

A sort in reverse. It's equivalent to running sort() and then reverse() , but is more efficient than running each separately. @webref floatlist:method @webBrief A sort in reverse

()

Source from the content-addressed store, hash-verified

603 * @webBrief A sort in reverse
604 */
605 public void sortReverse() {
606 new Sort() {
607 @Override
608 public int size() {
609 // if empty, don't even mess with the NaN check, it'll AIOOBE
610 if (count == 0) {
611 return 0;
612 }
613 // move NaN values to the end of the list and don't sort them
614 int right = count - 1;
615 while (data[right] != data[right]) {
616 right--;
617 if (right == -1) { // all values are NaN
618 return 0;
619 }
620 }
621 for (int i = right; i >= 0; --i) {
622 float v = data[i];
623 if (v != v) {
624 data[i] = data[right];
625 data[right] = v;
626 --right;
627 }
628 }
629 return right + 1;
630 }
631
632 @Override
633 public int compare(int a, int b) {
634 float diff = data[b] - data[a];
635 return diff == 0 ? 0 : (diff < 0 ? -1 : 1);
636 }
637
638 @Override
639 public void swap(int a, int b) {
640 float temp = data[a];
641 data[a] = data[b];
642 data[b] = temp;
643 }
644 }.run();
645 }
646
647
648 /**

Callers

nothing calls this directly

Calls 1

runMethod · 0.65

Tested by

no test coverage detected