Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

Red-black trees


Detailed Description

Red-black trees are a form of binary search tree. One essential feature of binary search trees is that they need to be balanced in order to be efficient. Many algorithms exist for keeping trees balanced, but among the easiest to implement is the red-black tree. In a red-black tree, every node is given a color--either red or black--and there are various rules for what color nodes can be present where in the tree. This library implements these rules, along with functions for traversing the tree in any desired tree order.

A red-black tree is represented by a caller-allocated rb_tree_t structure. This structure describes various characteristics of the tree, such as the number of nodes in the tree, and includes a pointer to the root node of the tree. Nodes may be added to the tree using rt_add() or removed from the tree using rt_remove(). Additionally, the key on a given node may be changed using the rt_move() function. Nodes may be looked up with rt_find(), and rt_iter() will execute a user-defined function for each node in the tree in the specified order. To remove all entries in the tree, simply call the rt_flush() function. If you must manually iterate through the tree, you may call the rt_next() and rt_prev() functions to determine the next or previous nodes to visit.

There are three ways to traverse a binary tree. The first, known as "preorder," visits the root node, then traverses the left subtree in preorder, then traverses the right subtree in preorder. The second, known an "inorder," traverses the left subtree in inorder, then the root node, then the right subtree in inorder. (This particular ordering retrieves the nodes in lexical order; thus its name.) The third ordering is known as "postorder"; this ordering traverses the left subtree, the right subtree, then visits the root node. To iterate over the tree in one of these orderings, simply call rt_iter() (or rt_next() or rt_prev()) with the RBT_ORDER_PRE, RBT_ORDER_IN, or RBT_ORDER_POST flags. You may OR these flags with DB_FLAG_REVERSE to reverse the traversal ordering, if you wish.


Data Structures

struct  _rb_tree_s
 Red-black tree structure. More...
struct  _rb_node_s
 Red-black tree node structure. More...

Defines

#define RB_TREE_MAGIC
 Red-black tree magic number.
#define RB_TREE_INIT(comp, extra)
 Red-black tree static initializer.
#define rt_verify(tree)
 Red-black tree verification macro.
#define rt_frozen(tree)
 Determine if a red-black tree is frozen.
#define rt_count(tree)
 Red-black tree count.
#define rt_root(tree)
 Red-black tree root node.
#define rt_comp(tree)
 Red-black tree comparison function.
#define rt_extra(tree)
 Extra pointer data in a red-black tree.
#define RBT_ORDER_PRE
 Preorder tree traversal method.
#define RBT_ORDER_IN
 Inorder tree traversal method.
#define RBT_ORDER_POST
 Postorder tree traversal method.
#define RBT_ORDER_MASK
 Tree traversal method mask.
#define rt_prev(tree, node_io, flags)
 Get the previous node.
#define RB_NODE_MAGIC
 Red-black tree node magic number.
#define RB_NODE_INIT(value)
 Red-black tree node static initializer.
#define rn_verify(node)
 Red-black tree node verification macro.
#define rn_color(node)
 Red-black tree node color.
#define rn_tree(node)
 Red-black tree node's tree pointer.
#define rn_parent(node)
 Red-black tree node's parent pointer.
#define rn_left(node)
 Red-black tree node's left pointer.
#define rn_right(node)
 Red-black tree node's right pointer.
#define rn_key(node)
 Red-black tree node's key pointer.
#define rn_value(node)
 Red-black tree node's value pointer.
#define rn_isblack(node)
 Test if a given node is black.
#define rn_isred(node)
 Test if a given node is red.
#define rn_isleft(node)
 Test if a given node is the left node of its parent.
#define rn_isright(node)
 Test if a given node is the right node of its parent.
#define uncle(node)
 Locate the uncle of a node.
#define flip(node)
 Flip the color of a node.
#define _rn_clear(node)
 Clear a node.
#define _rt_update_parent(tree, node, new)
 Update a node's parent.
#define isleft(par, n)
 Determine if node is a left child of its parent.
#define sel_lr(t, n)
 Select a child node based on a condition.
#define sibling(par, n)
 Locate the sibling of a node.
#define l_neph(par, n)
 Locate "closer" nephew of a node.
#define r_neph(par, n)
 Locate "further" nephew of a node.

Typedefs

typedef _rb_tree_s rb_tree_t
 Red-black tree.
