32#ifndef __ADS_CursorTree
33 #define __ADS_CursorTree
69 static constexpr int NIL = -1;
78 [[nodiscard]]
bool empty(
void )
const;
81 [[nodiscard]]
int root(
void )
const;
85 [[nodiscard]]
int parent(
int n )
const;
97 [[nodiscard]]
bool isLeaf(
int n )
const;
105 [[nodiscard]]
const T &
read(
int n )
const;
112 [[nodiscard]]
int size(
void )
const;
188 [[nodiscard]] std::vector< int >
previsit(
void )
const;
191 [[nodiscard]] std::vector< int >
postvisit(
void )
const;
210 [[nodiscard]] std::vector< int >
invisit(
int i )
const;
218 static std::size_t
size(
const auto & o ) {
return( o.f_N.size() ); }
220 static bool occupied(
const auto & o , std::size_t i ) {
221 return( o.f_N[ i ].used );
224 static int read(
const auto & , std::size_t i ) {
return(
int( i ) ); }
228 [[nodiscard]]
auto nodes(
void )
const {
230 return( std::ranges::subrange( It(
this , 0 ) , It(
this , f_N.size() ) ) );
247 return( std::ranges::subrange( It(
this ,
leftmostChild( n ) , n ) ,
263 const Node & node(
int n )
const;
265 Node & node(
int n );
269 [[nodiscard]]
bool linked(
void )
const;
271 int make(
const T & v ,
int p );
273 void free_node(
int n );
275 void release_children(
int n );
279 int copy(
const CursorTree & t ,
int s ,
int p );
283 void visit(
int n ,
int i , std::vector< int > & P ,
int kind )
const;
285 std::vector< Node > f_N;
300#include "ADS/tree/impl/CursorTree.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
static constexpr int NIL
no node
Definition CursorTree.h:69
CursorTree(void)=default
the empty tree
CursorTree(const T &v)
a tree of one node of value
int insertSiblingTree(int n, const CursorTree &t, int s)
a copy of the subtree of in as the next sibling of ; may be this tree, copied as it was before the...
auto nodes(void) const
the nodes, in the order of their places, bidirectional
Definition CursorTree.h:228
bool isLeaf(int n) const
true if has no child
int insertSibling(int n, const T &v)
a new next sibling of , not the root, of value , in , as insertChild() with the sibling of in place ...
int size(void) const
the number of nodes
std::vector< int > invisit(int i) const
the nodes in invisit with index , each node after its first subtrees
std::vector< int > previsit(void) const
the nodes in previsit
bool empty(void) const
true if the tree has no node
int rightSibling(int n) const
the next sibling of , NIL if there is none
void remove(int n)
removes the subtree of , detached from its parent, its places back to the free list
auto children(int n) const
the children of , from the leftmost, forward
Definition CursorTree.h:245
int parent(int n) const
the parent of , NIL for the root
int insertChildTree(int n, const CursorTree &t, int s)
a copy of the subtree of in as the first child of ; may be this tree, copied as it was before the ...
void write(int n, const T &v)
writes in
std::vector< int > postvisit(void) const
the nodes in postvisit
T Item
the type of the values
Definition CursorTree.h:68
const T & read(int n) const
the value of
int root(void) const
the place of the root, NIL if the tree is empty
bool isLastSibling(int n) const
whether is the last of its siblings
int insertChild(int n, const T &v)
a new first child of of value , in
int leftmostChild(int n) const
the first child of , NIL for a leaf
a bidirectional iterator on the occupied places of the table O, by the policy P with the static funct...
Definition Iterators.h:691
a forward iterator on the nodes H (pointers or indices) of the owner O, from a first node,...
Definition Iterators.h:1010
the walk of the children of a node
Definition CursorTree.h:235
static constexpr int none
the end
Definition CursorTree.h:236
static int next(const CursorTree *o, int n, int)
the next sibling of
Definition CursorTree.h:238
the places in use, for SlotIterator
Definition CursorTree.h:216
static int read(const auto &, std::size_t i)
the node of the place , the place itself
Definition CursorTree.h:224
static bool occupied(const auto &o, std::size_t i)
whether the place holds a node
Definition CursorTree.h:220
static std::size_t size(const auto &o)
the places
Definition CursorTree.h:218