- HMAP_FOR_EACH_WITH_HASH (vn, struct variable_node, node, hash, map)
+ HMAP_FOR_EACH_WITH_HASH (vn, struct variable_node, node,
+ hash_pointer (var, 0), map)
- {
- int v;
- struct string str;
- const struct interact_params *iap = &cat->iap[i];
- const struct interaction *iact = iap->iact;
-
- ds_init_empty (&str);
- interaction_to_string (iact, &str);
-
- printf ("\nInteraction: \"%s\" (number of categories: %d); ", ds_cstr (&str), iap->n_cats);
- ds_destroy (&str);
- printf ("Base index (df/categories): %d/%d\n", iap->base_df, iap->base_cats);
-
- printf ("\t(");
- for (v = 0; v < hmap_count (&iap->ivmap); ++v)
- {
- int vv;
- const struct interaction_value *iv = iap->ivs[v];
-
- if (v > 0) printf (" ");
- printf ("{");
- for (vv = 0; vv < iact->n_vars; ++vv)
- {
- const struct variable *var = iact->vars[vv];
- const union value *val = case_data (iv->ccase, var);
- struct variable_node *vn = iap->varnodes[vv];
- const int width = var_get_width (var);
- unsigned int valhash = value_hash (val, width, 0);
- struct value_node *valn = lookup_value (&vn->valmap, val, valhash, width);
-
- assert (vn->var == var);
-
- printf ("%.*g(%d)", DBL_DIG + 1, val->f, valn->index);
- if (vv < iact->n_vars - 1)
- printf (", ");
- }
- printf ("}");
- }
- printf (")\n");
- }
+ {
+ int v;
+ struct string str;
+ const struct interact_params *iap = &cat->iap[i];
+ const struct interaction *iact = iap->iact;
+
+ ds_init_empty (&str);
+ interaction_to_string (iact, &str);
+
+ printf ("\nInteraction: \"%s\" (number of categories: %d); ", ds_cstr (&str), iap->n_cats);
+ ds_destroy (&str);
+ printf ("Base index (df/categories): %d/%d\n", iap->base_df, iap->base_cats);
+
+ printf ("\t(");
+ for (v = 0; v < hmap_count (&iap->ivmap); ++v)
+ {
+ int vv;
+ const struct interaction_value *iv = iap->ivs[v];
+
+ if (v > 0) printf (" ");
+ printf ("{");
+ for (vv = 0; vv < iact->n_vars; ++vv)
+ {
+ const struct variable *var = iact->vars[vv];
+ const union value *val = case_data (iv->ccase, var);
+ struct variable_node *vn = iap->varnodes[vv];
+ const int width = var_get_width (var);
+ unsigned int valhash = value_hash (val, width, 0);
+ struct value_node *valn = lookup_value (&vn->valmap, val, valhash, width);
+
+ assert (vn->var == var);
+
+ printf ("%.*g(%d)", DBL_DIG + 1, val->f, valn->index);
+ if (vv < iact->n_vars - 1)
+ printf (", ");
+ }
+ printf ("}");
+ }
+ printf (")\n");
+ }
/* Unref any cases that we reffed. */
struct interaction_value *iv;
HMAP_FOR_EACH (iv, struct interaction_value, node, &cat->iap[i].ivmap)
/* Unref any cases that we reffed. */
struct interaction_value *iv;
HMAP_FOR_EACH (iv, struct interaction_value, node, &cat->iap[i].ivmap)
- {
- if (cat->payload && cat->payload->destroy)
- cat->payload->destroy (cat->aux1, cat->aux2, iv->user_data);
- case_unref (iv->ccase);
- }
+ {
+ if (cat->payload && cat->payload->destroy)
+ cat->payload->destroy (cat->aux1, cat->aux2, iv->user_data);
+ case_unref (iv->ccase);
+ }
- {
- const struct variable *var = inter[i]->vars[v];
- unsigned int hash = hash_pointer (var, 0);
- struct variable_node *vn = lookup_variable (&cat->varmap, var, hash);
- if (!vn)
- {
- vn = pool_malloc (cat->pool, sizeof *vn);
- vn->var = var;
- hmap_init (&vn->valmap);
- hmap_insert (&cat->varmap, &vn->node, hash);
- }
+ {
+ const struct variable *var = inter[i]->vars[v];
+ struct variable_node *vn = lookup_variable (&cat->varmap, var);
+ if (!vn)
+ {
+ vn = pool_malloc (cat->pool, sizeof *vn);
+ vn->var = var;
+ vn->values = NULL;
+ hmap_init (&vn->valmap);
+ hmap_insert (&cat->varmap, &vn->node, hash_pointer (var, 0));
+ }
- {
- valn = pool_malloc (cat->pool, sizeof *valn);
- valn->index = -1;
- value_init (&valn->val, width);
- value_copy (&valn->val, val, width);
- hmap_insert (&vn->valmap, &valn->node, hash);
- }
+ {
+ valn = pool_malloc (cat->pool, sizeof *valn);
+ valn->index = -1;
+ value_init_pool (cat->pool, &valn->val, width);
+ value_copy (&valn->val, val, width);
+ hmap_insert (&vn->valmap, &valn->node, hash);
+ }
struct interact_params *iap = &cat->iap[i];
const struct interaction *iact = iap->iact;
if (interaction_case_is_missing (iact, c, cat->fctr_excl))
struct interact_params *iap = &cat->iap[i];
const struct interaction *iact = iap->iact;
if (interaction_case_is_missing (iact, c, cat->fctr_excl))
unsigned int hash = interaction_case_hash (iact, c, 0);
struct interaction_value *node = lookup_case (&iap->ivmap, iact, c);
if (!node)
unsigned int hash = interaction_case_hash (iact, c, 0);
struct interaction_value *node = lookup_case (&iap->ivmap, iact, c);
if (!node)
- iap->enc_sum[x - iap->base_df] += bin * iv->cc;
- }
- if (cat->payload && cat->payload->calculate)
- cat->payload->calculate (cat->aux1, cat->aux2, iv->user_data);
- }
+ iap->enc_sum[x - iap->base_df] += bin * iv->cc;
+ }
+ if (cat->payload && cat->payload->calculate)
+ cat->payload->calculate (cat->aux1, cat->aux2, iv->user_data);
+ }
+union value *
+categoricals_get_var_values (const struct categoricals *cat,
+ const struct variable *var, size_t *np)
+{
+ struct variable_node *vn = lookup_variable (&cat->varmap, var);
+ *np = hmap_count (&vn->valmap);
+ if (!vn->values)
+ {
+ vn->values = pool_nalloc (cat->pool, *np, sizeof *vn->values);
+
+ struct value_node *valnd;
+ HMAP_FOR_EACH (valnd, struct value_node, node, &vn->valmap)
+ vn->values[valnd->index] = valnd->val;
+ }
+ return vn->values;
+}
+
+int
+categoricals_get_value_index_by_category_real (const struct categoricals *cat,
+ int iact_idx, int cat_idx,
+ int var_idx)
+{
+ const struct interact_params *iap = &cat->iap[iact_idx];
+ const struct interaction_value *ivn = iap->ivs[cat_idx];
+ const struct variable *var = iap->iact->vars[var_idx];
+ const struct variable_node *vn = iap->varnodes[var_idx];
+ const union value *val = case_data (ivn->ccase, var);
+ int width = var_get_width (var);
+ unsigned int hash = value_hash (val, width, 0);
+ return lookup_value (&vn->valmap, val, hash, width)->index;
+}
+