ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::RedBlackJoin< A > Struct Template Reference

the join of the Red-Black trees, whose ranks are the black heights; A gives also red( t ), false for nil, and paint( t , red ) More...

#include <ADS/tree/JoinAlgorithms.h>

Public types

using Node = typename A::Node
 the type of the nodes

Static public member functions

static std::pair< Node *, int > join (Node *l, int bl, Node *m, Node *r, int br)
 the join of the Red-Black trees \( l \) and \( r \), of black heights \( b_l \) and \( b_r \), with \( m \) between them: the root and its black height, in \( O( | b_l - b_r | + 1 ) \) time
static Node * joinRight (Node *l, int bl, Node *m, Node *r, int br)
 the join when the black height \( b_l \) of \( l \) is larger than \( b_r \), by the right spine of \( l \)
static Node * joinLeft (Node *l, int bl, Node *m, Node *r, int br)
 the join when the black height \( b_r \) of \( r \) is larger than \( b_l \), the mirror of joinRight()

Detailed description

template<class A>
struct ADS::RedBlackJoin< A >

the join of the Red-Black trees, whose ranks are the black heights; A gives also red( t ), false for nil, and paint( t , red )

Member typedef documentation

◆ Node

template<class A>
using ADS::RedBlackJoin< A >::Node = typename A::Node

the type of the nodes

Member function documentation

◆ join()

template<class A>
std::pair< Node *, int > ADS::RedBlackJoin< A >::join ( Node * l,
int bl,
Node * m,
Node * r,
int br )
static

the join of the Red-Black trees \( l \) and \( r \), of black heights \( b_l \) and \( b_r \), with \( m \) between them: the root and its black height, in \( O( | b_l - b_r | + 1 ) \) time

In pseudocode (Tarjan, chapter 4, and Blelloch, Ferizovic and Sun, beyond the book), \( \hat{h} \) the black height, and the mirror of joinRight() when \( R \) is higher:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{join}( L , k , R ) \cr 2 & \quad \textbf{if}\ \hat{h}( L ) > \hat{h}( R )\ \textbf{then} \cr 3 & \qquad T' \gets \mathrm{joinRight}( L , k , R ) \cr 4 & \qquad \textbf{if}\ T' \text{ and its right child are red} \ \textbf{then}\ \text{paint } T' \text{ black} \cr 5 & \qquad \textbf{return}\ T' \cr 6 & \quad \textbf{if}\ \hat{h}( R ) > \hat{h}( L )\ \textbf{then} \ \text{the mirror of the lines 3 to 5} \cr 7 & \quad \textbf{if}\ L \text{ and } R \text{ are black}\ \textbf{then} \ \textbf{return}\ \mathrm{node}( L , k , R ) \text{, } k \text{ red} \cr 8 & \quad \textbf{return}\ \mathrm{node}( L , k , R ) \text{, } k \text{ black} \cr 9 & \textbf{function}\ \mathrm{joinRight}( L , k , R ) \cr 10 & \quad \textbf{if}\ L \text{ is black}\ \textbf{and}\ \hat{h}( L ) = \hat{h}( R )\ \textbf{then return}\ \mathrm{node}( L , k , R ) \text{, } k \text{ red} \cr 11 & \quad ( l , k' , c ) \gets \mathrm{expose}( L ) \cr 12 & \quad T' \gets \mathrm{joinRight}( c , k , R );\ T'' \gets \mathrm{node}( l , k' , T' ) \cr 13 & \quad \textbf{if}\ k' \text{ is black}\ \textbf{and}\ T' \text{ and } \text{its right child are red}\ \textbf{then} \cr 14 & \qquad \text{paint the right child of } T' \text{ black}; \ \textbf{return}\ \mathrm{rotateLeft}( T'' ) \cr 15 & \quad \textbf{return}\ T'' \end{array}} \]

◆ joinLeft()

template<class A>
Node * ADS::RedBlackJoin< A >::joinLeft ( Node * l,
int bl,
Node * m,
Node * r,
int br )
static

the join when the black height \( b_r \) of \( r \) is larger than \( b_l \), the mirror of joinRight()

◆ joinRight()

template<class A>
Node * ADS::RedBlackJoin< A >::joinRight ( Node * l,
int bl,
Node * m,
Node * r,
int br )
static

the join when the black height \( b_l \) of \( l \) is larger than \( b_r \), by the right spine of \( l \)


The documentation for this struct was generated from the following file: