[ovs-dev] [PATCH 1/3] sset: New function sset_intersect().

Ben Pfaff blp at nicira.com
Wed Aug 26 04:37:27 UTC 2015


This will acquire its first user in an upcoming commit.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/sset.c | 14 ++++++++++++++
 lib/sset.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/lib/sset.c b/lib/sset.c
index 33c4298..f9d4fc0 100644
--- a/lib/sset.c
+++ b/lib/sset.c
@@ -269,6 +269,20 @@ sset_at_position(const struct sset *set, uint32_t *bucketp, uint32_t *offsetp)
     return SSET_NODE_FROM_HMAP_NODE(hmap_node);
 }
 
+/* Replaces 'a' by the intersection of 'a' and 'b'.  That is, removes from 'a'
+ * all of the strings that are not also in 'b'. */
+void
+sset_intersect(struct sset *a, const struct sset *b)
+{
+    const char *name, *next;
+
+    SSET_FOR_EACH_SAFE (name, next, a) {
+        if (!sset_contains(b, name)) {
+            sset_delete(a, SSET_NODE_FROM_NAME(name));
+        }
+    }
+}
+
 /* Returns a null-terminated array of pointers to the strings in 'set', in no
  * particular order.  The caller must free the returned array when it is no
  * longer needed, but the strings in the array belong to 'set' and thus must
diff --git a/lib/sset.h b/lib/sset.h
index 35bf463..25d9c1c 100644
--- a/lib/sset.h
+++ b/lib/sset.h
@@ -67,6 +67,9 @@ bool sset_equals(const struct sset *, const struct sset *);
 struct sset_node *sset_at_position(const struct sset *,
                                    uint32_t *bucketp, uint32_t *offsetp);
 
+/* Set operations. */
+void sset_intersect(struct sset *, const struct sset *);
+
 /* Iteration macros. */
 #define SSET_FOR_EACH(NAME, SSET)               \
     for ((NAME) = SSET_FIRST(SSET);             \
-- 
2.1.3




More information about the dev mailing list