+
+struct freq **
+freq_hmap_sort (struct hmap *hmap, int width)
+{
+ size_t n_entries = hmap_count (hmap);
+ struct freq **entries;
+ struct freq *f;
+ size_t i;
+
+ entries = xnmalloc (n_entries, sizeof *entries);
+ i = 0;
+ HMAP_FOR_EACH (f, struct freq, hmap_node, hmap)
+ entries[i++] = f;
+ assert (i == n_entries);
+
+ sort (entries, n_entries, sizeof *entries, compare_freq_ptr_3way, &width);
+
+ return entries;
+}
+
+struct freq *
+freq_hmap_extract (struct hmap *hmap)
+{
+ struct freq *freqs, *f;
+ size_t n_freqs;
+ size_t i;
+
+ n_freqs = hmap_count (hmap);
+ freqs = xnmalloc (n_freqs, sizeof *freqs);
+ i = 0;
+ HMAP_FOR_EACH (f, struct freq, hmap_node, hmap)
+ freqs[i++] = *f;
+ assert (i == n_freqs);
+
+ return freqs;
+}
+