From: Ben Pfaff <b...@ovn.org> This will acquire a user in an upcoming commit.
Signed-off-by: Ben Pfaff <b...@ovn.org> --- lib/simap.c | 23 +++++++++++++++++++++-- lib/simap.h | 3 ++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/simap.c b/lib/simap.c index 9c30f68..d634f8e 100644 --- a/lib/simap.c +++ b/lib/simap.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 2012, 2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -222,7 +222,26 @@ simap_sort(const struct simap *simap) return nodes; } } - + +/* Returns true if the two maps are equal, meaning that they have the same set + * of key-value pairs, otherwise false. */ +bool +simap_equal(const struct simap *a, const struct simap *b) +{ + if (simap_count(a) != simap_count(b)) { + return false; + } + + const struct simap_node *an; + SIMAP_FOR_EACH (an, a) { + const struct simap_node *bn = simap_find(b, an->name); + if (!bn || an->data != bn->data) { + return false; + } + } + return true; +} + static size_t hash_name(const char *name, size_t length) { diff --git a/lib/simap.h b/lib/simap.h index 9486080..5b4a2f3 100644 --- a/lib/simap.h +++ b/lib/simap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011, 2012, 2016 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 2012, 2016, 2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,6 +69,7 @@ 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 *); +bool simap_equal(const struct simap *, const struct simap *); #ifdef __cplusplus } -- 1.8.3.1 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev