From: John Darrington Date: Thu, 11 Jun 2009 04:57:17 +0000 (+0800) Subject: Add check that input to casereader_create_distinct are sorted X-Git-Tag: build37~50^2~19 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ad29da8225568e97bd066d8d530b1f9b81aa70c;p=pspp-builds.git Add check that input to casereader_create_distinct are sorted --- diff --git a/src/data/casereader-translator.c b/src/data/casereader-translator.c index 62b38b99..e3c764cd 100644 --- a/src/data/casereader-translator.c +++ b/src/data/casereader-translator.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -371,6 +372,7 @@ struct consolodator casenumber n; struct casereader *clone; struct caseproto *proto; + int direction; }; static bool @@ -381,17 +383,23 @@ uniquify (const struct ccase *c, void *aux) const int key_width = var_get_width (cdr->key); const double weight = cdr->weight ? case_data (c, cdr->weight)->f : 1.0; const struct ccase *next_case = casereader_peek (cdr->clone, cdr->n + 1); + int dir = 0; cdr->n ++; cdr->cc += weight; if ( NULL == next_case) goto end; - - if ( 0 != value_compare_3way (case_data (next_case, cdr->key), - current_value, key_width)) - goto end; - + + dir = value_compare_3way (case_data (next_case, cdr->key), + current_value, key_width); + if ( dir != 0 ) + { + /* Insist that the data are sorted */ + assert (cdr->direction == 0 || dir == cdr->direction); + cdr->direction = dir; + goto end; + } return false; @@ -449,7 +457,7 @@ casereader_create_distinct (struct casereader *input, { struct casereader *u ; struct casereader *ud ; - struct caseproto *output_proto = casereader_get_proto (input); + const struct caseproto *output_proto = casereader_get_proto (input); struct consolodator *cdr = xmalloc (sizeof (*cdr)); cdr->n = 0; @@ -457,6 +465,7 @@ casereader_create_distinct (struct casereader *input, cdr->weight = weight; cdr->cc = 0; cdr->clone = casereader_clone (input); + cdr->direction = 0; if ( NULL == cdr->weight ) output_proto = caseproto_add_width (output_proto, 0);