ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BPTree.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------------- File BPTree.h ------------------------------*/
3/*--------------------------------------------------------------------------*/
59/*--------------------------------------------------------------------------*/
60/*----------------------------- DEFINITIONS --------------------------------*/
61/*--------------------------------------------------------------------------*/
62
63#ifndef __ADS_BPTree
64 #define __ADS_BPTree
65/* self-identification: #endif constant */
66
67/*--------------------------------------------------------------------------*/
68/*------------------------------ INCLUDES ----------------------------------*/
69/*--------------------------------------------------------------------------*/
70
71#include "ADS/Contract.h"
74
75#include <cstddef>
76#include <string_view>
77#include <utility>
78#include <vector>
79
80/*--------------------------------------------------------------------------*/
81/*--------------------------- NAMESPACE ------------------------------------*/
82/*--------------------------------------------------------------------------*/
83
84namespace ADS
85{
86
87/*--------------------------------------------------------------------------*/
88/*------------------------------ CLASS BPTree ------------------------------*/
89/*--------------------------------------------------------------------------*/
90
93class BPTree
94{
95
96/*--------------------------------------------------------------------------*/
97 public:
98 static constexpr std::size_t nil = std::size_t( -1 );
99
101 BPTree( void ) = default;
102
126 explicit BPTree( const std::vector< std::vector< std::size_t > > & c );
127
130 explicit BPTree( BitVector b );
131
133 [[nodiscard]] std::size_t size( void ) const;
134
136 [[nodiscard]] std::size_t root( void ) const;
137
150 [[nodiscard]] std::size_t parent( std::size_t v ) const;
151
155 [[nodiscard]] std::size_t leftmostChild( std::size_t v ) const;
156
171 [[nodiscard]] std::size_t rightSibling( std::size_t v ) const;
172
176 [[nodiscard]] std::size_t degree( std::size_t v ) const;
177
182 [[nodiscard]] std::size_t subtreeSize( std::size_t v ) const;
183
187 [[nodiscard]] std::size_t depth( std::size_t v ) const;
188
192 [[nodiscard]] bool isAncestor( std::size_t u , std::size_t v ) const;
193
196 [[nodiscard]] bool isLeaf( std::size_t v ) const;
197
199 [[nodiscard]] const BalancedParentheses & parentheses( void ) const;
200
201/*----------------------------- THE PERSISTENCE ----------------------------*/
202
204 static constexpr std::string_view persistName = "BPTree";
205
208 template< class A >
209 void persist( A & a );
210
211/*--------------------------------------------------------------------------*/
212 private:
214 [[nodiscard]] std::size_t open( std::size_t v ) const;
215
217
218 }; // end( class BPTree )
219
220/*--------------------------------------------------------------------------*/
221
222} // end( namespace ADS )
223
224/*--------------------------------------------------------------------------*/
225/*-------------------------- IMPLEMENTATION --------------------------------*/
226/*--------------------------------------------------------------------------*/
227
228#include "ADS/succinct/impl/BPTree.tpp"
229
230/*--------------------------------------------------------------------------*/
231
232#endif /* BPTree.h included */
233
234/*--------------------------------------------------------------------------*/
235/*---------------------------- End File BPTree.h ---------------------------*/
236/*--------------------------------------------------------------------------*/
A static sequence of balanced parentheses, 1 for an open one and 0 for a closed one,...
The vector of bits on which the succinct structures and the integer codes of ADS are built: the bits ...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
std::size_t degree(std::size_t v) const
the number of children of , by a walk along them with leftmostChild() and rightSibling()
std::size_t depth(std::size_t v) const
the edges from the root to , the excess at its open parenthesis less 1
std::size_t size(void) const
the number of nodes
bool isLeaf(std::size_t v) const
whether has no children
BPTree(const std::vector< std::vector< std::size_t > > &c)
the tree whose node has the children , in order, rooted at 0
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition BPTree.h:204
std::size_t leftmostChild(std::size_t v) const
the first child of , nil for a leaf, which is when an open parenthesis follows that of
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
BPTree(void)=default
the empty tree
std::size_t subtreeSize(std::size_t v) const
the nodes of the subtree of , included, as for the open parenthesis of
bool isAncestor(std::size_t u, std::size_t v) const
whether is or one of its ancestors, i.e., whether
static constexpr std::size_t nil
no node
Definition BPTree.h:98
std::size_t rightSibling(std::size_t v) const
the next sibling of , nil for the last one
std::size_t parent(std::size_t v) const
the parent of , nil for the root
const BalancedParentheses & parentheses(void) const
the parentheses, with their matching
std::size_t root(void) const
the root, nil if the tree is empty
BPTree(BitVector b)
the tree whose parentheses are
a static sequence of balanced parentheses with a range min-max tree
Definition BalancedParentheses.h:124
a vector of bits packed in words of 64 bits
Definition BitVector.h:479
Definition ADT.h:96