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

an ordered tree in \( 2 n + 1 \) bits by LOUDS, its nodes by levels More...

#include <ADS/succinct/LoudsTree.h>

Public member functions

 LoudsTree (void)
 the empty tree
 LoudsTree (const std::vector< std::vector< std::size_t > > &c)
 the tree whose node \( u \) has the children \( c[ u ] \), in order, rooted at 0
 LoudsTree (BitVector b)
 the tree whose code 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 degree (std::size_t v) const
 the number of children of \( v \), the 0s between the \( ( v + 1 ) \)-th 1 and the next, i.e., \( \mathrm{select}_1( v + 2 ) - \mathrm{select}_1( v + 1 ) - 1 \) with the ranks counted from 1
std::size_t parent (std::size_t v) const
 the parent of \( v \), nil for the root, i.e., \( \mathrm{select}_0( v + 1 ) - v - 1 \), the 1s before the 0 of \( v \) less the one of the dummy root
std::size_t leftmostChild (std::size_t v) const
 the first child of \( v \), nil for a leaf, i.e., \( \mathrm{select}_1( v + 1 ) - v \) when a 0 follows the \( ( v + 1 ) \)-th 1
std::size_t rightSibling (std::size_t v) const
 the next sibling of \( v \), nil for the last one, i.e., \( v + 1 \) when a 0 follows the 0 of \( v \)
std::size_t child (std::size_t v, std::size_t i) const
 the child \( i \) of \( v \), from 0, i.e., \( \mathrm{leftmostChild}( v ) + i \)
bool isLeaf (std::size_t v) const
 whether \( v \) has no children
const BitVector & bits (void) const
 \( B \), the code
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 = "LoudsTree"
 the name of the structure in a file [see Persistence.h]

Detailed description

an ordered tree in \( 2 n + 1 \) bits by LOUDS, its nodes by levels

Constructor and destructor documentation

◆ LoudsTree() [1/3]

ADS::LoudsTree::LoudsTree ( void )

the empty tree

◆ LoudsTree() [2/3]

ADS::LoudsTree::LoudsTree ( const std::vector< std::vector< std::size_t > > & c)
explicit

the tree whose node \( u \) has the children \( c[ u ] \), in order, rooted at 0

In pseudocode (the LOUDS of Jacobson, beyond the book), the degrees in unary by a visit in breadth:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{louds}( c ) \cr 2 & \quad B \gets ( 0 , 1 )\quad \triangleright\ \text{the dummy root,} \text{ of degree 1} \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 ]\ \textbf{do}\ B \gets B \cdot 0;\ \mathrm{enqueue}( Q , w ) \cr 7 & \qquad B \gets B \cdot 1 \cr 8 & \quad \textbf{return}\ B \end{array}} \]

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

◆ LoudsTree() [3/3]

ADS::LoudsTree::LoudsTree ( BitVector b)
explicit

the tree whose code is \( b \)

Precondition
\( b \) is a code of LOUDS (an audit)

Member function documentation

◆ bits()

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

\( B \), the code

◆ child()

std::size_t ADS::LoudsTree::child ( std::size_t v,
std::size_t i ) const
nodiscard

the child \( i \) of \( v \), from 0, i.e., \( \mathrm{leftmostChild}( v ) + i \)

Precondition
\( v < \mathrm{size}() \) and \( i < \mathrm{degree}( v ) \)

◆ degree()

std::size_t ADS::LoudsTree::degree ( std::size_t v) const
nodiscard

the number of children of \( v \), the 0s between the \( ( v + 1 ) \)-th 1 and the next, i.e., \( \mathrm{select}_1( v + 2 ) - \mathrm{select}_1( v + 1 ) - 1 \) with the ranks counted from 1

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

◆ isLeaf()

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

whether \( v \) has no children

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

◆ leftmostChild()

std::size_t ADS::LoudsTree::leftmostChild ( std::size_t v) const
nodiscard

the first child of \( v \), nil for a leaf, i.e., \( \mathrm{select}_1( v + 1 ) - v \) when a 0 follows the \( ( v + 1 ) \)-th 1

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

◆ parent()

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

the parent of \( v \), nil for the root, i.e., \( \mathrm{select}_0( v + 1 ) - v - 1 \), the 1s before the 0 of \( v \) less the one of the dummy root

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

◆ persist()

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

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

◆ rightSibling()

std::size_t ADS::LoudsTree::rightSibling ( std::size_t v) const
nodiscard

the next sibling of \( v \), nil for the last one, i.e., \( v + 1 \) when a 0 follows the 0 of \( v \)

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

◆ root()

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

the root, nil if the tree is empty

◆ size()

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

the number of nodes

Member data documentation

◆ nil

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

no node

◆ persistName

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

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


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