From: Ben Pfaff Date: Sat, 4 Mar 2023 01:31:36 +0000 (-0800) Subject: dictionary: Get rid of next_value_idx. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2891092322c530609ebfc132b6d0e62f515946db;p=pspp dictionary: Get rid of next_value_idx. At this point, it was always the number of variables in the dictionary. --- diff --git a/src/data/dataset-writer.c b/src/data/dataset-writer.c index 5d14203d3d..011deed39d 100644 --- a/src/data/dataset-writer.c +++ b/src/data/dataset-writer.c @@ -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); diff --git a/src/data/dataset.c b/src/data/dataset.c index 9503521207..063a4a4251 100644 --- a/src/data/dataset.c +++ b/src/data/dataset.c @@ -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); diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 7a4d094e78..23a07ae586 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -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) { diff --git a/src/data/dictionary.h b/src/data/dictionary.h index 9a4e8bf1c9..092a2b23e8 100644 --- a/src/data/dictionary.h +++ b/src/data/dictionary.h @@ -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). */ diff --git a/src/language/commands/inpt-pgm.c b/src/language/commands/inpt-pgm.c index b5bd041d79..f6beea1f54 100644 --- a/src/language/commands/inpt-pgm.c +++ b/src/language/commands/inpt-pgm.c @@ -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); diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index c93a39fd40..598e278669 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -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 * diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 5ba4246ac7..22be052f30 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -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); diff --git a/src/ui/gui/psppire-dict.h b/src/ui/gui/psppire-dict.h index e5f8032965..9d593a913f 100644 --- a/src/ui/gui/psppire-dict.h +++ b/src/ui/gui/psppire-dict.h @@ -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);