+static int
+compare_ints_3way (int a, int b)
+{
+ return a < b ? -1 : a > b;
+}
+
+static int
+ctables_cell_compare_leaf_3way (const void *a_, const void *b_,
+ const void *aux UNUSED)
+{
+ struct ctables_cell *const *ap = a_;
+ struct ctables_cell *const *bp = b_;
+ const struct ctables_cell *a = *ap;
+ const struct ctables_cell *b = *bp;
+
+ if (a == b)
+ {
+ assert (a_ == b_);
+ return 0;
+ }
+
+ for (enum pivot_axis_type axis = 0; axis < PIVOT_N_AXES; axis++)
+ {
+ int cmp = compare_ints_3way (a->axes[axis].leaf, b->axes[axis].leaf);
+ if (cmp)
+ return cmp;
+ }
+
+ const struct ctables_value *a_ctv = ctables_value_find (a);
+ const struct ctables_value *b_ctv = ctables_value_find (b);
+ if (a_ctv && b_ctv)
+ {
+ int cmp = compare_ints_3way (a_ctv->leaf, b_ctv->leaf);
+ if (cmp)
+ return cmp;
+ }
+ else
+ assert (!a_ctv && !b_ctv);
+ return 0;
+}
+