X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fmatrix-data.c;h=986186ab9c0f54264ad3b34b609d66332b1f3a8f;hb=2ed139f9baf695edf0300f272a31d3ef98038521;hp=5e4d5f5d70ad16d20cda547464adff255866db80;hpb=4944c86a9318bc5b5578ab145a95c116ffd2c9fd;p=pspp diff --git a/src/matrix-data.c b/src/matrix-data.c index 5e4d5f5d70..986186ab9c 100644 --- a/src/matrix-data.c +++ b/src/matrix-data.c @@ -39,6 +39,7 @@ char *alloca (); #include #include #include +#include "algorithm.h" #include "alloc.h" #include "command.h" #include "data-in.h" @@ -52,8 +53,6 @@ char *alloca (); #include "var.h" #include "vfm.h" -#undef DEBUGGING -/*#define DEBUGGING 1*/ #include "debug-print.h" /* FIXME: /N subcommand not implemented. It should be pretty simple, @@ -682,14 +681,17 @@ string_to_content_type (char *s, int *collide) /* Compare two variables using p.mxd.vartype and p.mxd.subtype fields. */ static int -compare_variables_by_mxd_vartype (const void *pa, const void *pb) +compare_variables_by_mxd_vartype (const void *a_, const void *b_) { - struct matrix_data_proc *a = &(*((struct variable **) pa))->p.mxd; - struct matrix_data_proc *b = &(*((struct variable **) pb))->p.mxd; - - return (a->vartype != b->vartype - ? a->vartype - b->vartype - : a->subtype - b->subtype); + struct variable *const *pa = a_; + struct variable *const *pb = b_; + const struct matrix_data_proc *a = &(*pa)->p.mxd; + const struct matrix_data_proc *b = &(*pb)->p.mxd; + + if (a->vartype != b->vartype) + return a->vartype > b->vartype ? 1 : -1; + else + return a->subtype < b->subtype ? -1 : a->subtype > b->subtype; } #if DEBUGGING @@ -1640,29 +1642,39 @@ wr_read_splits (void) return 1; } -/* Return strcmp()-type comparison of the n_factors factors at _A and - _B. Sort missing values toward the end. */ +/* Compares doubles A and B, treating SYSMIS as greatest. */ static int -compare_factors (const void *pa, const void *pb) +compare_doubles (const void *a_, const void *b_, void *aux unused) { - const double *a = (*(struct factor_data **) pa)->factors; - const double *b = (*(struct factor_data **) pb)->factors; - int i; + const double *a = a_; + const double *b = b_; - for (i = 0; i < n_factors; i++, a++, b++) - { - if (*a == *b) - continue; - - if (*a == SYSMIS) - return 1; - else if (*b == SYSMIS) - return -1; - else - return *a - *b < 0 ? -1 : 1; - } + if (*a == *b) + return 0; + else if (*a == SYSMIS) + return 1; + else if (*b == SYSMIS) + return -1; + else if (*a > *b) + return 1; + else + return -1; +} - return 0; +/* Return strcmp()-type comparison of the n_factors factors at _A and + _B. Sort missing values toward the end. */ +static int +compare_factors (const void *a_, const void *b_) +{ + struct factor_data *const *pa = a_; + struct factor_data *const *pb = b_; + const double *a = (*pa)->factors; + const double *b = (*pb)->factors; + + return lexicographical_compare (a, n_factors, + b, n_factors, + sizeof *a, + compare_doubles, NULL); } /* Write out the data for the current split file to the active