Next: , Previous: Public Routines, Up: Public Routines


3.1.1 rbtree_bnd_search

Search a red-black binary tree keeping track of sibling nodes.

Synopsis

     #include <rbtree/rbtree.h>
     
     
     
void *rbtree_bnd_search( RBTree rbtree, const void *data, void **prev, void **next, int (*cmp)(const void *,const void *) );

Parameters

RBTree rbtree
the red-black tree to search
const void *data
the data to search for
void **prev
holding place for data that is found
void **next
holding place for data that is found
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.

Description

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 keeps track of the preceding and succeeding in-order 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 the node's data pointer. If a node is not found, and if there exists a previous in-order node, the parameter prev is set to that node's data pointer, else it is set to NULL. If there exists a succeeding in-order node, the parameter next is set to its data pointer, else it is set to NULL.

Returns

It returns the node's data pointer if the node can be found, NULL otherwise.