From 623504ed9e09daaeabde3168070ded7767816460 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 2 Jan 2022 17:38:32 -0800 Subject: [PATCH] Rename ctables_freq to ctables_cell. --- src/language/stats/ctables.c | 96 +++++++++++++----------------------- 1 file changed, 33 insertions(+), 63 deletions(-) diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index 64ef2a5e64..aee54a1f52 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -165,15 +165,15 @@ struct ctables_domain { struct hmap_node node; - const struct ctables_freq *example; + const struct ctables_cell *example; double valid; double missing; }; -struct ctables_freq +struct ctables_cell { - /* In struct ctables's 'ft' hmap. Indexed by all the values in all the + /* In struct ctables's 'cells' hmap. Indexed by all the values in all the axes (except the scalar variable, if any). */ struct hmap_node node; @@ -293,7 +293,7 @@ struct ctables_table struct ctables_axis *axes[PIVOT_N_AXES]; struct var_array2 vaas[PIVOT_N_AXES]; enum pivot_axis_type summary_axis; - struct hmap ft; + struct hmap cells; struct hmap domains[N_CTDTS]; enum pivot_axis_type slabels_position; @@ -1740,7 +1740,7 @@ ctables_summary_add (union ctables_summary *s, } static double -ctables_summary_value (const struct ctables_freq *f, +ctables_summary_value (const struct ctables_cell *f, union ctables_summary *s, const struct ctables_summary_spec *ss) { @@ -1882,20 +1882,20 @@ ctables_summary_value (const struct ctables_freq *f, NOT_REACHED (); } -struct ctables_freq_sort_aux +struct ctables_cell_sort_aux { const struct ctables_table *t; enum pivot_axis_type a; }; static int -ctables_freq_compare_3way (const void *a_, const void *b_, const void *aux_) +ctables_cell_compare_3way (const void *a_, const void *b_, const void *aux_) { - const struct ctables_freq_sort_aux *aux = aux_; - struct ctables_freq *const *ap = a_; - struct ctables_freq *const *bp = b_; - const struct ctables_freq *a = *ap; - const struct ctables_freq *b = *bp; + const struct ctables_cell_sort_aux *aux = aux_; + struct ctables_cell *const *ap = a_; + struct ctables_cell *const *bp = b_; + const struct ctables_cell *a = *ap; + const struct ctables_cell *b = *bp; size_t a_idx = a->axes[aux->a].vaa_idx; size_t b_idx = b->axes[aux->a].vaa_idx; @@ -1974,7 +1974,7 @@ ctables_freq_compare_3way (const void *a_, const void *b_, const void *aux_) */ static struct ctables_domain * -ctables_domain_insert (struct ctables_table *t, struct ctables_freq *f, +ctables_domain_insert (struct ctables_table *t, struct ctables_cell *f, enum ctables_domain_type domain) { size_t hash = 0; @@ -1994,7 +1994,7 @@ ctables_domain_insert (struct ctables_table *t, struct ctables_freq *f, struct ctables_domain *d; HMAP_FOR_EACH_WITH_HASH (d, struct ctables_domain, node, hash, &t->domains[domain]) { - const struct ctables_freq *df = d->example; + const struct ctables_cell *df = d->example; for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++) { size_t idx = f->axes[a].vaa_idx; @@ -2066,10 +2066,10 @@ ctables_categories_match (const struct ctables_categories *cats, } static void -ctables_freqtab_insert (struct ctables_table *t, - const struct ccase *c, - size_t ir, size_t ic, size_t il, - double weight) +ctables_cell_insert (struct ctables_table *t, + const struct ccase *c, + size_t ir, size_t ic, size_t il, + double weight) { size_t ix[PIVOT_N_AXES] = { [PIVOT_AXIS_ROW] = ir, @@ -2123,8 +2123,8 @@ ctables_freqtab_insert (struct ctables_table *t, var_get_width (va->vars[i]), hash); } - struct ctables_freq *f; - HMAP_FOR_EACH_WITH_HASH (f, struct ctables_freq, node, hash, &t->ft) + struct ctables_cell *f; + HMAP_FOR_EACH_WITH_HASH (f, struct ctables_cell, node, hash, &t->cells) { for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++) { @@ -2161,7 +2161,7 @@ ctables_freqtab_insert (struct ctables_table *t, ctables_summary_init (&f->summaries[i], &ss->summaries[i]); for (enum ctables_domain_type dt = 0; dt < N_CTDTS; dt++) f->domains[dt] = ctables_domain_insert (t, f, dt); - hmap_insert (&t->ft, &f->node, hash); + hmap_insert (&t->cells, &f->node, hash); summarize: for (size_t i = 0; i < ss->n_summaries; i++) @@ -2284,7 +2284,7 @@ ctables_execute (struct dataset *ds, struct ctables *ct) for (size_t ir = 0; ir < t->vaas[PIVOT_AXIS_ROW].n; ir++) for (size_t ic = 0; ic < t->vaas[PIVOT_AXIS_COLUMN].n; ic++) for (size_t il = 0; il < t->vaas[PIVOT_AXIS_LAYER].n; il++) - ctables_freqtab_insert (t, c, ir, ic, il, weight); + ctables_cell_insert (t, c, ir, ic, il, weight); } } casereader_destroy (input); @@ -2322,16 +2322,16 @@ ctables_execute (struct dataset *ds, struct ctables *ct) assert (t->axes[a]); - struct ctables_freq **sorted = xnmalloc (t->ft.count, sizeof *sorted); + struct ctables_cell **sorted = xnmalloc (t->cells.count, sizeof *sorted); - struct ctables_freq *f; + struct ctables_cell *f; size_t n = 0; - HMAP_FOR_EACH (f, struct ctables_freq, node, &t->ft) + HMAP_FOR_EACH (f, struct ctables_cell, node, &t->cells) sorted[n++] = f; - assert (n == t->ft.count); + assert (n == t->cells.count); - struct ctables_freq_sort_aux aux = { .t = t, .a = a }; - sort (sorted, n, sizeof *sorted, ctables_freq_compare_3way, &aux); + struct ctables_cell_sort_aux aux = { .t = t, .a = a }; + sort (sorted, n, sizeof *sorted, ctables_cell_compare_3way, &aux); size_t max_depth = 0; for (size_t j = 0; j < t->vaas[a].n; j++) @@ -2343,14 +2343,14 @@ ctables_execute (struct dataset *ds, struct ctables *ct) int prev_leaf = 0; for (size_t j = 0; j < n; j++) { - struct ctables_freq *f = sorted[j]; + struct ctables_cell *f = sorted[j]; const struct var_array *va = &t->vaas[a].vas[f->axes[a].vaa_idx]; size_t n_common = 0; bool new_subtable = false; if (j > 0) { - struct ctables_freq *prev = sorted[j - 1]; + struct ctables_cell *prev = sorted[j - 1]; if (prev->axes[a].vaa_idx == f->axes[a].vaa_idx) { for (; n_common < va->n; n_common++) @@ -2429,8 +2429,8 @@ ctables_execute (struct dataset *ds, struct ctables *ct) free (sorted); free (groups); } - struct ctables_freq *f; - HMAP_FOR_EACH (f, struct ctables_freq, node, &t->ft) + struct ctables_cell *f; + HMAP_FOR_EACH (f, struct ctables_cell, node, &t->cells) { const struct var_array *ss = &t->vaas[t->summary_axis].vas[f->axes[t->summary_axis].vaa_idx]; for (size_t j = 0; j < ss->n_summaries; j++) @@ -2457,36 +2457,6 @@ ctables_execute (struct dataset *ds, struct ctables *ct) pivot_table_submit (pt); } -#if 0 - for (size_t i = 0; i < ct->n_tables; i++) - { - struct ctables_table *t = ct->tables[i]; - - for (size_t j = 0; j < t->n_fts; j++) - { - struct ctables_freqtab *ft = t->fts[j]; - struct ctables_freq *f, *next; - HMAP_FOR_EACH_SAFE (f, next, struct ctables_freq, node, &ft->data) - { - hmap_delete (&ft->data, &f->node); - for (size_t k = 0; k < ft->n_summaries; k++) - ctables_summary_uninit (&f->summaries[k], &ft->summaries[k]); - free (f->summaries); - for (size_t k = 0; k < ft->vars.n; k++) - { - const struct variable *var = ft->vars.vars[k]; - value_destroy (&f->values[k], var_get_width (var)); - } - free (f); - } - hmap_destroy (&ft->data); - var_array_uninit (&ft->vars); - free (ft); - } - free (t->fts); - } -#endif - return proc_commit (ds); } @@ -2704,7 +2674,7 @@ cmd_ctables (struct lexer *lexer, struct dataset *ds) struct ctables_table *t = xmalloc (sizeof *t); *t = (struct ctables_table) { - .ft = HMAP_INITIALIZER (t->ft), + .cells = HMAP_INITIALIZER (t->cells), .slabels_position = PIVOT_AXIS_COLUMN, .slabels_visible = true, .row_labels = CTLP_NORMAL, -- 2.30.2