From: John Darrington Date: Mon, 15 Jun 2009 23:27:31 +0000 (+0800) Subject: Add new functions to define subcase orderings. X-Git-Tag: build37~50^2~16 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=2fe0749f0892964767cefadb5fac1c9784e9df84 Add new functions to define subcase orderings. Allow subcases to be defined from a index and width, rather from a variable. This avoids much of the need for var_create_internal. --- diff --git a/src/data/subcase.c b/src/data/subcase.c index be586096..6ffaa4c2 100644 --- a/src/data/subcase.c +++ b/src/data/subcase.c @@ -64,6 +64,16 @@ subcase_init_var (struct subcase *sc, const struct variable *var, subcase_add_var (sc, var, direction); } + +void +subcase_init (struct subcase *sc, int index, int width, + enum subcase_direction direction) +{ + subcase_init_empty (sc); + subcase_add (sc, index, width, direction); +} + + /* Removes all the fields from SC. */ void subcase_clear (struct subcase *sc) @@ -89,6 +99,7 @@ subcase_destroy (struct subcase *sc) caseproto_unref (sc->proto); } + /* Add a field for VAR to SC, with DIRECTION as the sort order. Returns true if successful, false if VAR already has a field in SC. */ @@ -96,7 +107,17 @@ bool subcase_add_var (struct subcase *sc, const struct variable *var, enum subcase_direction direction) { - size_t case_index = var_get_case_index (var); + return subcase_add (sc, var_get_case_index (var), + var_get_width (var), direction); +} + +/* Add a field for CASE_INDEX, WIDTH to SC, with DIRECTION as the sort order. + Returns true if successful, false if CASE_INDEX already has a field + in SC. */ +bool +subcase_add (struct subcase *sc, int case_index, int width, + enum subcase_direction direction) +{ struct subcase_field *field; size_t i; @@ -107,7 +128,7 @@ subcase_add_var (struct subcase *sc, const struct variable *var, sc->fields = xnrealloc (sc->fields, sc->n_fields + 1, sizeof *sc->fields); field = &sc->fields[sc->n_fields++]; field->case_index = case_index; - field->width = var_get_width (var); + field->width = width; field->direction = direction; invalidate_proto (sc); return true; diff --git a/src/data/subcase.h b/src/data/subcase.h index 050cf17d..6e59da1d 100644 --- a/src/data/subcase.h +++ b/src/data/subcase.h @@ -53,10 +53,16 @@ void subcase_init_vars (struct subcase *, const struct variable *const *, size_t n_vars); void subcase_init_var (struct subcase *, const struct variable *, enum subcase_direction); +void subcase_init (struct subcase *, int index, int width, + enum subcase_direction); + void subcase_clone (struct subcase *, const struct subcase *); void subcase_clear (struct subcase *); void subcase_destroy (struct subcase *); +bool subcase_add (struct subcase *sc, int index, int width, + enum subcase_direction direction); + bool subcase_add_var (struct subcase *, const struct variable *, enum subcase_direction); diff --git a/src/language/stats/roc.c b/src/language/stats/roc.c index 3dff0407..eae528a3 100644 --- a/src/language/stats/roc.c +++ b/src/language/stats/roc.c @@ -560,8 +560,7 @@ do_roc (struct cmd_roc *roc, struct casereader *input, struct dictionary *dict) struct caseproto *proto = caseproto_create (); struct subcase ordering; - struct variable *iv = var_create_internal (CUTPOINT); - subcase_init_var (&ordering, iv, SC_ASCEND); + subcase_init (&ordering, CUTPOINT, 0, SC_ASCEND); proto = caseproto_add_width (proto, 0); /* cutpoint */