mirror of
https://github.com/netwide-assembler/nasm
synced 2026-08-26 16:23:04 -04:00
rbtree: add rb_search_exact()
Sometimes we want to search for an exact key only, and reject the case when tree->key < key. Add rb_search_exact() for this purpose, rather than forcing the caller to perform the comparison in open code. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
parent
50184c26c7
commit
e450e06084
2 changed files with 13 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue