- struct variable *v = dict_get_var (d, i);
- int *src_fv = xmalloc (sizeof *src_fv);
- *src_fv = var_get_case_index (v);
- var_attach_aux (v, src_fv, var_dtor_free);
+ const struct variable *var = dict_get_var (dict, i);
+ struct stage_var *stage_var;
+
+ stage_var = xmalloc (sizeof *stage_var);
+ stage_var->var = var;
+ stage_var->case_index = var_get_case_index (var);
+ hmap_insert (&stage->stage_vars, &stage_var->hmap_node,
+ hash_pointer (var, 0));
+ }
+
+ return stage;
+}
+
+/* Destroys STAGE, which was created by case_map_stage_create(). */
+void
+case_map_stage_destroy (struct case_map_stage *stage)
+{
+ if (stage != NULL)
+ {
+ struct stage_var *stage_var, *next_stage_var;
+
+ HMAP_FOR_EACH_SAFE (stage_var, next_stage_var,
+ struct stage_var, hmap_node, &stage->stage_vars)
+ {
+ hmap_delete (&stage->stage_vars, &stage_var->hmap_node);
+ free (stage_var);
+ }
+ hmap_destroy (&stage->stage_vars);
+ free (stage);