#include <config.h>
#include "simap.h"
-#include <assert.h>
#include "hash.h"
static size_t hash_name(const char *, size_t length);
free(node);
}
+/* Searches for 'name' in 'simap'. If found, deletes it and returns true. If
+ * not found, returns false without modifying 'simap'. */
+bool
+simap_find_and_delete(struct simap *simap, const char *name)
+{
+ struct simap_node *node = simap_find(simap, name);
+ if (node) {
+ simap_delete(simap, node);
+ return true;
+ }
+ return false;
+}
+
/* Searches 'simap' for a mapping with the given 'name'. Returns it, if found,
* or a null pointer if not. */
struct simap_node *
return node ? node->data : 0;
}
+/* Returns true if 'simap' contains a copy of 'name', false otherwise. */
+bool
+simap_contains(const struct simap *simap, const char *name)
+{
+ return simap_find(simap, name) != NULL;
+}
+
/* Returns an array that contains a pointer to each mapping in 'simap',
* ordered alphabetically by name. The returned array has simap_count(simap)
* elements.
SIMAP_FOR_EACH (node, simap) {
nodes[i++] = node;
}
- assert(i == n);
+ ovs_assert(i == n);
qsort(nodes, n, sizeof *nodes, compare_nodes_by_name);