dictionary: Get rid of next_value_idx.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 4 Mar 2023 01:31:36 +0000 (17:31 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 5 Mar 2023 19:23:16 +0000 (11:23 -0800)
At this point, it was always the number of variables in the dictionary.

src/data/dataset-writer.c
src/data/dataset.c
src/data/dictionary.c
src/data/dictionary.h
src/language/commands/inpt-pgm.c
src/ui/gui/psppire-data-store.c
src/ui/gui/psppire-dict.c
src/ui/gui/psppire-dict.h

index 5d14203d3d9354fa664eb19ffc42245f91e5d0a5..011deed39d3cc5ef0e9e33058766c9bd4e378808 100644 (file)
@@ -74,8 +74,7 @@ dataset_writer_open (struct file_handle *fh,
 
   writer->dict = dict_clone (dictionary);
   dict_delete_scratch_vars (writer->dict);
-  if (dict_count_values (writer->dict, 0)
-      < dict_get_next_value_idx (writer->dict))
+  if (dict_count_values (writer->dict, 0) < dict_get_n_vars (writer->dict))
     {
       writer->compactor = case_map_to_compact_dict (writer->dict, 0);
       dict_compact_values (writer->dict);
index 9503521207c0fd78a5bbbc2fc18a9c55a579da53..063a4a425184ff1c6c35c06717c1552d83177e58 100644 (file)
@@ -474,7 +474,8 @@ proc_open_filtering (struct dataset *ds, bool filter)
     {
       struct dictionary *pd = ds->permanent_dict;
       size_t compacted_n_values = dict_count_values (pd, DC_SCRATCH);
-      if (compacted_n_values < dict_get_next_value_idx (pd))
+      assert (dict_count_values (pd, 0) == dict_get_n_vars (pd));
+      if (compacted_n_values < dict_get_n_vars (pd))
         {
           struct caseproto *compacted_proto;
           compacted_proto = dict_get_compacted_proto (pd, DC_SCRATCH);
index 7a4d094e78994d45f81cfa14836b4dd2e4e85f7b..23a07ae5863fbeecda6e804c1b97487787b5e982 100644 (file)
@@ -65,7 +65,6 @@ struct dictionary
     struct caseproto *proto;    /* Prototype for dictionary cases
                                    (updated lazily). */
     struct hmap name_map;      /* Variable index by name. */
-    int next_value_idx;         /* Index of next `union value' to allocate. */
     const struct variable **split;    /* SPLIT FILE vars. */
     size_t n_splits;            /* SPLIT FILE count. */
     enum split_type split_type;
@@ -293,12 +292,6 @@ dict_create (const char *encoding)
 /* Creates and returns a (deep) copy of an existing
    dictionary.
 
-   The new dictionary's case indexes are copied from the old
-   dictionary.  If the new dictionary won't be used to access
-   cases produced with the old dictionary, then the new
-   dictionary's case indexes should be compacted with
-   dict_compact_values to save space.
-
    Callbacks are not cloned. */
 struct dictionary *
 dict_clone (const struct dictionary *s)
@@ -317,8 +310,6 @@ dict_clone (const struct dictionary *s)
       var_get_vardict (dv)->case_index = var_get_vardict (sv)->case_index;
     }
 
-  d->next_value_idx = s->next_value_idx;
-
   d->n_splits = s->n_splits;
   if (d->n_splits > 0)
     {
@@ -665,7 +656,6 @@ dict_clear__ (struct dictionary *d, bool skip_callbacks)
   d->n_vars = d->allocated_vars = 0;
   invalidate_proto (d);
   hmap_clear (&d->name_map);
-  d->next_value_idx = 0;
   dict_set_split_vars__ (d, NULL, 0, SPLIT_NONE, skip_callbacks);
 
   if (skip_callbacks)
@@ -799,8 +789,6 @@ add_var_with_case_index (struct dictionary *d, struct variable *v,
 {
   struct vardict_info *vardict;
 
-  assert (case_index >= d->next_value_idx);
-
   /* Update dictionary. */
   if (d->n_vars >= d->allocated_vars)
     {
@@ -829,7 +817,6 @@ add_var_with_case_index (struct dictionary *d, struct variable *v,
     d->callbacks->var_added (d, var_get_dict_index (v), d->cb_data);
 
   invalidate_proto (d);
-  d->next_value_idx = case_index + 1;
 
   return v;
 }
@@ -837,7 +824,7 @@ add_var_with_case_index (struct dictionary *d, struct variable *v,
 static struct variable *
 add_var (struct dictionary *d, struct variable *v)
 {
-  return add_var_with_case_index (d, v, d->next_value_idx);
+  return add_var_with_case_index (d, v, dict_get_n_vars (d));
 }
 
 /* Creates and returns a new variable in D with the given NAME
@@ -1418,35 +1405,15 @@ dict_get_proto (const struct dictionary *d_)
   return d->proto;
 }
 
-/* Returns the case index of the next value to be added to D.
-   This value is the number of `union value's that need to be
-   allocated to store a case for dictionary D. */
-int
-dict_get_next_value_idx (const struct dictionary *d)
-{
-  return d->next_value_idx;
-}
-
-/* Returns the number of bytes needed to store a case for
-   dictionary D. */
-size_t
-dict_get_case_size (const struct dictionary *d)
-{
-  return sizeof (union value) * dict_get_next_value_idx (d);
-}
-
 /* Reassigns values in dictionary D so that fragmentation is
    eliminated. */
 void
 dict_compact_values (struct dictionary *d)
 {
-  size_t i;
-
-  d->next_value_idx = 0;
-  for (i = 0; i < d->n_vars; i++)
+  for (size_t i = 0; i < d->n_vars; i++)
     {
       struct variable *v = d->vars[i].var;
-      set_var_case_index (v, d->next_value_idx++);
+      set_var_case_index (v, i);
     }
   invalidate_proto (d);
 }
@@ -1454,12 +1421,7 @@ dict_compact_values (struct dictionary *d)
 /* Returns the number of values occupied by the variables in
    dictionary D.  All variables are considered if EXCLUDE_CLASSES
    is 0, or it may contain one or more of DC_ORDINARY, DC_SYSTEM,
-   or DC_SCRATCH to exclude the corresponding type of variable.
-
-   The return value may be less than the number of values in one
-   of dictionary D's cases (as returned by
-   dict_get_next_value_idx) even if E is 0, because there may be
-   gaps in D's cases due to deleted variables. */
+   or DC_SCRATCH to exclude the corresponding type of variable. */
 size_t
 dict_count_values (const struct dictionary *d, unsigned int exclude_classes)
 {
index 9a4e8bf1c9c8f8f881dc1acf4864d328ee60a7c2..092a2b23e805baeac5c6494be8904a180498b1cd 100644 (file)
@@ -114,8 +114,6 @@ void dict_set_case_limit (struct dictionary *, casenumber);
 
 /* Size of cases for this dictionary. */
 const struct caseproto *dict_get_proto (const struct dictionary *);
-int dict_get_next_value_idx (const struct dictionary *);
-size_t dict_get_case_size (const struct dictionary *);
 
 /* Making this dictionary's cases smaller (if some variables were
    deleted). */
index b5bd041d79ffa2d81201113333688743c3080c5b..f6beea1f54aae6244f4aad80767440e8a0f0eb96 100644 (file)
@@ -149,7 +149,7 @@ cmd_input_program (struct lexer *lexer, struct dataset *ds)
       msg_location_destroy (location);
       return CMD_FAILURE;
     }
-  if (dict_get_next_value_idx (dataset_dict (inp->ds)) == 0)
+  if (dict_get_n_vars (dataset_dict (inp->ds)) == 0)
     {
       msg_at (SE, location, _("Input program did not create any variables."));
       destroy_input_program (inp);
index c93a39fd40f7e390f03d1cf70339a18fcd9d6180..598e2786690051b650f4355eaa3104a6737ed3c2 100644 (file)
@@ -332,7 +332,7 @@ psppire_data_store_get_case_count (const PsppireDataStore *store)
 size_t
 psppire_data_store_get_value_count (const PsppireDataStore *store)
 {
-  return psppire_dict_get_n_values (store->dict);
+  return psppire_dict_get_n_vars (store->dict);
 }
 
 const struct caseproto *
index 5ba4246ac78417f769206cfc5fc5862351d30c26..22be052f308964dc571f10da38cd9dc0bacd6c09 100644 (file)
@@ -501,17 +501,6 @@ psppire_dict_get_n_vars (const PsppireDict *d)
 }
 
 
-/* Return the number of `union value's in the dictionary */
-size_t
-psppire_dict_get_n_values (const PsppireDict *d)
-{
-  g_return_val_if_fail (d, -1);
-  g_return_val_if_fail (d->dict, -1);
-
-  return dict_get_next_value_idx (d->dict);
-}
-
-
 /* Returns the prototype for the cases that match the dictionary */
 const struct caseproto *
 psppire_dict_get_proto (const PsppireDict *d)
@@ -559,13 +548,6 @@ psppire_dict_check_name (const PsppireDict *dict,
           && !psppire_dict_lookup_var (dict, name));
 }
 
-gint
-psppire_dict_get_next_value_idx (const PsppireDict *dict)
-{
-  return dict_get_next_value_idx (dict->dict);
-}
-
-
 /* Tree Model Stuff */
 
 static GtkTreeModelFlags tree_model_get_flags (GtkTreeModel *model);
index e5f803296501f1cc7ba9449e7b153eb27282c313..9d593a913ffc5d3f218cb4ac907adcd840df692c 100644 (file)
@@ -83,9 +83,6 @@ void           psppire_dict_delete_var (PsppireDict *s, gint idx);
 /* Return the number of variables in the dictionary */
 gint psppire_dict_get_n_vars (const PsppireDict *d);
 
-/* Return the number of `union value's in the dictionary */
-size_t psppire_dict_get_n_values (const PsppireDict *d);
-
 /* Returns the prototype for the cases that match the dictionary */
 const struct caseproto *psppire_dict_get_proto (const PsppireDict *d);
 
@@ -111,8 +108,6 @@ gboolean psppire_dict_check_name (const PsppireDict *, const gchar *name);
 
 bool psppire_dict_generate_name (const PsppireDict *, char *name, size_t size);
 
-gint psppire_dict_get_next_value_idx (const PsppireDict *dict);
-
 gboolean psppire_dict_rename_var (PsppireDict *dict, struct variable *v,
                              const gchar *text);