cp_rbtree

Section: libcprops - cp_rbtree (3)
Updated: MAY 2006
Index Return to Main Contents
 

NAME

cp_rbtree_create, cp_rbtree_create_by_option, cp_rbtree_destroy, cp_rbtree_destroy_custom - red-black tree constructor / desctructor functions

 

SYNOPSIS

#include <cprops/rb.h>

cp_rbtree *cp_rbtree_create(cp_compare_fn cmp);
cp_rbtree *
      cp_rbtree_create_by_option(int mode,
                                 cp_compare_fn compare_fn,
                                 cp_copy_fn copy_key,
                                 cp_destructor_fn free_key);
                                 cp_copy_fn copy_value
                                 cp_destructor_fn free_value);

void cp_rbtree_destroy(cp_rbtree *tree);
void cp_rbtree_destroy_custom(cp_rbtree *tree,
                               cp_destructor_fn dk,
                               cp_destructor_fn dv);

 

DESCRIPTION

cp_rbtree_create allocates and initializes an red-black tree object with the given compare function. The compare function should follow this prototype:

  int cmp(void *a, void *b);

and return 0 for matching keys, > 0 if a > b and < 0 if a < b (strcmp semantics). The created tree is not synchronized (COLLECTION_MODE_NOSYNC mode bit is set).

cp_rbtree_create_by_option allows specifying an initial operation mode. Note that unless COLLECTION_MODE_NOSYNC is set on the mode parameter, tree operations are synchronized. The copy_key and copy_value functions are used on insertion if COLLECTION_MODE_COPY is set. If COLLECTION_MODE_COPY is set and either of these is NULL, inserted keys and / or values are inserted directly rather than copies.
The free_key and free_value functions are used on item removal or tree destruction if COLLECTION_MODE_DEEP is set. If COLLECTION_MODE_DEEP is set and either of these is NULL, no cleanup is performed on keys and / or values. This makes it possible to apply the copy/ deep mechanism to keys or values only.

cp_rbtree_destroy recursively deallocates the tree structure using the current mode settings. cp_rbtree_destroy_custom sets the COLLECTION_MODE_DEEP mode bit and destroys the tree using the given key and value destructor functions. Specifying a NULL destructor function or functions precludes key deallocation, value deallocation or both.

 

RETURN VALUE

cp_rbtree_create and cp_rbtree_create_by_option return a newly allocated cp_rbtree object on success or NULL on failure.


 

Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUE

This document was created by man2html, using the manual pages.
Time: 10:00:49 GMT, May 30, 2006
SourceForge.net Logo