typedef _rb_node_s rb_node_t
 Red-black tree node.
typedef unsigned long(* rb_iter_t )(rb_tree_t *tree, rb_node_t *node, void *extra)
 Red-black tree iteration callback.
typedef long(* rb_comp_t )(rb_tree_t *tree, db_key_t *key1, db_key_t *key2)
 Red-black tree comparison callback.
typedef enum _rb_color_e rb_color_t
 Red-black tree node color.

Enumerations

enum  _rb_color_e { RB_COLOR_NONE, RB_COLOR_RED, RB_COLOR_BLACK }
 Red-black tree node color. More...

Functions

long rbtree_comp (rb_tree_t *tree, db_key_t *key1, db_key_t *key2)
 Red-black tree comparison function.
unsigned long rt_init (rb_tree_t *tree, rb_comp_t comp, void *extra)
 Dynamically initialize a red-black tree.
unsigned long rt_add (rb_tree_t *tree, rb_node_t *node, db_key_t *key)
 Add a node to a red-black tree.
unsigned long rt_move (rb_tree_t *tree, rb_node_t *node, db_key_t *key)
 Move a node in a red-black tree.
unsigned long rt_remove (rb_tree_t *tree, rb_node_t *node)
 Remove a node from a red-black tree.
unsigned long rt_find (rb_tree_t *tree, rb_node_t **node_p, db_key_t *key)
 Find an entry in a red-black table.
unsigned long rt_next (rb_tree_t *tree, rb_node_t **node_io, unsigned long flags)
 Get the next node.
unsigned long rt_iter (rb_tree_t *tree, rb_node_t *start, rb_iter_t iter_func, void *extra, unsigned long flags)
 Iterate over each entry in a red-black tree.
unsigned long rt_flush (rb_tree_t *tree, rb_iter_t flush_func, void *extra)
 Flush a red-black tree.
unsigned long rn_init (rb_node_t *node, void *value)
 Dynamically initialize a red-black tree node.
rb_node_t_rb_locate (rb_tree_t *tree, rb_node_t *node, db_key_t *key)
 Locate or insert a red-black tree node.
void _rb_rotate (rb_tree_t *tree, rb_node_t *child)
 Rotate tree nodes.


Define Documentation

#define _rn_clear node   ) 
 

For internal use only.

This macro is used to clear a red-black tree node, so that it is no longer in the tree.

Parameters:
[in] node The rb_node_t to clear.

Definition at line 42 of file rt_remove.c.

Referenced by rt_remove().

#define _rt_update_parent tree,
node,
new   ) 
 

For internal use only.

This macro is used to update the parent of the given node to point to the new child new.

Parameters:
[in] tree The rb_tree_t that the node is in.
[in] node The rb_node_t whose parent is being updated.
[in] new The new rb_node_t for the parent to point to.

Definition at line 64 of file rt_remove.c.

Referenced by rt_remove().

#define flip node   ) 
 

For internal use only.

This macro is used to flip the color of a specific node.

Parameters:
[in] node The rb_node_t to flip.

Definition at line 57 of file rt_add.c.

Referenced by rt_add().

#define isleft par,
 ) 
 

For internal use only.

This macro simply tests whether a given node n is the left child of its parent par.

Parameters:
[in] par The parent being tested.
[in] n The node being tested.
Returns:
Boolean true if n is the left child of par, false otherwise.

Definition at line 87 of file rt_remove.c.

#define l_neph par,
 ) 
 

For internal use only.

This macro retrieves the "closer" nephew of the node n.

Warning:
This macro evaluates both of its arguments multiple times.
Parameters:
[in] par The parent of the node n.
[in] n The node to find the nephew of.
Returns:
The "closer" nephew of the node n.

Definition at line 135 of file rt_remove.c.

Referenced by rt_remove().

#define r_neph par,
 ) 
 

For internal use only.

This macro retrieves the "further" nephew of the node n.

Warning:
This macro evaluates both of its arguments multiple times.
Parameters:
[in] par The parent of the node n.
[in] n The node to find the nephew of.
Returns:
The "further" nephew of the node n.

Definition at line 151 of file rt_remove.c.

Referenced by rt_remove().

#define RB_NODE_INIT value   ) 
 

This macro statically initializes a rb_node_t.

Parameters:
[in] value A pointer to void representing the object associated with the node.

Definition at line 2918 of file dbprim.h.

#define RB_NODE_MAGIC
 

For internal use only.

This is the magic number used for the red-black tree structure.

Definition at line 2908 of file dbprim.h.

Referenced by rn_init().

#define RB_TREE_INIT comp,
extra   ) 
 

This macro statically initializes a rb_tree_t.

Parameters:
[in] comp A rb_comp_t function pointer for a comparison function.
[in] extra Extra pointer data that should be associated with the red-black tree.

Definition at line 2574 of file dbprim.h.

#define RB_TREE_MAGIC
 

For internal use only.

This is the magic number used for the red-black tree structure.

Definition at line 2554 of file dbprim.h.

Referenced by rt_init().

#define RBT_ORDER_IN
 

If this flag is passed to rt_iter(), an inorder iteration will be performed.

Definition at line 2667 of file dbprim.h.

Referenced by rt_next().

#define RBT_ORDER_MASK
 

This flag mask may be used to obtain the tree traversal order.

Definition at line 2682 of file dbprim.h.

Referenced by rt_iter(), and rt_next().

#define RBT_ORDER_POST
 

If this flag is passed to rt_iter(), a postorder iteration will be performed.

Definition at line 2675 of file dbprim.h.

Referenced by rt_next().

#define RBT_ORDER_PRE
 

If this flag is passed to rt_iter(), a preorder iteration will be performed.

Definition at line 2659 of file dbprim.h.

Referenced by rt_next().

#define rn_color node   ) 
 

This macro retrieves the color of the node.

Parameters:
[in] node A pointer to a rb_node_t.
Returns:
A rb_color_t value expressing the color of the node.

Definition at line 2947 of file dbprim.h.

#define rn_isblack node   ) 
 

This macro safely tests whether a given red-black tree node is black.

Warning:
This macro evaluates the node argument twice.
Parameters:
[in] node A pointer to a rb_node_t.
Returns:
Boolean true if node is black or false otherwise.

Definition at line 3036 of file dbprim.h.

Referenced by rt_add(), and rt_remove().

#define rn_isleft node   ) 
 

This macro safely tests whether a given red-black tree node is the left node of its parent.

Warning:
This macro evaluates the node argument three times.
Parameters:
[in] node A pointer to a rb_node_t.
Returns:
Boolean true if node is the left node of its parent or false otherwise.

Definition at line 3067 of file dbprim.h.

Referenced by _rb_rotate(), rt_add(), and rt_next().

#define rn_isred node   ) 
 

This macro safely tests whether a given red-black tree node is red.

Warning:
This macro evaluates the node argument twice.
Parameters:
[in] node A pointer to a rb_node_t.
Returns:
Boolean true if node is red or false otherwise.

Definition at line 3051 of file dbprim.h.

Referenced by rt_add(), and rt_remove().

#define rn_isright node   ) 
 

This macro safely tests whether a given red-black tree node is the right node of its parent.

Warning:
This macro evaluates the node argument three times.
Parameters:
[in] node A pointer to a rb_node_t.
Returns:
Boolean true if node is the right node of its parent or false otherwise.

Definition at line 3084 of file dbprim.h.

Referenced by rt_add(), and rt_next().

#define rn_key node   ) 
 

This macro retrieves the key associated with the red-black tree node.

Parameters:
[in] node A pointer to a rb_node_t.
Returns:
A pointer to a db_key_t.

Definition at line 3007 of file dbprim.h.

Referenced by _rb_locate().

#define rn_left node   ) 
 

This macro retrieves a pointer to the node's left node.

Parameters:
[in] node A pointer to a rb_node_t.
Returns:
A pointer to a rb_node_t representing the left node of the given node.

Definition at line 2983 of file dbprim.h.

#define rn_parent node   ) 
 

This macro retrieves a pointer to the node's parent node.

Parameters:
[in] node A pointer to a rb_node_t.
Returns:
A pointer to a rb_node_t representing the parent of the given node.

Definition at line 2971 of file dbprim.h.

#define rn_right node   ) 
 

This macro retrieves a pointer to the node's right node.

Parameters:
[in] node A pointer to a rb_node_t.
Returns:
A pointer to a rb_node_t representing the right node of the given node.

Definition at line 2995 of file dbprim.h.

#define rn_tree node   ) 
 

This macro retrieves a pointer to the red-black tree the node is in.

Parameters:
[in] node A pointer to a rb_node_t.
Returns:
A pointer to a rb_tree_t.

Definition at line 2959 of file dbprim.h.

#define rn_value node   ) 
 

This macro retrieves the value associated with the red-black tree's node. It may be treated as an lvalue to change that value. Care should be taken when using this option.

Parameters:
[in] node A pointer to a rb_node_t.
Returns:
A pointer to void representing the value associated with this node.

Definition at line 3021 of file dbprim.h.

#define rn_verify node   ) 
 

This macro verifies that a given pointer actually does point to a red-black tree node.

Warning:
This macro evaluates the node argument twice.
Parameters:
[in] node A pointer to a rb_node_t.
Returns:
Boolean true if entry is a valid red-black tree node or false otherwise.

Definition at line 2934 of file dbprim.h.

Referenced by rt_add(), rt_iter(), rt_move(), rt_next(), and rt_remove().

#define rt_comp tree   ) 
 

This macro retrieves the comparison function pointer.

Parameters:
[in] tree A pointer to a rb_tree_t.
Returns:
A rb_comp_t.

Definition at line 2639 of file dbprim.h.

#define rt_count tree   ) 
 

This macro retrieves the total number of items actually in the red-black tree.

Parameters:
[in] tree A pointer to a rb_tree_t.
Returns:
An unsigned long containing a count of the number of items in the red-black tree.

Definition at line 2617 of file dbprim.h.

#define rt_extra tree   ) 
 

This macro retrieves the extra pointer data associated with a particular red-black tree.

Parameters:
[in] tree A pointer to a rb_tree_t.
Returns:
A pointer to void.

Definition at line 2651 of file dbprim.h.

#define rt_frozen tree   ) 
 

This macro returns a non-zero value if the tree is currently frozen. The red-black tree may be frozen if there is an iteration in progress.

Parameters:
[in] tree A pointer to a rb_tree_t.
Returns:
A zero value if the table is not frozen or a non-zero value if the table is frozen.

Definition at line 2604 of file dbprim.h.

#define rt_prev tree,
node_io,
flags   ) 
 

Obtains the previous node in the given iteration scheme. See rt_next() for more information.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in,out] node_io A pointer to a pointer to a rb_node_t. If the pointer to which node_io points is NULL, the first node will be loaded, otherwise the next node will be loaded.
[in] flags One of RBT_ORDER_PRE, RBT_ORDER_IN, or RBT_ORDER_POST, possibly ORed with DB_FLAG_REVERSE to reverse the order of iteration. Zero is not allowed.
Return values:
DB_ERR_BADARGS An argument was invalid.
DB_ERR_WRONGTABLE start is not in this red-black tree.

Definition at line 2705 of file dbprim.h.

#define rt_root tree   ) 
 

This macro retrieves the root node of the tree.

Parameters:
[in] tree A pointer to a rb_tree_t.
Returns:
A pointer to a rb_node_t.

Definition at line 2628 of file dbprim.h.

#define rt_verify tree   ) 
 

This macro verifies that a given pointer actually does point to a red-black tree.

Warning:
This macro evaluates the tree argument twice.
Parameters:
[in] tree A pointer to a rb_tree_t.
Returns:
Boolean true if tree is a valid red-black tree or false otherwise.

Definition at line 2589 of file dbprim.h.

Referenced by rt_add(), rt_find(), rt_flush(), rt_iter(), rt_move(), rt_next(), and rt_remove().

#define sel_lr t,
 ) 
 

For internal use only.

This macro simply returns a pointer to the right child of n if the condition t is true. If not, it returns the left child of n.

Parameters:
[in] t The condition being tested.
[in] n The node whose child is being selected.
Returns:
The left child of n if t is true, otherwise, the right child of n.

Definition at line 104 of file rt_remove.c.

#define sibling par,
 ) 
 

For internal use only.

This macro retrieves the sibling of the node n.

Warning:
This macro evaluates the par argument twice.
Parameters:
[in] par The parent of the node n.
[in] n The node to find the sibling of.
Returns:
The sibling of the node n.

Definition at line 119 of file rt_remove.c.

Referenced by rt_remove().

#define uncle node   ) 
 

For internal use only.

