[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug37999 02/11] subcase: New function subcase_add_vars_always().
From: |
Ben Pfaff |
Subject: |
[bug37999 02/11] subcase: New function subcase_add_vars_always(). |
Date: |
Thu, 31 Jan 2013 22:03:24 -0800 |
This function will be used in an upcoming commit.
---
src/data/subcase.c | 37 ++++++++++++++++++++++++-------------
src/data/subcase.h | 2 ++
2 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/src/data/subcase.c b/src/data/subcase.c
index f87093c..d7f2780 100644
--- a/src/data/subcase.c
+++ b/src/data/subcase.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009, 2011, 2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -43,18 +43,8 @@ void
subcase_init_vars (struct subcase *sc,
const struct variable *const *vars, size_t n_vars)
{
- size_t i;
-
- sc->fields = xnmalloc (n_vars, sizeof *sc->fields);
- sc->n_fields = n_vars;
- sc->proto = NULL;
- for (i = 0; i < n_vars; i++)
- {
- struct subcase_field *field = &sc->fields[i];
- field->case_index = var_get_case_index (vars[i]);
- field->width = var_get_width (vars[i]);
- field->direction = SC_ASCEND;
- }
+ subcase_init_empty (sc);
+ subcase_add_vars_always (sc, vars, n_vars);
}
/* Initializes SC as a subcase with a single field extracted
@@ -166,6 +156,27 @@ subcase_add_var_always (struct subcase *sc, const struct
variable *var,
var_get_width (var), direction);
}
+/* Add a field for each of the N_VARS variables in VAR to SC, regardless of
+ whether each variable already has a field in SC. The fields are added with
+ ascending direction. */
+void
+subcase_add_vars_always (struct subcase *sc,
+ const struct variable *const *vars, size_t n_vars)
+{
+ size_t i;
+
+ sc->fields = xnrealloc (sc->fields,
+ sc->n_fields + n_vars, sizeof *sc->fields);
+ for (i = 0; i < n_vars; i++)
+ {
+ struct subcase_field *field = &sc->fields[sc->n_fields++];
+ field->case_index = var_get_case_index (vars[i]);
+ field->width = var_get_width (vars[i]);
+ field->direction = SC_ASCEND;
+ }
+ invalidate_proto (sc);
+}
+
/* Add a field for CASE_INDEX, WIDTH to SC, with DIRECTION as the
sort order, regardless of whether CASE_INDEX already has a
field in SC. */
diff --git a/src/data/subcase.h b/src/data/subcase.h
index 71bf6fd..f890f25 100644
--- a/src/data/subcase.h
+++ b/src/data/subcase.h
@@ -72,6 +72,8 @@ void subcase_add_always (struct subcase *sc, int case_index,
int width,
enum subcase_direction direction);
void subcase_add_var_always (struct subcase *, const struct variable *,
enum subcase_direction);
+void subcase_add_vars_always (struct subcase *,
+ const struct variable *const *, size_t n_vars);
void subcase_add_proto_always (struct subcase *, const struct caseproto *);
const struct caseproto *subcase_get_proto (const struct subcase *);
--
1.7.10.4
- [bug37999 00/11] Make RANK work with TEMPORARY., Ben Pfaff, 2013/02/01
- [bug37999 01/11] casegrouper: Add comments., Ben Pfaff, 2013/02/01
- [bug37999 04/11] RANK: Lowercase the name of "enum RANK_FUNC"., Ben Pfaff, 2013/02/01
- [bug37999 05/11] RANK: Remove write-only struct member 'ascending'., Ben Pfaff, 2013/02/01
- [bug37999 03/11] transformations: Relax the rules for transformation finalizing., Ben Pfaff, 2013/02/01
- [bug37999 06/11] RANK: Put #include directives into typical order., Ben Pfaff, 2013/02/01
- [bug37999 02/11] subcase: New function subcase_add_vars_always().,
Ben Pfaff <=
- [bug37999 07/11] RANK: Simplify fraction_name() function., Ben Pfaff, 2013/02/01
- [bug37999 08/11] RANK: Simplify rank_sorted_file() with new function sum_weights()., Ben Pfaff, 2013/02/01
- [bug37999 09/11] RANK: Create all variables together, in order., Ben Pfaff, 2013/02/01
- [bug37999 11/11] RANK: Add support for temporary transformations., Ben Pfaff, 2013/02/01
- [bug37999 10/11] RANK: Adopt a new ranking implementation., Ben Pfaff, 2013/02/01