+ if (!flag)
+ {
+ struct category *s = xzalloc (sizeof *s);
+ s->idx = idx++;
+ value_init (&s->val, var_get_width (var[pidx]));
+ value_copy (&s->val, &src->values[pidx], var_get_width (var[pidx]));
+ ds_init_empty (&s->label);
+ var_append_value_name (var[pidx], &s->val, &s->label);
+
+ hmap_insert (&bar->primaries, &s->node, hash);
+ }
+ }
+
+ bar->n_pcats = hmap_count (&bar->primaries);
+ }
+
+ if (n_vars > 1)
+ {
+ hmap_init (&bar->secondaries);
+ int idx = 0;
+ /* Iterate the categories, and create a hash table of secondary categories */
+ for (i = 0; i < n_cats; i++)
+ {
+ struct freq *src = cats[i];
+
+ struct category *foo;
+ int flag = 0;
+ size_t hash = value_hash (&src->values[sidx], var_get_width (var[sidx]), 0);
+ HMAP_FOR_EACH_WITH_HASH (foo, struct category, node, hash, &bar->secondaries)
+ {
+ if (value_equal (&foo->val, &src->values[sidx], var_get_width (var[sidx])))
+ {
+ flag = 1;
+ break;
+ }
+ }
+
+ if (!flag)
+ {
+ struct category *s = xzalloc (sizeof *s);
+ s->idx = idx++;
+ value_init (&s->val, var_get_width (var[sidx]));
+ value_copy (&s->val, &src->values[sidx], var_get_width (var[sidx]));
+ ds_init_empty (&s->label);
+ var_append_value_name (var[sidx], &s->val, &s->label);
+
+ hmap_insert (&bar->secondaries, &s->node, hash);
+ bar->ss = xrealloc (bar->ss, idx * sizeof *bar->ss);
+ bar->ss[idx - 1] = s;
+ }
+ }
+
+ int n_category = hmap_count (&bar->secondaries);
+
+ sort (bar->ss, n_category, sizeof *bar->ss,
+ compare_category_3way, bar);