an ordered tree in \( 2 n \) bits by balanced parentheses, its nodes in preorder
More...
#include <ADS/succinct/BPTree.h>
|
| | BPTree (void)=default |
| | the empty tree
|
| | BPTree (const std::vector< std::vector< std::size_t > > &c) |
| | the tree whose node \( u \) has the children \( c[ u ] \), in order, rooted at 0
|
| | BPTree (BitVector b) |
| | the tree whose parentheses are \( 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 | parent (std::size_t v) const |
| | the parent of \( v \), nil for the root
|
| std::size_t | leftmostChild (std::size_t v) const |
| | the first child of \( v \), nil for a leaf, which is \( v + 1 \) when an open parenthesis follows that of \( v \)
|
| std::size_t | rightSibling (std::size_t v) const |
| | the next sibling of \( v \), nil for the last one
|
| std::size_t | degree (std::size_t v) const |
| | the number of children of \( v \), by a walk along them with leftmostChild() and rightSibling()
|
| std::size_t | subtreeSize (std::size_t v) const |
| | the nodes of the subtree of \( v \), \( v \) included, as \( ( \mathrm{findClose}( p ) - p + 1 ) / 2 \) for the open parenthesis \( p \) of \( v \)
|
| std::size_t | depth (std::size_t v) const |
| | the edges from the root to \( v \), the excess at its open parenthesis less 1
|
| bool | isAncestor (std::size_t u, std::size_t v) const |
| | whether \( u \) is \( v \) or one of its ancestors, i.e., whether \( u \le v < u + \mathrm{subtreeSize}( u ) \)
|
| bool | isLeaf (std::size_t v) const |
| | whether \( v \) has no children
|
| const BalancedParentheses & | parentheses (void) const |
| | the parentheses, with their matching
|
| template<class A> |
| void | persist (A &a) |
| | the members written to, or read from, the archive \( a \) [see Persistence.h]
|
|
| static constexpr std::size_t | nil = std::size_t( -1 ) |
| | no node
|
| static constexpr std::string_view | persistName = "BPTree" |
| | the name of the structure in a file [see Persistence.h]
|
an ordered tree in \( 2 n \) bits by balanced parentheses, its nodes in preorder
◆ BPTree() [1/3]
| ADS::BPTree::BPTree |
( |
void | | ) |
|
|
default |
◆ BPTree() [2/3]
| ADS::BPTree::BPTree |
( |
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 parentheses of Munro and Raman, beyond the book), by a visit in depth with an explicit stack of pairs (node, next child):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{parentheses}( c ) \cr
2 & \quad B \gets ( 1 );\ S \gets \text{the stack } ( ( 0 , 0 ) ) \cr
3 & \quad \textbf{while}\ S \ne \emptyset\ \textbf{do} \cr
4 & \qquad ( u , k ) \gets \mathrm{top}( S ) \cr
5 & \qquad \textbf{if}\ k < | c[ u ] |\ \textbf{then} \cr
6 & \qquad\quad w \gets c[ u ][ k ];\ \mathrm{top}( S ) \gets ( u , k + 1
) \cr
7 & \qquad\quad B \gets B \cdot 1;\ \mathrm{push}( S , ( w , 0 ) )\quad
\triangleright\ \text{enter } w \cr
8 & \qquad \textbf{else} \cr
9 & \qquad\quad B \gets B \cdot 0;\ \mathrm{pop}( S )\quad
\triangleright\ \text{leave } u \cr
10 & \quad \textbf{return}\ B
\end{array}}
\]
- Precondition
- \( c \) describes a tree rooted at 0
◆ BPTree() [3/3]
the tree whose parentheses are \( b \)
- Precondition
- \( b \) is balanced and encloses one tree (an audit)
◆ degree()
| std::size_t ADS::BPTree::degree |
( |
std::size_t | v | ) |
const |
|
nodiscard |
◆ depth()
| std::size_t ADS::BPTree::depth |
( |
std::size_t | v | ) |
const |
|
nodiscard |
the edges from the root to \( v \), the excess at its open parenthesis less 1
- Precondition
- \( v < \mathrm{size}() \)
◆ isAncestor()
| bool ADS::BPTree::isAncestor |
( |
std::size_t | u, |
|
|
std::size_t | v ) const |
|
nodiscard |
whether \( u \) is \( v \) or one of its ancestors, i.e., whether \( u \le v < u + \mathrm{subtreeSize}( u ) \)
- Precondition
- \( u , v < \mathrm{size}() \)
◆ isLeaf()
| bool ADS::BPTree::isLeaf |
( |
std::size_t | v | ) |
const |
|
nodiscard |
whether \( v \) has no children
- Precondition
- \( v < \mathrm{size}() \)
◆ leftmostChild()
| std::size_t ADS::BPTree::leftmostChild |
( |
std::size_t | v | ) |
const |
|
nodiscard |
the first child of \( v \), nil for a leaf, which is \( v + 1 \) when an open parenthesis follows that of \( v \)
- Precondition
- \( v < \mathrm{size}() \)
◆ parent()
| std::size_t ADS::BPTree::parent |
( |
std::size_t | v | ) |
const |
|
nodiscard |
the parent of \( v \), nil for the root
In pseudocode (Navarro and Sadakane, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{parent}( v ) \cr
2 & \quad q \gets \mathrm{enclose}( \mathrm{select}_1( v + 1 ) ) \cr
3 & \quad \textbf{if}\ q = \textbf{nil}\ \textbf{then return nil} \cr
4 & \quad \textbf{return}\ \mathrm{rank}_1( q )
\end{array}}
\]
- Precondition
- \( v < \mathrm{size}() \)
◆ parentheses()
the parentheses, with their matching
◆ persist()
template<class A>
| void ADS::BPTree::persist |
( |
A & | a | ) |
|
the members written to, or read from, the archive \( a \) [see Persistence.h]
◆ rightSibling()
| std::size_t ADS::BPTree::rightSibling |
( |
std::size_t | v | ) |
const |
|
nodiscard |
the next sibling of \( v \), nil for the last one
In pseudocode (Navarro and Sadakane, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{rightSibling}( v ) \cr
2 & \quad q \gets \mathrm{findClose}( \mathrm{select}_1( v + 1 ) ) + 1
\cr
3 & \quad \textbf{if}\ q < | B |\ \textbf{and}\ B[ q ] = 1
\ \textbf{then return}\ \mathrm{rank}_1( q ) \cr
4 & \quad \textbf{return nil}
\end{array}}
\]
- Precondition
- \( v < \mathrm{size}() \)
◆ root()
| std::size_t ADS::BPTree::root |
( |
void | | ) |
const |
|
nodiscard |
the root, nil if the tree is empty
◆ size()
| std::size_t ADS::BPTree::size |
( |
void | | ) |
const |
|
nodiscard |
◆ subtreeSize()
| std::size_t ADS::BPTree::subtreeSize |
( |
std::size_t | v | ) |
const |
|
nodiscard |
the nodes of the subtree of \( v \), \( v \) included, as \( ( \mathrm{findClose}( p ) - p + 1 ) / 2 \) for the open parenthesis \( p \) of \( v \)
- Precondition
- \( v < \mathrm{size}() \)
◆ nil
| std::size_t ADS::BPTree::nil = std::size_t( -1 ) |
|
staticconstexpr |
◆ persistName
| std::string_view ADS::BPTree::persistName = "BPTree" |
|
staticconstexpr |
The documentation for this class was generated from the following file: