@ -30,26 +30,26 @@
/*
* Colors of nodes ( values of RBNode . color )
* Colors of nodes ( values of RBT Node . color )
*/
# define RBBLACK (0)
# define RBRED (1)
# define RBT BLACK (0)
# define RBT RED (1)
/*
* RBTree control structure
*/
struct RBTree
{
RBNode * root ; /* root node, or RBNIL if tree is empty */
RBTNode * root ; /* root node, or RBT NIL if tree is empty */
/* Remaining fields are constant after rb_create */
/* Remaining fields are constant after rbt _create */
Size node_size ; /* actual size of tree nodes */
/* The caller-supplied manipulation functions */
rb_comparator comparator ;
rb_combiner combiner ;
rb_allocfunc allocfunc ;
rb_freefunc freefunc ;
rbt _comparator comparator ;
rbt _combiner combiner ;
rbt _allocfunc allocfunc ;
rbt _freefunc freefunc ;
/* Passthrough arg passed to all manipulation functions */
void * arg ;
} ;
@ -58,28 +58,31 @@ struct RBTree
* all leafs are sentinels , use customized NIL name to prevent
* collision with system - wide constant NIL which is actually NULL
*/
# define RBNIL (&sentinel)
# define RBT NIL (&sentinel)
static RBNode sentinel = { RBBLACK , RBNIL , RBNIL , NULL } ;
static RBTNode sentinel =
{
RBTBLACK , RBTNIL , RBTNIL , NULL
} ;
/*
* rb_create : create an empty RBTree
* rbt _create : create an empty RBTree
*
* Arguments are :
* node_size : actual size of tree nodes ( > sizeof ( RBNode ) )
* node_size : actual size of tree nodes ( > sizeof ( RBT Node ) )
* The manipulation functions :
* comparator : compare two RBNodes for less / equal / greater
* comparator : compare two RBT Nodes for less / equal / greater
* combiner : merge an existing tree entry with a new one
* allocfunc : allocate a new RBNode
* freefunc : free an old RBNode
* allocfunc : allocate a new RBT Node
* freefunc : free an old RBT Node
* arg : passthrough pointer that will be passed to the manipulation functions
*
* Note that the combiner ' s righthand argument will be a " proposed " tree node ,
* ie the input to rb_insert , in which the RBNode fields themselves aren ' t
* ie the input to rbt _insert , in which the RBT Node fields themselves aren ' t
* valid . Similarly , either input to the comparator may be a " proposed " node .
* This shouldn ' t matter since the functions aren ' t supposed to look at the
* RBNode fields , only the extra fields of the struct the RBNode is embedded
* RBT Node fields , only the extra fields of the struct the RBT Node is embedded
* in .
*
* The freefunc should just be pfree or equivalent ; it should NOT attempt
@ -96,18 +99,18 @@ static RBNode sentinel = {RBBLACK, RBNIL, RBNIL, NULL};
* the RBTree node if you feel the urge .
*/
RBTree *
rb_create ( Size node_size ,
rb_comparator comparator ,
rb_combiner combiner ,
rb_allocfunc allocfunc ,
rb_freefunc freefunc ,
void * arg )
rbt _create ( Size node_size ,
rbt _comparator comparator ,
rbt _combiner combiner ,
rbt _allocfunc allocfunc ,
rbt _freefunc freefunc ,
void * arg )
{
RBTree * tree = ( RBTree * ) palloc ( sizeof ( RBTree ) ) ;
Assert ( node_size > sizeof ( RBNode ) ) ;
Assert ( node_size > sizeof ( RBT Node ) ) ;
tree - > root = RBNIL ;
tree - > root = RBT NIL ;
tree - > node_size = node_size ;
tree - > comparator = comparator ;
tree - > combiner = combiner ;
@ -119,11 +122,11 @@ rb_create(Size node_size,
return tree ;
}
/* Copy the additional data fields from one RBNode to another */
/* Copy the additional data fields from one RBT Node to another */
static inline void
rb_copy_data ( RBTree * rb , RBNode * dest , const RBNode * src )
rbt _copy_data ( RBTree * rbt , RBT Node * dest , const RBT Node * src )
{
memcpy ( dest + 1 , src + 1 , rb - > node_size - sizeof ( RBNode ) ) ;
memcpy ( dest + 1 , src + 1 , rbt - > node_size - sizeof ( RBT Node ) ) ;
}
/**********************************************************************
@ -131,21 +134,21 @@ rb_copy_data(RBTree *rb, RBNode *dest, const RBNode *src)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* rb_find : search for a value in an RBTree
* rbt _find : search for a value in an RBTree
*
* data represents the value to try to find . Its RBNode fields need not
* data represents the value to try to find . Its RBT Node fields need not
* be valid , it ' s the extra data in the larger struct that is of interest .
*
* Returns the matching tree entry , or NULL if no match is found .
*/
RBNode *
rb_find ( RBTree * rb , const RBNode * data )
RBT Node *
rbt _find ( RBTree * rbt , const RBT Node * data )
{
RBNode * node = rb - > root ;
RBTNode * node = rbt - > root ;
while ( node ! = RBNIL )
while ( node ! = RBT NIL )
{
int cmp = rb - > comparator ( data , node , rb - > arg ) ;
int cmp = rbt - > comparator ( data , node , rbt - > arg ) ;
if ( cmp = = 0 )
return node ;
@ -159,26 +162,26 @@ rb_find(RBTree *rb, const RBNode *data)
}
/*
* rb_leftmost : fetch the leftmost ( smallest - valued ) tree node .
* rbt _leftmost : fetch the leftmost ( smallest - valued ) tree node .
* Returns NULL if tree is empty .
*
* Note : in the original implementation this included an unlink step , but
* that ' s a bit awkward . Just call rb_delete on the result if that ' s what
* that ' s a bit awkward . Just call rbt _delete on the result if that ' s what
* you want .
*/
RBNode *
rb_leftmost ( RBTree * rb )
RBT Node *
rbt _leftmost ( RBTree * rbt )
{
RBNode * node = rb - > root ;
RBNode * leftmost = rb - > root ;
RBTNode * node = rbt - > root ;
RBTNode * leftmost = rbt - > root ;
while ( node ! = RBNIL )
while ( node ! = RBT NIL )
{
leftmost = node ;
node = node - > left ;
}
if ( leftmost ! = RBNIL )
if ( leftmost ! = RBT NIL )
return leftmost ;
return NULL ;
@ -195,17 +198,17 @@ rb_leftmost(RBTree *rb)
* child of that node .
*/
static void
rb_rotate_left ( RBTree * rb , RBNode * x )
rbt _rotate_left ( RBTree * rbt , RBT Node * x )
{
RBNode * y = x - > right ;
RBTNode * y = x - > right ;
/* establish x->right link */
x - > right = y - > left ;
if ( y - > left ! = RBNIL )
if ( y - > left ! = RBT NIL )
y - > left - > parent = x ;
/* establish y->parent link */
if ( y ! = RBNIL )
if ( y ! = RBT NIL )
y - > parent = x - > parent ;
if ( x - > parent )
{
@ -216,12 +219,12 @@ rb_rotate_left(RBTree *rb, RBNode *x)
}
else
{
rb - > root = y ;
rbt - > root = y ;
}
/* link x and y */
y - > left = x ;
if ( x ! = RBNIL )
if ( x ! = RBT NIL )
x - > parent = y ;
}
@ -232,17 +235,17 @@ rb_rotate_left(RBTree *rb, RBNode *x)
* child of that node .
*/
static void
rb_rotate_right ( RBTree * rb , RBNode * x )
rbt _rotate_right ( RBTree * rbt , RBT Node * x )
{
RBNode * y = x - > left ;
RBTNode * y = x - > left ;
/* establish x->left link */
x - > left = y - > right ;
if ( y - > right ! = RBNIL )
if ( y - > right ! = RBT NIL )
y - > right - > parent = x ;
/* establish y->parent link */
if ( y ! = RBNIL )
if ( y ! = RBT NIL )
y - > parent = x - > parent ;
if ( x - > parent )
{
@ -253,12 +256,12 @@ rb_rotate_right(RBTree *rb, RBNode *x)
}
else
{
rb - > root = y ;
rbt - > root = y ;
}
/* link x and y */
y - > right = x ;
if ( x ! = RBNIL )
if ( x ! = RBT NIL )
x - > parent = y ;
}
@ -276,13 +279,13 @@ rb_rotate_right(RBTree *rb, RBNode *x)
* the invariant that every leaf has equal black - height . )
*/
static void
rb_insert_fixup ( RBTree * rb , RBNode * x )
rbt _insert_fixup ( RBTree * rbt , RBT Node * x )
{
/*
* x is always a red node . Initially , it is the newly inserted node . Each
* iteration of this loop moves it higher up in the tree .
*/
while ( x ! = rb - > root & & x - > parent - > color = = RBRED )
while ( x ! = rbt - > root & & x - > parent - > color = = RBT RED )
{
/*
* x and x - > parent are both red . Fix depends on whether x - > parent is
@ -302,60 +305,60 @@ rb_insert_fixup(RBTree *rb, RBNode *x)
*/
if ( x - > parent = = x - > parent - > parent - > left )
{
RBNode * y = x - > parent - > parent - > right ;
RBTNode * y = x - > parent - > parent - > right ;
if ( y - > color = = RBRED )
if ( y - > color = = RBT RED )
{
/* uncle is RBRED */
x - > parent - > color = RBBLACK ;
y - > color = RBBLACK ;
x - > parent - > parent - > color = RBRED ;
/* uncle is RBT RED */
x - > parent - > color = RBT BLACK ;
y - > color = RBT BLACK ;
x - > parent - > parent - > color = RBT RED ;
x = x - > parent - > parent ;
}
else
{
/* uncle is RBBLACK */
/* uncle is RBT BLACK */
if ( x = = x - > parent - > right )
{
/* make x a left child */
x = x - > parent ;
rb_rotate_left ( rb , x ) ;
rbt _rotate_left ( rbt , x ) ;
}
/* recolor and rotate */
x - > parent - > color = RBBLACK ;
x - > parent - > parent - > color = RBRED ;
x - > parent - > color = RBT BLACK ;
x - > parent - > parent - > color = RBT RED ;
rb_rotate_right ( rb , x - > parent - > parent ) ;
rbt _rotate_right ( rbt , x - > parent - > parent ) ;
}
}
else
{
/* mirror image of above code */
RBNode * y = x - > parent - > parent - > left ;
RBTNode * y = x - > parent - > parent - > left ;
if ( y - > color = = RBRED )
if ( y - > color = = RBT RED )
{
/* uncle is RBRED */
x - > parent - > color = RBBLACK ;
y - > color = RBBLACK ;
x - > parent - > parent - > color = RBRED ;
/* uncle is RBT RED */
x - > parent - > color = RBT BLACK ;
y - > color = RBT BLACK ;
x - > parent - > parent - > color = RBT RED ;
x = x - > parent - > parent ;
}
else
{
/* uncle is RBBLACK */
/* uncle is RBT BLACK */
if ( x = = x - > parent - > left )
{
x = x - > parent ;
rb_rotate_right ( rb , x ) ;
rbt _rotate_right ( rbt , x ) ;
}
x - > parent - > color = RBBLACK ;
x - > parent - > parent - > color = RBRED ;
x - > parent - > color = RBT BLACK ;
x - > parent - > parent - > color = RBT RED ;
rb_rotate_left ( rb , x - > parent - > parent ) ;
rbt _rotate_left ( rbt , x - > parent - > parent ) ;
}
}
}
@ -364,13 +367,13 @@ rb_insert_fixup(RBTree *rb, RBNode *x)
* The root may already have been black ; if not , the black - height of every
* node in the tree increases by one .
*/
rb - > root - > color = RBBLACK ;
rbt - > root - > color = RBT BLACK ;
}
/*
* rb_insert : insert a new value into the tree .
* rbt _insert : insert a new value into the tree .
*
* data represents the value to insert . Its RBNode fields need not
* data represents the value to insert . Its RBT Node fields need not
* be valid , it ' s the extra data in the larger struct that is of interest .
*
* If the value represented by " data " is not present in the tree , then
@ -384,28 +387,28 @@ rb_insert_fixup(RBTree *rb, RBNode *x)
* " data " is unmodified in either case ; it ' s typically just a local
* variable in the caller .
*/
RBNode *
rb_insert ( RBTree * rb , const RBNode * data , bool * isNew )
RBT Node *
rbt _insert ( RBTree * rbt , const RBT Node * data , bool * isNew )
{
RBNode * current ,
RBTNode * current ,
* parent ,
* x ;
int cmp ;
/* find where node belongs */
current = rb - > root ;
current = rbt - > root ;
parent = NULL ;
cmp = 0 ; /* just to prevent compiler warning */
while ( current ! = RBNIL )
while ( current ! = RBT NIL )
{
cmp = rb - > comparator ( data , current , rb - > arg ) ;
cmp = rbt - > comparator ( data , current , rbt - > arg ) ;
if ( cmp = = 0 )
{
/*
* Found node with given key . Apply combiner .
*/
rb - > combiner ( current , data , rb - > arg ) ;
rbt - > combiner ( current , data , rbt - > arg ) ;
* isNew = false ;
return current ;
}
@ -418,14 +421,14 @@ rb_insert(RBTree *rb, const RBNode *data, bool *isNew)
*/
* isNew = true ;
x = rb - > allocfunc ( rb - > arg ) ;
x = rbt - > allocfunc ( rbt - > arg ) ;
x - > color = RBRED ;
x - > color = RBT RED ;
x - > left = RBNIL ;
x - > right = RBNIL ;
x - > left = RBT NIL ;
x - > right = RBT NIL ;
x - > parent = parent ;
rb_copy_data ( rb , x , data ) ;
rbt _copy_data ( rbt , x , data ) ;
/* insert node in tree */
if ( parent )
@ -437,10 +440,10 @@ rb_insert(RBTree *rb, const RBNode *data, bool *isNew)
}
else
{
rb - > root = x ;
rbt - > root = x ;
}
rb_insert_fixup ( rb , x ) ;
rbt _insert_fixup ( rbt , x ) ;
return x ;
}
@ -453,14 +456,14 @@ rb_insert(RBTree *rb, const RBNode *data, bool *isNew)
* Maintain Red - Black tree balance after deleting a black node .
*/
static void
rb_delete_fixup ( RBTree * rb , RBNode * x )
rbt _delete_fixup ( RBTree * rbt , RBT Node * x )
{
/*
* x is always a black node . Initially , it is the former child of the
* deleted node . Each iteration of this loop moves it higher up in the
* tree .
*/
while ( x ! = rb - > root & & x - > color = = RBBLACK )
while ( x ! = rbt - > root & & x - > color = = RBT BLACK )
{
/*
* Left and right cases are symmetric . Any nodes that are children of
@ -471,93 +474,93 @@ rb_delete_fixup(RBTree *rb, RBNode *x)
*/
if ( x = = x - > parent - > left )
{
RBNode * w = x - > parent - > right ;
RBTNode * w = x - > parent - > right ;
if ( w - > color = = RBRED )
if ( w - > color = = RBT RED )
{
w - > color = RBBLACK ;
x - > parent - > color = RBRED ;
w - > color = RBT BLACK ;
x - > parent - > color = RBT RED ;
rb_rotate_left ( rb , x - > parent ) ;
rbt _rotate_left ( rbt , x - > parent ) ;
w = x - > parent - > right ;
}
if ( w - > left - > color = = RBBLACK & & w - > right - > color = = RBBLACK )
if ( w - > left - > color = = RBT BLACK & & w - > right - > color = = RBT BLACK )
{
w - > color = RBRED ;
w - > color = RBT RED ;
x = x - > parent ;
}
else
{
if ( w - > right - > color = = RBBLACK )
if ( w - > right - > color = = RBT BLACK )
{
w - > left - > color = RBBLACK ;
w - > color = RBRED ;
w - > left - > color = RBT BLACK ;
w - > color = RBT RED ;
rb_rotate_right ( rb , w ) ;
rbt _rotate_right ( rbt , w ) ;
w = x - > parent - > right ;
}
w - > color = x - > parent - > color ;
x - > parent - > color = RBBLACK ;
w - > right - > color = RBBLACK ;
x - > parent - > color = RBT BLACK ;
w - > right - > color = RBT BLACK ;
rb_rotate_left ( rb , x - > parent ) ;
x = rb - > root ; /* Arrange for loop to terminate. */
rbt _rotate_left ( rbt , x - > parent ) ;
x = rbt - > root ; /* Arrange for loop to terminate. */
}
}
else
{
RBNode * w = x - > parent - > left ;
RBTNode * w = x - > parent - > left ;
if ( w - > color = = RBRED )
if ( w - > color = = RBT RED )
{
w - > color = RBBLACK ;
x - > parent - > color = RBRED ;
w - > color = RBT BLACK ;
x - > parent - > color = RBT RED ;
rb_rotate_right ( rb , x - > parent ) ;
rbt _rotate_right ( rbt , x - > parent ) ;
w = x - > parent - > left ;
}
if ( w - > right - > color = = RBBLACK & & w - > left - > color = = RBBLACK )
if ( w - > right - > color = = RBT BLACK & & w - > left - > color = = RBT BLACK )
{
w - > color = RBRED ;
w - > color = RBT RED ;
x = x - > parent ;
}
else
{
if ( w - > left - > color = = RBBLACK )
if ( w - > left - > color = = RBT BLACK )
{
w - > right - > color = RBBLACK ;
w - > color = RBRED ;
w - > right - > color = RBT BLACK ;
w - > color = RBT RED ;
rb_rotate_left ( rb , w ) ;
rbt _rotate_left ( rbt , w ) ;
w = x - > parent - > left ;
}
w - > color = x - > parent - > color ;
x - > parent - > color = RBBLACK ;
w - > left - > color = RBBLACK ;
x - > parent - > color = RBT BLACK ;
w - > left - > color = RBT BLACK ;
rb_rotate_right ( rb , x - > parent ) ;
x = rb - > root ; /* Arrange for loop to terminate. */
rbt _rotate_right ( rbt , x - > parent ) ;
x = rbt - > root ; /* Arrange for loop to terminate. */
}
}
}
x - > color = RBBLACK ;
x - > color = RBT BLACK ;
}
/*
* Delete node z from tree .
*/
static void
rb_delete_node ( RBTree * rb , RBNode * z )
rbt _delete_node ( RBTree * rbt , RBT Node * z )
{
RBNode * x ,
RBTNode * x ,
* y ;
/* This is just paranoia: we should only get called on a valid node */
if ( ! z | | z = = RBNIL )
if ( ! z | | z = = RBT NIL )
return ;
/*
@ -565,21 +568,21 @@ rb_delete_node(RBTree *rb, RBNode *z)
* be z if z has fewer than two children , or the tree successor of z
* otherwise .
*/
if ( z - > left = = RBNIL | | z - > right = = RBNIL )
if ( z - > left = = RBT NIL | | z - > right = = RBT NIL )
{
/* y has a RBNIL node as a child */
/* y has a RBT NIL node as a child */
y = z ;
}
else
{
/* find tree successor */
y = z - > right ;
while ( y - > left ! = RBNIL )
while ( y - > left ! = RBT NIL )
y = y - > left ;
}
/* x is y's only child */
if ( y - > left ! = RBNIL )
if ( y - > left ! = RBT NIL )
x = y - > left ;
else
x = y - > right ;
@ -595,7 +598,7 @@ rb_delete_node(RBTree *rb, RBNode *z)
}
else
{
rb - > root = x ;
rbt - > root = x ;
}
/*
@ -603,55 +606,55 @@ rb_delete_node(RBTree *rb, RBNode *z)
* the data for the removed node to the one we were supposed to remove .
*/
if ( y ! = z )
rb_copy_data ( rb , z , y ) ;
rbt _copy_data ( rbt , z , y ) ;
/*
* Removing a black node might make some paths from root to leaf contain
* fewer black nodes than others , or it might make two red nodes adjacent .
*/
if ( y - > color = = RBBLACK )
rb_delete_fixup ( rb , x ) ;
if ( y - > color = = RBT BLACK )
rbt _delete_fixup ( rbt , x ) ;
/* Now we can recycle the y node */
if ( rb - > freefunc )
rb - > freefunc ( y , rb - > arg ) ;
if ( rbt - > freefunc )
rbt - > freefunc ( y , rbt - > arg ) ;
}
/*
* rb_delete : remove the given tree entry
* rbt _delete : remove the given tree entry
*
* " node " must have previously been found via rb_find or rb_leftmost .
* " node " must have previously been found via rbt _find or rbt _leftmost .
* It is caller ' s responsibility to free any subsidiary data attached
* to the node before calling rb_delete . ( Do * not * try to push that
* to the node before calling rbt _delete . ( Do * not * try to push that
* responsibility off to the freefunc , as some other physical node
* may be the one actually freed ! )
*/
void
rb_delete ( RBTree * rb , RBNode * node )
rbt _delete ( RBTree * rbt , RBT Node * node )
{
rb_delete_node ( rb , node ) ;
rbt _delete_node ( rbt , node ) ;
}
/**********************************************************************
* Traverse *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static RBNode *
rb_left_right_iterator ( RBTreeIterator * iter )
static RBT Node *
rbt _left_right_iterator ( RBTreeIterator * iter )
{
if ( iter - > last_visited = = NULL )
{
iter - > last_visited = iter - > rb - > root ;
while ( iter - > last_visited - > left ! = RBNIL )
iter - > last_visited = iter - > rbt - > root ;
while ( iter - > last_visited - > left ! = RBT NIL )
iter - > last_visited = iter - > last_visited - > left ;
return iter - > last_visited ;
}
if ( iter - > last_visited - > right ! = RBNIL )
if ( iter - > last_visited - > right ! = RBT NIL )
{
iter - > last_visited = iter - > last_visited - > right ;
while ( iter - > last_visited - > left ! = RBNIL )
while ( iter - > last_visited - > left ! = RBT NIL )
iter - > last_visited = iter - > last_visited - > left ;
return iter - > last_visited ;
@ -659,7 +662,7 @@ rb_left_right_iterator(RBTreeIterator *iter)
for ( ; ; )
{
RBNode * came_from = iter - > last_visited ;
RBTNode * came_from = iter - > last_visited ;
iter - > last_visited = iter - > last_visited - > parent ;
if ( iter - > last_visited = = NULL )
@ -678,22 +681,22 @@ rb_left_right_iterator(RBTreeIterator *iter)
return iter - > last_visited ;
}
static RBNode *
rb_right_left_iterator ( RBTreeIterator * iter )
static RBT Node *
rbt _right_left_iterator ( RBTreeIterator * iter )
{
if ( iter - > last_visited = = NULL )
{
iter - > last_visited = iter - > rb - > root ;
while ( iter - > last_visited - > right ! = RBNIL )
iter - > last_visited = iter - > rbt - > root ;
while ( iter - > last_visited - > right ! = RBT NIL )
iter - > last_visited = iter - > last_visited - > right ;
return iter - > last_visited ;
}
if ( iter - > last_visited - > left ! = RBNIL )
if ( iter - > last_visited - > left ! = RBT NIL )
{
iter - > last_visited = iter - > last_visited - > left ;
while ( iter - > last_visited - > right ! = RBNIL )
while ( iter - > last_visited - > right ! = RBT NIL )
iter - > last_visited = iter - > last_visited - > right ;
return iter - > last_visited ;
@ -701,7 +704,7 @@ rb_right_left_iterator(RBTreeIterator *iter)
for ( ; ; )
{
RBNode * came_from = iter - > last_visited ;
RBTNode * came_from = iter - > last_visited ;
iter - > last_visited = iter - > last_visited - > parent ;
if ( iter - > last_visited = = NULL )
@ -721,33 +724,33 @@ rb_right_left_iterator(RBTreeIterator *iter)
}
/*
* rb_begin_iterate : prepare to traverse the tree in any of several orders
* rbt _begin_iterate : prepare to traverse the tree in any of several orders
*
* After calling rb_begin_iterate , call rb_iterate repeatedly until it
* After calling rbt _begin_iterate , call rbt _iterate repeatedly until it
* returns NULL or the traversal stops being of interest .
*
* If the tree is changed during traversal , results of further calls to
* rb_iterate are unspecified . Multiple concurrent iterators on the same
* rbt _iterate are unspecified . Multiple concurrent iterators on the same
* tree are allowed .
*
* The iterator state is stored in the ' iter ' struct . The caller should
* treat it as an opaque struct .
*/
void
rb_begin_iterate ( RBTree * rb , RBOrderControl ctrl , RBTreeIterator * iter )
rbt _begin_iterate ( RBTree * rbt , RBT OrderControl ctrl , RBTreeIterator * iter )
{
/* Common initialization for all traversal orders */
iter - > rb = rb ;
iter - > rbt = rbt ;
iter - > last_visited = NULL ;
iter - > is_over = ( rb - > root = = RBNIL ) ;
iter - > is_over = ( rbt - > root = = RBT NIL ) ;
switch ( ctrl )
{
case LeftRightWalk : /* visit left, then self, then right */
iter - > iterate = rb_left_right_iterator ;
iter - > iterate = rbt _left_right_iterator ;
break ;
case RightLeftWalk : /* visit right, then self, then left */
iter - > iterate = rb_right_left_iterator ;
iter - > iterate = rbt _right_left_iterator ;
break ;
default :
elog ( ERROR , " unrecognized rbtree iteration order: %d " , ctrl ) ;
@ -755,10 +758,10 @@ rb_begin_iterate(RBTree *rb, RBOrderControl ctrl, RBTreeIterator *iter)
}
/*
* rb_iterate : return the next node in traversal order , or NULL if no more
* rbt _iterate : return the next node in traversal order , or NULL if no more
*/
RBNode *
rb_iterate ( RBTreeIterator * iter )
RBT Node *
rbt _iterate ( RBTreeIterator * iter )
{
if ( iter - > is_over )
return NULL ;