Next: rbtree_count, Previous: rbtree_bnd_search, Up: Public Routines
Search a red-black binary tree keeping track of sibling nodes.
#include <rbtree/rbtree.h>RBNode rbtree_bnd_search_node( RBTree rbtree, const void *data, RBNode *prev, RBNode *next, int (*cmp)(const void *,const void *) );
RBTree rbtree
- binary tree to search
const void *data
- the data to search for
RBNode *prev
- set to the previous node
RBNode *next
- set to the next node
int (*cmp)(const void *,const void *)
- The address of a comparison function. Set to
RBTREE_NULL_CMP
to use the tree's initial comparison function.
This routine searches a binary tree for the node for which the passed data compares equivalently with the node's data. It uses the passed comparison routine, if available. If not, it uses that with which the tree was initialized. Note that in the former case the passed data need not have the same form as the data stored in the node.
The comparison routine is called with the passed data as the first argument and the node's data as the second argument. It must return `-1', `0', or `1' if, respectively, the first argument is less than, equal to, or greater than the second.
As the tree is being searched, rbtree_bnd_search_node
keeps
track of the preceding in-order and succeeding nodes. If the node
is not found, the nodes which bracket the data are returned. The
result of the search is returned via the parameters prev
and
next
. If a node has data which matches the key data, both
parameters are set to point at the node. If a node is not found,
and if there exists a previous in-order node, the parameter
prev
is set to point at the node, else it is set to
NULL
. If there exists a succeeding in-order node, the
parameter next
is set to point to it, else it is set to
NULL
.
It returns a handle to the found node, or NULL
if not found.