summaryrefslogtreecommitdiff
path: root/lib/typerb.h
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2021-03-27 22:05:07 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2021-10-19 14:55:39 +0200
commitf45897e45c57db80b21e31d44723733a17bfac54 (patch)
treec5a8bcdf49194dfe78fb2ffc8800997e7bf211f2 /lib/typerb.h
parent4a1b3289c7a8abc9858bfd1ac2ced35e8d20dd68 (diff)
lib: typesafe *_member()
This provides a "is this item on this list" check, which may or may not be faster than using *_find() for the same purpose. (If the container has no faster way of doing it, it falls back to using *_find().) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/typerb.h')
-rw-r--r--lib/typerb.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/typerb.h b/lib/typerb.h
index cbed8d4893..d22d864aae 100644
--- a/lib/typerb.h
+++ b/lib/typerb.h
@@ -62,6 +62,8 @@ const struct typed_rb_entry *typed_rb_find_lt(const struct typed_rb_root *rbt,
const struct typed_rb_entry *b));
struct typed_rb_entry *typed_rb_min(const struct typed_rb_root *rbt);
struct typed_rb_entry *typed_rb_next(const struct typed_rb_entry *rbe);
+bool typed_rb_member(const struct typed_rb_root *rbt,
+ const struct typed_rb_entry *rbe);
#define _PREDECL_RBTREE(prefix) \
struct prefix ## _head { struct typed_rb_root rr; }; \
@@ -142,6 +144,11 @@ macro_pure size_t prefix ## _count(const struct prefix##_head *h) \
{ \
return h->rr.count; \
} \
+macro_pure bool prefix ## _member(const struct prefix##_head *h, \
+ const type *item) \
+{ \
+ return typed_rb_member(&h->rr, &item->field.re); \
+} \
MACRO_REQUIRE_SEMICOLON() /* end */
#define PREDECL_RBTREE_UNIQ(prefix) \