+
+void *
+shash_find_and_delete(struct shash *sh, const char *name)
+{
+ struct shash_node *node = shash_find(sh, name);
+ if (node) {
+ void *data = node->data;
+ shash_delete(sh, node);
+ return data;
+ } else {
+ return NULL;
+ }
+}
+
+void *
+shash_find_and_delete_assert(struct shash *sh, const char *name)
+{
+ void *data = shash_find_and_delete(sh, name);
+ ovs_assert(data != NULL);
+ return data;
+}
+
+struct shash_node *
+shash_first(const struct shash *shash)
+{
+ struct hmap_node *node = hmap_first(&shash->map);
+ return node ? CONTAINER_OF(node, struct shash_node, node) : NULL;
+}
+
+static int
+compare_nodes_by_name(const void *a_, const void *b_)
+{
+ const struct shash_node *const *a = a_;
+ const struct shash_node *const *b = b_;
+ return strcmp((*a)->name, (*b)->name);
+}
+
+const struct shash_node **
+shash_sort(const struct shash *sh)
+{
+ if (shash_is_empty(sh)) {
+ return NULL;
+ } else {
+ const struct shash_node **nodes;
+ struct shash_node *node;
+ size_t i, n;
+
+ n = shash_count(sh);
+ nodes = xmalloc(n * sizeof *nodes);
+ i = 0;
+ SHASH_FOR_EACH (node, sh) {
+ nodes[i++] = node;
+ }
+ ovs_assert(i == n);
+
+ qsort(nodes, n, sizeof *nodes, compare_nodes_by_name);
+
+ return nodes;
+ }
+}
+
+/* Returns true if 'a' and 'b' contain the same keys (regardless of their
+ * values), false otherwise. */
+bool
+shash_equal_keys(const struct shash *a, const struct shash *b)
+{
+ struct shash_node *node;
+
+ if (hmap_count(&a->map) != hmap_count(&b->map)) {
+ return false;
+ }
+ SHASH_FOR_EACH (node, a) {
+ if (!shash_find(b, node->name)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+/* Chooses and returns a randomly selected node from 'sh', which must not be
+ * empty.
+ *
+ * I wouldn't depend on this algorithm to be fair, since I haven't analyzed it.
+ * But it does at least ensure that any node in 'sh' can be chosen. */
+struct shash_node *
+shash_random_node(struct shash *sh)
+{
+ return CONTAINER_OF(hmap_random_node(&sh->map), struct shash_node, node);
+}