ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::JacobsonTree Class Reference

a binary tree in \( 2 n + 1 \) bits, its nodes by levels More...

#include <ADS/succinct/JacobsonTree.h>

Public member functions

 JacobsonTree (void)
 the empty tree
 JacobsonTree (const std::vector< std::pair< std::size_t, std::size_t > > &c)
 the tree whose node \( u \) has the children c[ u ].first (left) and c[ u ].second (right), nil if missing, rooted at 0
 JacobsonTree (BitVector b)
 the tree whose code by levels is \( b \)
std::size_t size (void) const
 the number of nodes
std::size_t root (void) const
 the root, nil if the tree is empty
std::size_t left (std::size_t v) const
 the left child of \( v \), nil if missing: the node at the place \( 2 v + 1 \) of \( B \), counted from 0
std::size_t right (std::size_t v) const
 the right child of \( v \), nil if missing: left() with the place \( 2 v + 2 \)
std::size_t parent (std::size_t v) const
 the parent of \( v \), nil for the root
bool isLeaf (std::size_t v) const
 whether \( v \) has no children
const BitVector & bits (void) const
 \( B \), the code by levels
template<class A>
void persist (A &a)
 the members written to, or read from, the archive \( a \) [see Persistence.h]

Static public attributes

static constexpr std::size_t nil = std::size_t( -1 )
 no node
static constexpr std::string_view persistName = "JacobsonTree"
 the name of the structure in a file [see Persistence.h]

Detailed description

a binary tree in \( 2 n + 1 \) bits, its nodes by levels

Constructor and destructor documentation

◆ JacobsonTree() [1/3]

ADS::JacobsonTree::JacobsonTree ( void )

the empty tree

◆ JacobsonTree() [2/3]

ADS::JacobsonTree::JacobsonTree ( const std::vector< std::pair< std::size_t, std::size_t > > & c)
explicit

the tree whose node \( u \) has the children c[ u ].first (left) and c[ u ].second (right), nil if missing, rooted at 0

In pseudocode (the binary trees of Jacobson, beyond the book), a bit per child, present or not, in a visit in breadth:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{levelCode}( c ) \cr 2 & \quad B \gets ( 1 )\quad \triangleright\ \text{the root} \cr 3 & \quad Q \gets \text{an empty queue};\ \mathrm{enqueue}( Q , 0 ) \cr 4 & \quad \textbf{while}\ Q \ne \emptyset\ \textbf{do} \cr 5 & \qquad u \gets \mathrm{dequeue}( Q ) \cr 6 & \qquad \textbf{foreach}\ w \in ( c[ u ].\mathit{first} , c[ u ].\mathit{second} )\ \textbf{do} \cr 7 & \qquad\quad \textbf{if}\ w = \textbf{nil}\ \textbf{then}\ B \gets B \cdot 0\ \textbf{else}\ B \gets B \cdot 1;\ \mathrm{enqueue}( Q , w ) \cr 8 & \quad \textbf{return}\ B \end{array}} \]

Precondition
\( c \) describes a binary tree rooted at 0

◆ JacobsonTree() [3/3]

ADS::JacobsonTree::JacobsonTree ( BitVector b)
explicit

the tree whose code by levels is \( b \)

Precondition
\( b \) is the code of a binary tree (an audit)

Member function documentation

◆ bits()

const BitVector & ADS::JacobsonTree::bits ( void ) const
nodiscard

\( B \), the code by levels

◆ isLeaf()

bool ADS::JacobsonTree::isLeaf ( std::size_t v) const
nodiscard

whether \( v \) has no children

Precondition
\( v < \mathrm{size}() \)

◆ left()

std::size_t ADS::JacobsonTree::left ( std::size_t v) const
nodiscard

the left child of \( v \), nil if missing: the node at the place \( 2 v + 1 \) of \( B \), counted from 0

In pseudocode (Jacobson, beyond the book), the places counted from 0 and \( \mathrm{rank}_1( q ) \) the 1s before \( q \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{left}( v ) \cr 2 & \quad \textbf{if}\ B[ 2 v + 1 ] = 0\ \textbf{then return nil} \cr 3 & \quad \textbf{return}\ \mathrm{rank}_1( 2 v + 1 ) \end{array}} \]

Precondition
\( v < \mathrm{size}() \)

◆ parent()

std::size_t ADS::JacobsonTree::parent ( std::size_t v) const
nodiscard

the parent of \( v \), nil for the root

In pseudocode (Jacobson, beyond the book), with the places counted from 0 and the ranks of select from 1:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{parent}( v ) \cr 2 & \quad \textbf{if}\ v = 0\ \textbf{then return nil} \cr 3 & \quad \textbf{return}\ \lfloor ( \mathrm{select}_1( v + 1 ) + 1 ) / 2 \rfloor - 1 \end{array}} \]

Precondition
\( v < \mathrm{size}() \)
Postcondition
\( v \) is the left or the right child of the node returned

◆ persist()

template<class A>
void ADS::JacobsonTree::persist ( A & a)

the members written to, or read from, the archive \( a \) [see Persistence.h]

◆ right()

std::size_t ADS::JacobsonTree::right ( std::size_t v) const
nodiscard

the right child of \( v \), nil if missing: left() with the place \( 2 v + 2 \)

Precondition
\( v < \mathrm{size}() \)

◆ root()

std::size_t ADS::JacobsonTree::root ( void ) const
nodiscard

the root, nil if the tree is empty

◆ size()

std::size_t ADS::JacobsonTree::size ( void ) const
nodiscard

the number of nodes

Member data documentation

◆ nil

std::size_t ADS::JacobsonTree::nil = std::size_t( -1 )
staticconstexpr

no node

◆ persistName

std::string_view ADS::JacobsonTree::persistName = "JacobsonTree"
staticconstexpr

the name of the structure in a file [see Persistence.h]


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