It's nasty and doesn't conform to the usual invariants.
}
-\f
-/* Dictionary used to contain "internal variables". */
-static struct dictionary *internal_dict;
-
-/* Create a variable of the specified WIDTH to be used for internal
- calculations only. The variable is assigned case index CASE_IDX. */
-struct variable *
-dict_create_internal_var (int case_idx, int width)
-{
- if (internal_dict == NULL)
- internal_dict = dict_create ("UTF-8");
-
- for (;;)
- {
- static int counter = INT_MAX / 2;
- struct variable *var;
- char name[64];
-
- if (++counter == INT_MAX)
- counter = INT_MAX / 2;
-
- sprintf (name, "$internal%d", counter);
- var = dict_create_var (internal_dict, name, width);
- if (var != NULL)
- {
- set_var_case_index (var, case_idx);
- return var;
- }
- }
-}
-
-/* Destroys VAR, which must have been created with
- dict_create_internal_var(). */
-void
-dict_destroy_internal_var (struct variable *var)
-{
- if (var != NULL)
- {
- dict_delete_var (internal_dict, var);
-
- /* Destroy internal_dict if it has no variables left, just so that
- valgrind --leak-check --show-reachable won't show internal_dict. */
- if (dict_get_n_vars (internal_dict) == 0)
- {
- dict_unref (internal_dict);
- internal_dict = NULL;
- }
- }
-}
\f
int
vardict_get_dict_index (const struct vardict_info *vardict)
WARN_UNUSED_RESULT;
bool dict_id_is_valid (const struct dictionary *, const char *id);
-/* Internal variables. */
-struct variable *dict_create_internal_var (int case_idx, int width);
-void dict_destroy_internal_var (struct variable *);
-
/* Functions to be called upon dictionary changes. */
struct dict_callbacks
{
bool saw_missing;
struct moments1 *moments;
+ struct dictionary *dict;
struct variable *subject;
struct variable *weight;
struct casewriter *writer;
if (av->function == AGRF_SD)
moments1_destroy (av->moments);
- dict_destroy_internal_var (av->subject);
- dict_destroy_internal_var (av->weight);
+ dict_unref (av->dict);
}
free (agr->agr_vars);
if (agr->dict != NULL)
proto = caseproto_add_width (proto, 0);
proto = caseproto_add_width (proto, 0);
+ if (!av->dict)
+ av->dict = dict_create ("UTF-8");
if (! av->subject)
- av->subject = dict_create_internal_var (0, 0);
-
+ av->subject = dict_create_var (av->dict, "subject", 0);
if (! av->weight)
- av->weight = dict_create_internal_var (1, 0);
+ av->weight = dict_create_var (av->dict, "weight", 0);
struct subcase ordering;
subcase_init_var (&ordering, av->subject, SC_ASCEND);
struct wilcoxon_state *ws = XCALLOC (t2s->n_pairs, struct wilcoxon_state);
const struct variable *weight = dict_get_weight (dict);
- struct variable *weightx = dict_create_internal_var (WEIGHT_IDX, 0);
struct caseproto *proto;
input =
struct subcase ordering;
variable_pair *vp = &t2s->pairs[i];
- ws[i].sign = dict_create_internal_var (0, 0);
- ws[i].absdiff = dict_create_internal_var (1, 0);
+ ws[i].dict = dict_create ("UTF-8");
+ ws[i].sign = dict_create_var (ws[i].dict, "sign", 0);
+ ws[i].absdiff = dict_create_var (ws[i].dict, "absdiff", 0);
+ ws[i].weight = dict_create_var (ws[i].dict, "weight", 0);
r = casereader_create_filter_missing (r, *vp, 2,
exclude,
*case_num_rw (output, ws[i].absdiff) = fabs (d);
if (weight)
- *case_num_rw (output, weightx) = case_num (c, weight);
+ *case_num_rw (output, ws[i].weight) = case_num (c, weight);
casewriter_write (writer, output);
}
enum rank_error err = 0;
rr = casereader_create_append_rank (ws[i].reader, ws[i].absdiff,
- weight ? weightx : NULL, &err,
+ weight ? ws[i].weight : NULL, &err,
distinct_callback, &ws[i]
);
{
double sign = case_num (c, ws[i].sign);
double rank = case_num_idx (c, weight ? 3 : 2);
- double w = weight ? case_num (c, weightx) : 1.0;
+ double w = weight ? case_num (c, ws[i].weight) : 1.0;
if (sign > 0)
{
casereader_destroy (input);
- dict_destroy_internal_var (weightx);
-
show_ranks_box (ws, t2s, dict);
show_tests_box (ws, t2s, exact, timer);
for (i = 0 ; i < t2s->n_pairs; ++i)
- {
- dict_destroy_internal_var (ws[i].sign);
- dict_destroy_internal_var (ws[i].absdiff);
- }
+ dict_unref (ws[i].dict);
free (ws);
}
struct wilcoxon_state
{
struct casereader *reader;
+
+ struct dictionary *dict;
struct variable *sign;
struct variable *absdiff;
+ struct variable *weight;
struct rank_sum positives;
struct rank_sum negatives;