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

the join of the trees balanced by weight, with \( \alpha = 0.29 \) More...

#include <ADS/tree/JoinAlgorithms.h>

Public types

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

Static public member functions

static Node * join (Node *l, Node *m, Node *r)
 the join of the trees \( l \) and \( r \) balanced by weight with \( m \) between them, in \( O( | \log w( l ) - \log w( r ) | + 1 ) \) time
static Node * joinRight (Node *l, Node *m, Node *r)
 the join when \( l \) is heavier than \( r \) beyond the balance, by the right spine of \( l \)
static Node * joinLeft (Node *l, Node *m, Node *r)
 the join when \( r \) is heavier than \( l \) beyond the balance, the mirror of joinRight()
static bool like (std::size_t a, std::size_t b)
 whether the weights \( a \) and \( b \) may be the two sides of a node: \( \alpha ( a + b ) \le \min( a , b ) \)
static std::size_t weight (const Node *t)
 the weight of \( t \), its size plus 1

Static public attributes

static constexpr std::size_t kAlphaNum = 29
 \( \alpha \), up
static constexpr std::size_t kAlphaDen = 100
 and down

Detailed description

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

the join of the trees balanced by weight, with \( \alpha = 0.29 \)

Member typedef documentation

◆ Node

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

the type of the nodes

Member function documentation

◆ join()

template<class A>
Node * ADS::WeightBalancedJoin< A >::join ( Node * l,
Node * m,
Node * r )
static

the join of the trees \( l \) and \( r \) balanced by weight with \( m \) between them, in \( O( | \log w( l ) - \log w( r ) | + 1 ) \) time

In pseudocode (Blelloch, Ferizovic and Sun, after Nievergelt and Reingold, beyond the book), \( w \) the weight, \( \mathrm{like}( a , b ) \) true if \( \alpha ( a + b ) \le \min( a , b ) \), and the mirror of joinRight() when \( R \) is heavier:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{join}( L , k , R ) \cr 2 & \quad \textbf{if}\ \mathrm{like}( w( L ) , w( R ) )\ \textbf{then return} \ \mathrm{node}( L , k , R ) \cr 3 & \quad \textbf{if}\ w( L ) > w( R )\ \textbf{then return} \ \mathrm{joinRight}( L , k , R ) \cr 4 & \quad \textbf{return}\ \mathrm{joinLeft}( L , k , R ) \cr 5 & \textbf{function}\ \mathrm{joinRight}( L , k , R ) \cr 6 & \quad \textbf{if}\ \mathrm{like}( w( L ) , w( R ) )\ \textbf{then return} \ \mathrm{node}( L , k , R ) \cr 7 & \quad ( l , k' , c ) \gets \mathrm{expose}( L );\ T' \gets \mathrm{joinRight}( c , k , R ) \cr 8 & \quad \textbf{if}\ \mathrm{like}( w( l ) , w( T' ) )\ \textbf{then return} \ \mathrm{node}( l , k' , T' ) \cr 9 & \quad ( l_1 , r_1 ) \gets \text{the children of } T' \cr 10 & \quad \textbf{if}\ \mathrm{like}( w( l ) , w( l_1 ) )\ \textbf{and} \ \mathrm{like}( w( l ) + w( l_1 ) , w( r_1 ) )\ \textbf{then} \cr 11 & \qquad \textbf{return}\ \mathrm{rotateLeft}( \mathrm{node}( l , k' , T' ) ) \cr 12 & \quad \textbf{return}\ \mathrm{rotateLeft}( \mathrm{node}( l , k' , \mathrm{rotateRight}( T' ) ) ) \end{array}} \]

◆ joinLeft()

template<class A>
Node * ADS::WeightBalancedJoin< A >::joinLeft ( Node * l,
Node * m,
Node * r )
static

the join when \( r \) is heavier than \( l \) beyond the balance, the mirror of joinRight()

◆ joinRight()

template<class A>
Node * ADS::WeightBalancedJoin< A >::joinRight ( Node * l,
Node * m,
Node * r )
static

the join when \( l \) is heavier than \( r \) beyond the balance, by the right spine of \( l \)

◆ like()

template<class A>
bool ADS::WeightBalancedJoin< A >::like ( std::size_t a,
std::size_t b )
static

whether the weights \( a \) and \( b \) may be the two sides of a node: \( \alpha ( a + b ) \le \min( a , b ) \)

◆ weight()

template<class A>
std::size_t ADS::WeightBalancedJoin< A >::weight ( const Node * t)
static

the weight of \( t \), its size plus 1

Member data documentation

◆ kAlphaDen

template<class A>
std::size_t ADS::WeightBalancedJoin< A >::kAlphaDen = 100
staticconstexpr

and down

◆ kAlphaNum

template<class A>
std::size_t ADS::WeightBalancedJoin< A >::kAlphaNum = 29
staticconstexpr

\( \alpha \), up


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