Corrected spelling of "consolidate".
[pspp-builds.git] / src / data / casereader-translator.c
index 62b38b99a6c07114bcb4159caa23c35060cbd078..a2963980253790dd5f398cf20fd44420350c26d3 100644 (file)
@@ -19,6 +19,7 @@
 #include <data/casereader.h>
 #include <stdlib.h>
 
+#include <data/variable.h>
 #include <data/casereader-provider.h>
 #include <libpspp/taint.h>
 
@@ -361,7 +362,7 @@ car_translate (struct ccase *input, void *car_)
 
 \f
 
-struct consolodator
+struct consolidator
 {
   const struct variable *key;
   const struct variable *weight;
@@ -371,27 +372,34 @@ struct consolodator
   casenumber n;
   struct casereader *clone;
   struct caseproto *proto;
+  int direction;
 };
 
 static bool
 uniquify (const struct ccase *c, void *aux)
 {
-  struct consolodator *cdr = aux;
+  struct consolidator *cdr = aux;
   const union value *current_value = case_data (c, cdr->key);
   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;
 
@@ -406,7 +414,7 @@ uniquify (const struct ccase *c, void *aux)
 static struct ccase *
 consolodate_weight (struct ccase *input, void *aux)
 {
-  struct consolodator *cdr = aux;
+  struct consolidator *cdr = aux;
   struct ccase *c;
 
   c = case_unshare_and_resize (input, cdr->proto);
@@ -423,7 +431,7 @@ consolodate_weight (struct ccase *input, void *aux)
 static bool
 uniquify_destroy (void *aux)
 {
-  struct consolodator *cdr = aux;
+  struct consolidator *cdr = aux;
 
   casereader_destroy (cdr->clone);
   free (cdr);
@@ -449,14 +457,15 @@ 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));
+  struct consolidator *cdr = xmalloc (sizeof (*cdr));
   cdr->n = 0;
   cdr->key = key;
   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);