This macro is used to locate the "uncle"--parent's sibling--of a given red-black tree node.

Parameters:
[in] node The rb_node_t to look up the uncle for.
Returns:
The rb_node_t representing the uncle of node.

Definition at line 45 of file rt_add.c.

Referenced by rt_add().


Typedef Documentation

typedef enum _rb_color_e rb_color_t
 

See the documentation for the enumeration _rb_color_e.

Definition at line 575 of file dbprim.h.

typedef long(* rb_comp_t)(rb_tree_t *tree, db_key_t *key1, db_key_t *key2)
 

This function pointer references a callback used to compare nodes in a red-black tree. It should return 0 for identical entries, less than 0 if the first key is less than the second, or greater than 0 if the first key is greater than the second.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] key1 The first key being compared.
[in] key2 The second key being compared.
Returns:
Zero if the keys match, less than zero if the first key orders before the second key, or greater than zero if the first key orders after the second key.

Definition at line 514 of file dbprim.h.

typedef unsigned long(* rb_iter_t)(rb_tree_t *tree, rb_node_t *node, void *extra)
 

This function pointer references a callback used by rb_iter() and rb_flush(). It should return 0 for success. A non-zero return value will terminate the operation and will become the return value of the call.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] node A pointer to the rb_node_t being considered.
[in] extra A void pointer passed to rt_iter() or rt_flush().
Returns:
Zero for success, or non-zero to terminate the iteration.

Definition at line 495 of file dbprim.h.

typedef struct _rb_node_s rb_node_t
 

This structure represents a single node in a red-black tree.

Definition at line 323 of file dbprim.h.

typedef struct _rb_tree_s rb_tree_t
 

This structure is the basis of all red-black trees maintained by this library.

Definition at line 316 of file dbprim.h.


Enumeration Type Documentation

enum _rb_color_e
 

This enumeration is used to specify the color of a node of a red-black tree.

Enumerator:
RB_COLOR_NONE  Node is uncolored as of yet.
RB_COLOR_RED  Node is red.
RB_COLOR_BLACK  Node is black.

Definition at line 564 of file dbprim.h.


Function Documentation

rb_node_t* _rb_locate rb_tree_t tree,
rb_node_t node,
db_key_t key
 

For internal use only.

This function is used to locate a red-black tree node with a key matching key. If the node does not exist, but node is non-NULL, node will be inserted into the tree at an appropriate place, although please note that rebalancing will be necessary.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] node A pointer to a rb_node_t to be added to the tree.
[in] key A pointer to a db_key_t containing the key to be looked up or inserted.
Returns:
A pointer to the rb_node_t found or inserted, or NULL if one could not be found.

Definition at line 35 of file _rb_locate.c.

References RB_COLOR_BLACK, RB_COLOR_RED, _rb_node_s::rn_color, rn_key, _rb_node_s::rn_key, _rb_node_s::rn_left, _rb_node_s::rn_parent, _rb_node_s::rn_right, _rb_node_s::rn_tree, _rb_tree_s::rt_comp, _rb_tree_s::rt_count, and _rb_tree_s::rt_root.

Referenced by rt_add(), rt_find(), and rt_move().

void _rb_rotate rb_tree_t tree,
rb_node_t child
 

For internal use only.

This function is used to swap child with its parent, effecting a tree-balancing rotation.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] child A pointer to a rb_node_t to be swapped with its parent.

Definition at line 35 of file _rb_rotate.c.

References rn_isleft, _rb_node_s::rn_left, _rb_node_s::rn_parent, _rb_node_s::rn_right, and _rb_tree_s::rt_root.

Referenced by rt_add(), and rt_remove().

long rbtree_comp rb_tree_t tree,
db_key_t key1,
db_key_t key2
 

This is a red-black tree comparison function, compatible with rb_comp_t, based around memcmp().

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] key1 The first key being compared.
[in] key2 The second key being compared.
Returns:
Zero if the keys match, less than zero if the first key orders before the second key, or greater than zero if the first key orders after the second key.

Definition at line 37 of file rbtree_comp.c.

References dk_key, and dk_len.

unsigned long rn_init rb_node_t node,
void *  value
 

This function dynamically initializes a red-black tree node.

Parameters:
[in] node A pointer to a rb_tree_t to be initialized.
[in] value A pointer to void which will be the value of the red-black tree entry.
Return values:
DB_ERR_BADARGS A NULL pointer was passed for node.

