Add a new iterator that allows us to pop the items as we iterate.
We already have a wrapper for sort, add wrapper for bsearch that
can be used later on.

Signed-off-by: Ales Musil <[email protected]>
---
 lib/vec.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib/vec.h b/lib/vec.h
index 5e51357de..ff8f69a5e 100644
--- a/lib/vec.h
+++ b/lib/vec.h
@@ -148,6 +148,18 @@ vector_qsort(struct vector *vec, int (*cmp)(const void *a, 
const void *b))
     }
 }
 
+/* Binary search for given key in the vector, the vector has to be ordered. */
+static inline void *
+vector_bsearch(const struct vector *vec, const void *key,
+               int (*cmp)(const void *a, const void *b))
+{
+    if (vec->len) {
+        return bsearch(key, vec->buffer, vec->len, vec->esize, cmp);
+    }
+
+    return NULL;
+}
+
 /* Returns the size of allocated space for the vector elements in bytes. */
 static inline size_t
 vector_memory_usage(struct vector *vec)
-- 
2.53.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to