Reworked very long string support for better encapsulation.
[pspp-builds.git] / src / data / dictionary.c
index 161071ec159a038555da3467ef8586a07a143fa3..bf467440aa7ce294cb4f5a9aa7d0fdfef590d01a 100644 (file)
@@ -59,9 +59,6 @@ struct dictionary
     size_t vector_cnt;          /* Number of vectors. */
   };
 
-/* Active file dictionary. */
-struct dictionary *default_dict;
-
 /* Creates and returns a new dictionary. */
 struct dictionary *
 dict_create (void) 
@@ -270,7 +267,7 @@ dict_create_var (struct dictionary *d, const char *name, int width)
   assert (d != NULL);
   assert (name != NULL);
 
-  assert (width >= 0 && width < 256);
+  assert (width >= 0 && width <= MAX_STRING);
 
   assert (var_is_plausible_name(name,0));
     
@@ -284,7 +281,7 @@ dict_create_var (struct dictionary *d, const char *name, int width)
   v->type = width == 0 ? NUMERIC : ALPHA;
   v->width = width;
   v->fv = d->next_value_idx;
-  v->nv = width == 0 ? 1 : DIV_RND_UP (width, 8);
+  v->nv = width == 0 ? 1 : DIV_RND_UP (width, MAX_SHORT_STRING);
   v->leave = dict_class_from_id (v->name) == DC_SCRATCH;
   v->index = d->var_cnt;
   mv_init (&v->miss, width);
@@ -858,19 +855,44 @@ dict_get_compacted_idx_to_fv (const struct dictionary *d)
 }
 
 /* Returns true if a case for dictionary D would be smaller after
-   compaction, false otherwise.  Compacting a case eliminates
+   compacting, false otherwise.  Compacting a case eliminates
    "holes" between values and after the last value.  Holes are
    created by deleting variables (or by scratch variables).
 
    The return value may differ from whether compacting a case
-   from dictionary D would *change* the case: compaction could
+   from dictionary D would *change* the case: compacting could
    rearrange values even if it didn't reduce space
    requirements. */
 bool
-dict_needs_compaction (const struct dictionary *d) 
+dict_compacting_would_shrink (const struct dictionary *d) 
 {
   return dict_get_compacted_value_cnt (d) < dict_get_next_value_idx (d);
 }
+
+/* Returns true if a case for dictionary D would be smaller after
+   compacting, false otherwise.  Compacting a case eliminates
+   "holes" between values and after the last value.  Holes are
+   created by deleting variables (or by scratch variables).
+
+   The return value may differ from whether compacting a case
+   from dictionary D would *shrink* the case: compacting could
+   rearrange values without reducing space requirements. */
+bool
+dict_compacting_would_change (const struct dictionary *d) 
+{
+  size_t case_idx;
+  size_t i;
+
+  case_idx = 0;
+  for (i = 0; i < dict_get_var_cnt (d); i++) 
+    {
+      struct variable *v = dict_get_var (d, i);
+      if (v->fv != case_idx)
+        return true;
+      case_idx += v->nv;
+    }
+  return false;
+}
 \f
 /* How to copy a contiguous range of values between cases. */
 struct copy_map