Next: , Previous: rbtree_min_node, Up: Public Routines


3.1.17 rbtree_new

Create the root of a red-black tree.

Synopsis

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

Parameters

int (*cmp)(const void *,const void *)
a node comparison routine used to sort the nodes

Description

This routine creates the data structures necessary to implement the root of a red-black tree. It requires a node comparison function which will be used to sort the nodes.

The comparison routine is usually only used for sorting, not searching, but may be if a search or destroy routine is called without a specific comparison routine. It should return ‘-1’, ‘0’, or ‘1’ depending upon whether the first node is respectively less than, equal to, or greater than the second node.

Returns

It returns a handle to the new tree if successful, NULL if not.