X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fcasefilter.c;h=fb23e4f674ad104c547d439d64b50dc1c4d7530e;hb=44326932c8227c64a87f7a92ef16ce83c2fba2d4;hp=d88af50a565f52e29f4cce396bdd6684c9159bb5;hpb=f43378497b8400e9c22a3485c534693dc1bc9554;p=pspp-builds.git diff --git a/src/data/casefilter.c b/src/data/casefilter.c index d88af50a..fb23e4f6 100644 --- a/src/data/casefilter.c +++ b/src/data/casefilter.c @@ -1,6 +1,5 @@ /* PSPP - computes sample statistics. Copyright (C) 2006 Free Software Foundation, Inc. - Written by John Darrington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -28,9 +27,9 @@ #include #include -struct casefilter +struct casefilter { - bool exclude_user_missing; + enum mv_class class; const struct variable **vars; int n_vars; @@ -38,12 +37,12 @@ struct casefilter /* Returns true iff the entire case should be skipped */ -bool +bool casefilter_skip_case (const struct casefilter *filter, const struct ccase *c) { int i; - for (i = 0; i < filter->n_vars; ++i) + for (i = 0; i < filter->n_vars; ++i) { if ( casefilter_variable_missing (filter, c, filter->vars[i])) return true; @@ -53,39 +52,30 @@ casefilter_skip_case (const struct casefilter *filter, const struct ccase *c) } /* Returns true iff the variable V in case C is missing */ -bool -casefilter_variable_missing (const struct casefilter *filter, - const struct ccase *c, +bool +casefilter_variable_missing (const struct casefilter *filter, + const struct ccase *c, const struct variable *var) { - const union value *val = case_data (c, var->fv) ; - - if ( val->f == SYSMIS ) - return true; - - if ( filter->exclude_user_missing && - mv_is_value_user_missing (&var->miss, val) ) - return true; - - return false; + const union value *val = case_data (c, var) ; + return var_is_value_missing (var, val, filter->class); } -/* Create a new casefilter. - If EXCL is true, then the filter user missing values to be missing, - otherwise they are considered at their face value. +/* Create a new casefilter that drops cases in which any of the + N_VARS variables in VARS are in the given CLASS of missing values. VARS is an array of variables which if *any* of them are missing. N_VARS is the size of VARS. */ -struct casefilter * -casefilter_create (bool excl, struct variable **vars, int n_vars) +struct casefilter * +casefilter_create (enum mv_class class, struct variable **vars, int n_vars) { int i; struct casefilter * filter = xmalloc (sizeof (*filter)) ; - filter->exclude_user_missing = excl ; + filter->class = class; filter->vars = xnmalloc (n_vars, sizeof (*filter->vars) ); - for ( i = 0 ; i < n_vars ; ++i ) + for ( i = 0 ; i < n_vars ; ++i ) filter->vars[i] = vars[i]; filter->n_vars = n_vars ; @@ -96,27 +86,25 @@ casefilter_create (bool excl, struct variable **vars, int n_vars) /* Add the variables in VARS to the list of variables for which the filter considers. N_VARS is the size of VARS */ -void -casefilter_add_variables (struct casefilter *filter, - struct variable **vars, int n_vars) +void +casefilter_add_variables (struct casefilter *filter, + struct variable *const *vars, int n_vars) { int i; filter->vars = xnrealloc (filter->vars, filter->n_vars + n_vars, sizeof (*filter->vars) ); - - for ( i = 0 ; i < n_vars ; ++i ) + + for ( i = 0 ; i < n_vars ; ++i ) filter->vars[i + filter->n_vars] = vars[i]; filter->n_vars += n_vars ; } /* Destroy the filter FILTER */ -void +void casefilter_destroy (struct casefilter *filter) { free (filter->vars); free (filter); } - -