The reference order: an insertion sort that moves a row before an earlier * one only when the earlier one compares greater — stable, like the old * bubble sorts. */
| 5632 | * one only when the earlier one compares greater — stable, like the old |
| 5633 | * bubble sorts. */ |
| 5634 | static void ref_stable_order(const cbm_cypher_result_t *r, int *order, ref_cmp_fn cmp) { |
| 5635 | for (int i = 0; i < r->row_count; i++) { |
| 5636 | order[i] = i; |
| 5637 | } |
| 5638 | for (int i = 1; i < r->row_count; i++) { |
| 5639 | for (int j = i; j > 0 && cmp(r, order[j - 1], order[j]) > 0; j--) { |
| 5640 | int swap = order[j]; |
| 5641 | order[j] = order[j - 1]; |
| 5642 | order[j - 1] = swap; |
| 5643 | } |
| 5644 | } |
| 5645 | } |
| 5646 | |
| 5647 | /* Columns 0 (name) and 1 (line): line descending, then name ascending. */ |
| 5648 | static int ref_line_desc_name(const cbm_cypher_result_t *r, int a, int b) { |