diff options
| author | David Lamparter <equinox@diac24.net> | 2021-03-27 22:05:07 +0100 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2021-10-19 14:55:39 +0200 |
| commit | f45897e45c57db80b21e31d44723733a17bfac54 (patch) | |
| tree | c5a8bcdf49194dfe78fb2ffc8800997e7bf211f2 /lib/typerb.c | |
| parent | 4a1b3289c7a8abc9858bfd1ac2ced35e8d20dd68 (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.c')
| -rw-r--r-- | lib/typerb.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/typerb.c b/lib/typerb.c index 151d91ce20..e1346df191 100644 --- a/lib/typerb.c +++ b/lib/typerb.c @@ -480,3 +480,11 @@ struct rb_entry *typed_rb_min(const struct rbt_tree *rbt) return parent; } + +bool typed_rb_member(const struct typed_rb_root *rbt, + const struct typed_rb_entry *rbe) +{ + while (rbe->rbt_parent) + rbe = rbe->rbt_parent; + return rbe == rbt->rbt_root; +} |
