-#if GLOBAL_DEBUGGING
- static int reentrant;
- if (reentrant)
- abort ();
- reentrant++;
-#endif
- hsh_param = h->param;
- hsh_compare = compare ? compare : h->compare;
- qsort (h->table, h->m, sizeof *h->table, internal_comparison_fn);
-#if GLOBAL_DEBUGGING
- reentrant--;
-#endif
- return h->table;
+ assert (h != NULL);
+
+ hsh_data (h);
+ sort (h->entries, h->used, sizeof *h->entries, comparison_helper, h);
+ return h->entries;
+}
+
+/* Makes and returns a copy of the pointers to the data in H.
+ The returned data consists of hsh_count(H) non-null pointers,
+ in no particular order, followed by a null pointer. The hash
+ table is not modified. The caller is responsible for freeing
+ the allocated data. */
+void **
+hsh_data_copy (struct hsh_table *h)
+{
+ void **copy;
+
+ assert (h != NULL);
+ copy = xmalloc ((h->used + 1) * sizeof *copy);
+ copy_if (h->entries, h->size, sizeof *h->entries, copy,
+ not_null, NULL);
+ copy[h->used] = NULL;
+ return copy;
+}
+
+/* Makes and returns a copy of the pointers to the data in H.
+ The returned data consists of hsh_count(H) non-null pointers,
+ sorted in order of the hash comparison function, followed by a
+ null pointer. The hash table is not modified. The caller is
+ responsible for freeing the allocated data. */
+void **
+hsh_sort_copy (struct hsh_table *h)
+{
+ void **copy;
+
+ assert (h != NULL);
+ copy = hsh_data_copy (h);
+ sort (copy, h->used, sizeof *copy, comparison_helper, h);
+ return copy;