diff --git a/include/rbtree.h b/include/rbtree.h index 332f6f85b..39d45affe 100644 --- a/include/rbtree.h +++ b/include/rbtree.h @@ -72,6 +72,11 @@ struct rbtree *rb_insert(struct rbtree *, struct rbtree *); */ struct rbtree *rb_search(const struct rbtree *, uint64_t); +/* + * Find a node in the tree exactly matching the key value. + */ +struct rbtree *rb_search_exact(const struct rbtree *, uint64_t); + /* * Return the immediately previous or next node in key order. * Returns NULL if this node is the end of the tree. diff --git a/nasmlib/rbtree.c b/nasmlib/rbtree.c index 510f34b1b..773338bb4 100644 --- a/nasmlib/rbtree.c +++ b/nasmlib/rbtree.c @@ -87,6 +87,14 @@ struct rbtree *rb_search(const struct rbtree *tree, uint64_t key) return (struct rbtree *)best; } +struct rbtree *rb_search_exact(const struct rbtree *tree, uint64_t key) +{ + struct rbtree *rv; + + rv = rb_search(tree, key); + return (rv && rv->key == key) ? rv : NULL; +} + /* Reds two left in a row? */ static inline bool is_red_left_left(struct rbtree *h) {