for (size_t j = 0; j < n_sorted; j++)
{
struct ctables_cell *cell = sorted[j];
+ struct ctables_cell *prev = j > 0 ? sorted[j - 1] : NULL;
const struct ctables_nest *nest = &t->stacks[a].nests[cell->axes[a].stack_idx];
- size_t n_common = 0;
- bool new_subtable = false;
- if (j > 0)
- {
- struct ctables_cell *prev = sorted[j - 1];
- if (prev->axes[a].stack_idx == cell->axes[a].stack_idx)
- {
- for (; n_common < nest->n; n_common++)
- if (n_common != nest->scale_idx
- && (prev->axes[a].cvs[n_common].category
- != cell->axes[a].cvs[n_common].category
- || !value_equal (&prev->axes[a].cvs[n_common].value,
- &cell->axes[a].cvs[n_common].value,
- var_get_type (nest->vars[n_common]))))
- break;
- if (a == PIVOT_AXIS_ROW)
- printf ("n_common=%zu\n", n_common);
- }
- else
- new_subtable = true;
- }
- else
- new_subtable = true;
-
+ bool new_subtable = !prev || prev->axes[a].stack_idx != cell->axes[a].stack_idx;
if (new_subtable)
{
n_levels = 0;
}
printf ("\n");
}
- if (a == PIVOT_AXIS_ROW)
- printf ("n_common=%zu\n", n_common);
- if (n_common == nest->n)
+
+ size_t n_common = 0;
+ if (!new_subtable)
{
- cell->axes[a].leaf = prev_leaf;
- continue;
+ for (; n_common < nest->n; n_common++)
+ {
+ const struct ctables_level *level = &levels[n_common];
+ if (level->type == CTL_CATEGORY)
+ {
+ size_t var_idx = level->var_idx;
+ if (prev->axes[a].cvs[var_idx].category
+ != cell->axes[a].cvs[var_idx].category
+ || !value_equal (&prev->axes[a].cvs[var_idx].value,
+ &cell->axes[a].cvs[var_idx].value,
+ var_get_type (nest->vars[var_idx])))
+ break;
+ }
+ }
}
- for (size_t k = 0; k < n_levels; k++)
+ for (size_t k = n_common; k < n_levels; k++)
{
const struct ctables_level *level = &levels[k];
- if (n_common > level->var_idx)
- continue;
-
struct pivot_category *parent = k ? groups[k - 1] : d[a]->root;
if (level->type == CTL_SUMMARY)
{