};
};
+static const struct ctables_cat_value *ctables_categories_match (
+ const struct ctables_categories *, const union value *,
+ const struct variable *);
+
static void
ctables_cat_value_uninit (struct ctables_cat_value *cv)
{
for (size_t i = 0; i < va->n; i++)
if (i != va->scale_idx)
{
- int cmp = value_compare_3way (&a->axes[aux->a].values[i],
- &b->axes[aux->a].values[i],
- var_get_width (va->vars[i]));
- if (cmp)
- return cmp;
+ const struct variable *var = va->vars[i];
+ const union value *val_a = &a->axes[aux->a].values[i];
+ const union value *val_b = &b->axes[aux->a].values[i];
+ int cmp = value_compare_3way (val_a, val_b, var_get_width (var));
+ if (!cmp)
+ continue;
+
+ const struct ctables_categories *cats = aux->t->categories[var_get_dict_index (var)];
+ if (cats && cats->n_values)
+ {
+ const struct ctables_cat_value *a_cv = ctables_categories_match (cats, val_a, var);
+ const struct ctables_cat_value *b_cv = ctables_categories_match (cats, val_b, var);
+ assert (a_cv && b_cv);
+ return (a_cv == b_cv ? cmp
+ : a_cv > b_cv ? 1
+ : -1);
+ }
+
+ return cmp;
}
return 0;
}