Next: , Previous: rbtree_udelete, Up: Public Routines


3.1.6 rbtree_destroy

Search for a node in a red-black binary tree and destroy it.

Synopsis

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

Parameters

RBTree rbtree
the red-black tree to search
const void *data
the data to search for
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

rbtree_destroy 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. 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.

rbtree_destroy frees the memory required by the node. The user must destroy the data referenced by the node's data pointer.

Returns

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