Definition at line 34 of file rn_init.c.

References _db_key_s::dk_key, _db_key_s::dk_len, RB_COLOR_NONE, RB_NODE_MAGIC, _rb_node_s::rn_color, _rb_node_s::rn_key, _rb_node_s::rn_left, _rb_node_s::rn_magic, _rb_node_s::rn_parent, _rb_node_s::rn_right, _rb_node_s::rn_tree, and _rb_node_s::rn_value.

unsigned long rt_add rb_tree_t tree,
rb_node_t node,
db_key_t key
 

This function adds a node to a red-black tree.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] node A pointer to a rb_node_t to be added to the tree.
[in] key A pointer to a db_key_t containing the key for the node.
Return values:
DB_ERR_BADARGS An invalid argument was given.
DB_ERR_BUSY The node is already in a tree.
DB_ERR_FROZEN The tree is currently frozen.
DB_ERR_DUPLICATE The entry is a duplicate of an existing node.

Definition at line 62 of file rt_add.c.

References _rb_locate(), _rb_rotate(), flip, RB_COLOR_BLACK, RBT_FLAG_FREEZE, _rb_node_s::rn_color, rn_isblack, rn_isleft, rn_isred, rn_isright, _rb_node_s::rn_parent, _rb_node_s::rn_tree, rn_verify, _rb_tree_s::rt_flags, _rb_tree_s::rt_root, rt_verify, and uncle.

Referenced by rt_move().

Here is the call graph for this function:

unsigned long rt_find rb_tree_t tree,
rb_node_t **  node_p,
db_key_t key
 

This function looks up an entry matching the given key.

Parameters:
[in] tree A pointer to a rb_tree_t.
[out] node_p A pointer to a pointer to a rb_node_t. If NULL is passed, the lookup will be performed and an appropriate error code returned.
[in] key A pointer to a db_key_t describing the item to find.
Return values:
DB_ERR_BADARGS An argument was invalid.
DB_ERR_NOENTRY No matching entry was found.

Definition at line 34 of file rt_find.c.

References _rb_locate(), _rb_tree_s::rt_count, and rt_verify.

Here is the call graph for this function:

unsigned long rt_flush rb_tree_t tree,
rb_iter_t  flush_func,
void *  extra
 

This function flushes a red-black tree--that is, it removes each node from the tree. If a flush_func is specified, it will be called on the node after it has been removed from the tree, and may safely call free().

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] flush_func A pointer to a callback function used to perform user-specified actions on a node after removing it from the tree. May be NULL. See the documentation for rb_iter_t for more information.
[in] extra A void pointer that will be passed to flush_func.
Return values:
DB_ERR_BADARGS An argument was invalid.
DB_ERR_FROZEN The red-black tree is frozen.

Definition at line 34 of file rt_flush.c.

References RBT_FLAG_FREEZE, _rb_tree_s::rt_count, _rb_tree_s::rt_flags, rt_remove(), _rb_tree_s::rt_root, and rt_verify.

Here is the call graph for this function:

unsigned long rt_init rb_tree_t tree,
rb_comp_t  comp,
void *  extra
 

This function dynamically initializes a red-black tree.

Parameters:
[in] tree A pointer to a rb_tree_t to be initialized.
[in] comp A rb_comp_t function pointer for a comparison function.
[in] extra Extra pointer data that should be associated with the tree.
Return values:
DB_ERR_BADARGS An invalid argument was given.

Definition at line 34 of file rt_init.c.

References RB_TREE_MAGIC, _rb_tree_s::rt_comp, _rb_tree_s::rt_count, _rb_tree_s::rt_extra, _rb_tree_s::rt_flags, _rb_tree_s::rt_magic, and _rb_tree_s::rt_root.

unsigned long rt_iter rb_tree_t tree,
rb_node_t start,
rb_iter_t  iter_func,
void *  extra,
unsigned long  flags
 

