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

Method sortImpl

core/src/processing/data/FloatDict.java:750–811  ·  view source on GitHub ↗
(final boolean useKeys, final boolean reverse,
                          final boolean stable)

Source from the content-addressed store, hash-verified

748
749
750 protected void sortImpl(final boolean useKeys, final boolean reverse,
751 final boolean stable) {
752 Sort s = new Sort() {
753 @Override
754 public int size() {
755 if (useKeys) {
756 return count; // don't worry about NaN values
757
758 } else if (count == 0) { // skip the NaN check, it'll AIOOBE
759 return 0;
760
761 } else { // first move NaN values to the end of the list
762 int right = count - 1;
763 while (values[right] != values[right]) {
764 right--;
765 if (right == -1) {
766 return 0; // all values are NaN
767 }
768 }
769 for (int i = right; i >= 0; --i) {
770 if (Float.isNaN(values[i])) {
771 swap(i, right);
772 --right;
773 }
774 }
775 return right + 1;
776 }
777 }
778
779 @Override
780 public int compare(int a, int b) {
781 float diff = 0;
782 if (useKeys) {
783 diff = keys[a].compareToIgnoreCase(keys[b]);
784 if (diff == 0) {
785 diff = values[a] - values[b];
786 }
787 } else { // sort values
788 diff = values[a] - values[b];
789 if (diff == 0 && stable) {
790 diff = keys[a].compareToIgnoreCase(keys[b]);
791 }
792 }
793 if (diff == 0) {
794 return 0;
795 } else if (reverse) {
796 return diff < 0 ? 1 : -1;
797 } else {
798 return diff < 0 ? -1 : 1;
799 }
800 }
801
802 @Override
803 public void swap(int a, int b) {
804 FloatDict.this.swap(a, b);
805 }
806 };
807 s.run();

Callers 4

sortKeysMethod · 0.95
sortKeysReverseMethod · 0.95
sortValuesMethod · 0.95
sortValuesReverseMethod · 0.95

Calls 2

runMethod · 0.95
resetIndicesMethod · 0.95

Tested by

no test coverage detected