X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fsimap.c;h=9c30f6886b2f0001784cc6a7596ab64a00281f7a;hb=28c5588e8e1a8d091c5d2275232c35f2968a97fa;hp=f6804aab3e26f7e232b472b36ba9e0a4065a42bf;hpb=44bac24ba5d22fe238bd96702707eb2029efec41;p=sliver-openvswitch.git diff --git a/lib/simap.c b/lib/simap.c index f6804aab3..9c30f6886 100644 --- a/lib/simap.c +++ b/lib/simap.c @@ -16,7 +16,6 @@ #include #include "simap.h" -#include #include "hash.h" static size_t hash_name(const char *, size_t length); @@ -148,6 +147,19 @@ simap_delete(struct simap *simap, struct simap_node *node) 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 * @@ -173,6 +185,13 @@ simap_get(const struct simap *simap, const char *name) 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. @@ -196,7 +215,7 @@ simap_sort(const struct simap *simap) SIMAP_FOR_EACH (node, simap) { nodes[i++] = node; } - assert(i == n); + ovs_assert(i == n); qsort(nodes, n, sizeof *nodes, compare_nodes_by_name);