+/* Compares two double pointers to variables, which should point
+ to elements of a struct dictionary's `var' member array. */
+static int
+compare_var_ptrs (const void *a_, const void *b_, const void *aux UNUSED)
+{
+ struct variable *const *a = a_;
+ struct variable *const *b = b_;
+
+ return *a < *b ? -1 : *a > *b;
+}
+
+static void
+unindex_var (struct dictionary *d, struct vardict_info *vardict)
+{
+ hmap_delete (&d->name_map, &vardict->name_node);
+}
+
+/* This function assumes that vardict->name_node.hash is valid, that is, that
+ its name has not changed since it was hashed (rename_var() updates this
+ hash along with the name itself). */
+static void
+reindex_var (struct dictionary *d, struct vardict_info *vardict, bool skip_callbacks)
+{
+ struct variable *old = (d->callbacks && d->callbacks->var_changed
+ ? var_clone (vardict->var)
+ : NULL);
+
+ struct variable *var = vardict->var;
+ var_set_vardict (var, vardict);
+ hmap_insert_fast (&d->name_map, &vardict->name_node,
+ vardict->name_node.hash);
+
+ if (! skip_callbacks)
+ {
+ if (d->changed) d->changed (d, d->changed_data);
+ if (old)
+ {
+ d->callbacks->var_changed (d, var_get_dict_index (var), VAR_TRAIT_POSITION, old, d->cb_data);
+ var_unref (old);
+ }
+ }
+}
+
+/* Sets the case_index in V's vardict to CASE_INDEX. */
+static void
+set_var_case_index (struct variable *v, int case_index)
+{
+ var_get_vardict (v)->case_index = case_index;
+}
+
+/* Removes the dictionary variables with indexes from FROM to TO (exclusive)
+ from name_map. */
+static void
+unindex_vars (struct dictionary *d, size_t from, size_t to)
+{
+ size_t i;
+
+ for (i = from; i < to; i++)
+ unindex_var (d, &d->vars[i]);
+}
+
+/* Re-sets the dict_index in the dictionary variables with
+ indexes from FROM to TO (exclusive). */
+static void
+reindex_vars (struct dictionary *d, size_t from, size_t to, bool skip_callbacks)
+{
+ size_t i;
+
+ for (i = from; i < to; i++)
+ reindex_var (d, &d->vars[i], skip_callbacks);
+}
+
+\f
+