This function iterates over every node in a red-black tree in the given traversal order, executing the given iter_func on each node.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] start A pointer to a rb_node_t describing where in the tree to start. If NULL is passed, the first element of the tree for the specified order will be assumed.
[in] iter_func A pointer to a callback function used to perform user-specified actions on a node in the red-black tree. NULL is an invalid value. See the documentation for rb_iter_t for more information.
[in] extra A void pointer that will be passed to iter_func.
[in] flags One of RBT_ORDER_PRE, RBT_ORDER_IN, or RBT_ORDER_POST, possibly ORed with DB_FLAG_REVERSE to reverse the order of iteration. Zero is not allowed.
Return values:
DB_ERR_BADARGS An argument was invalid.
DB_ERR_WRONGTABLE start is not in this red-black tree.

Definition at line 34 of file rt_iter.c.

References RBT_FLAG_FREEZE, RBT_ORDER_MASK, _rb_node_s::rn_tree, rn_verify, _rb_tree_s::rt_flags, rt_next(), and rt_verify.

Here is the call graph for this function:

unsigned long rt_move rb_tree_t tree,
rb_node_t node,
db_key_t key
 

This function moves an existing node in the red-black tree to correspond to the new key.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] node A pointer to a rb_node_t to be moved. It must already be in the red-black tree.
[in] key A pointer to a db_key_t describing the new key for the node.
Return values:
DB_ERR_BADARGS An invalid argument was given.
DB_ERR_UNUSED Node is not in a red-black tree.
DB_ERR_WRONGTABLE Node is not in this tree.
DB_ERR_FROZEN Red-black tree is frozen.
DB_ERR_DUPLICATE New key is a duplicate of an existing key.
DB_ERR_READDFAILED Unable to re-add node to tree.

Definition at line 35 of file rt_move.c.

References _rb_locate(), RBT_FLAG_FREEZE, _rb_node_s::rn_tree, rn_verify, rt_add(), _rb_tree_s::rt_flags, rt_remove(), and rt_verify.

Here is the call graph for this function:

unsigned long rt_next rb_tree_t tree,
rb_node_t **  node_io,
unsigned long  flags
 

This function obtains the next node in the given iteration scheme. The node_io parameter is a value-result parameter--if the node pointer to which it points is NULL, the first node for the given iteration order will be loaded; otherwise, the next node in the given iteration order will be loaded.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in,out] node_io A pointer to a pointer to a rb_node_t. If the pointer to which node_io points is NULL, the first node will be loaded, otherwise the next node will be loaded.
[in] flags One of RBT_ORDER_PRE, RBT_ORDER_IN, or RBT_ORDER_POST, possibly ORed with DB_FLAG_REVERSE to reverse the order of iteration. Zero is not allowed.
Return values:
DB_ERR_BADARGS An argument was invalid.
DB_ERR_WRONGTABLE start is not in this red-black tree.

Definition at line 34 of file rt_next.c.

References DB_FLAG_REVERSE, RBT_ORDER_IN, RBT_ORDER_MASK, RBT_ORDER_POST, RBT_ORDER_PRE, rn_isleft, rn_isright, _rb_node_s::rn_left, _rb_node_s::rn_parent, _rb_node_s::rn_right, _rb_node_s::rn_tree, rn_verify, _rb_tree_s::rt_root, and rt_verify.

Referenced by rt_iter().

unsigned long rt_remove rb_tree_t tree,
rb_node_t node
 

This function removes the given node from the specified red-black tree.

Parameters:
[in] tree A pointer to a rb_tree_t.
[in] node A pointer to a rb_node_t to be removed from the tree.
Return values:
DB_ERR_BADARGS An invalid argument was given.
DB_ERR_UNUSED Node is not in a red-black tree.
DB_ERR_WRONGTABLE Node is not in this tree.
DB_ERR_FROZEN Red-black tree is frozen.

Definition at line 154 of file rt_remove.c.

References _rb_rotate(), _rn_clear, _rt_update_parent, l_neph, r_neph, RB_COLOR_BLACK, RB_COLOR_RED, RBT_FLAG_FREEZE, _rb_node_s::rn_color, rn_isblack, rn_isred, _rb_node_s::rn_left, _rb_node_s::rn_parent, _rb_node_s::rn_right, _rb_node_s::rn_tree, rn_verify, _rb_tree_s::rt_count, _rb_tree_s::rt_flags, _rb_tree_s::rt_root, rt_verify, and sibling.

Referenced by rt_flush(), and rt_move().

Here is the call graph for this function:


Generated on Sat Jul 15 14:11:05 2006 for DatabasePrimitivesLibrary by  doxygen 1.4.4