Add utility functions to the simap structure. These are used by future patches in this seris. The functions added are.
Signed-off-by: Kyle Mestery <kmest...@cisco.com> Acked-by: Ethan Jackson <et...@nicira.com> --- lib/simap.c | 19 +++++++++++++++++++ lib/simap.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/lib/simap.c b/lib/simap.c index cc8ddb8..998ab07 100644 --- a/lib/simap.c +++ b/lib/simap.c @@ -147,6 +147,18 @@ 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 node != NULL; +} + /* Searches 'simap' for a mapping with the given 'name'. Returns it, if found, * or a null pointer if not. */ struct simap_node * @@ -172,6 +184,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. diff --git a/lib/simap.h b/lib/simap.h index e7bf80b..3e247fc 100644 --- a/lib/simap.h +++ b/lib/simap.h @@ -58,8 +58,10 @@ unsigned int simap_get(const struct simap *, const char *); struct simap_node *simap_find(const struct simap *, const char *); struct simap_node *simap_find_len(const struct simap *, const char *, size_t len); +bool simap_contains(const struct simap *, const char *); void simap_delete(struct simap *, struct simap_node *); +bool simap_find_and_delete(struct simap *, const char *); const struct simap_node **simap_sort(const struct simap *); -- 1.8.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev