a bidirectional iterator on the nodes of a binary tree of the owner O in symmetric order, by the policy P with the static functions root( o ), left( n ), right( n ) (nil for no child) and read( n ); the items are constant, and the end is the empty path
More...
#include <ADS/Iterators.h>
|
| using | reference = decltype( P::read( std::declval< N * >() ) ) |
| | what P::read() gives
|
| using | value_type = typename detail::ItemValue< reference >::type |
| | the items, the pair of the copies for a PairRef
|
| using | difference_type = std::ptrdiff_t |
| | the distances
|
| using | iterator_concept = std::bidirectional_iterator_tag |
| | bidirectional for the concepts of C++20
|
| using | iterator_category |
| | bidirectional for the older algorithms if P::read() gives a reference, input otherwise
|
template<class O, class P>
class ADS::PathIterator< O, P >
a bidirectional iterator on the nodes of a binary tree of the owner O in symmetric order, by the policy P with the static functions root( o ), left( n ), right( n ) (nil for no child) and read( n ); the items are constant, and the end is the empty path
◆ difference_type
template<class O, class P>
◆ iterator_category
template<class O, class P>
Initial value:
std::conditional_t< std::is_reference_v< reference > ,
std::bidirectional_iterator_tag ,
std::input_iterator_tag >
bidirectional for the older algorithms if P::read() gives a reference, input otherwise
◆ iterator_concept
template<class O, class P>
bidirectional for the concepts of C++20
◆ reference
template<class O, class P>
| using ADS::PathIterator< O, P >::reference = decltype( P::read( std::declval< N * >() ) ) |
◆ value_type
template<class O, class P>
the items, the pair of the copies for a PairRef
◆ PathIterator() [1/2]
template<class O, class P>
◆ PathIterator() [2/2]
template<class O, class P>
on the first node of the tree of o if first, at the end otherwise
◆ operator*()
template<class O, class P>
the item of the current node, read by P::read()
◆ operator++() [1/2]
template<class O, class P>
to the next node, returning the iterator before the step
◆ operator++() [2/2]
template<class O, class P>
to the next node in symmetric order, \( O( 1 ) \) amortized over a whole visit and \( O( h ) \) at most
In pseudocode (beyond the book), \( \pi \) the path from the root to the current node, which is its last node: the leftmost node of the right subtree if there is one, else the lowest ancestor reached from a left child:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{next}() \cr
2 & \quad x \gets \text{the last node of } \pi \cr
3 & \quad \textbf{if}\ x.\mathit{right} \ne \textbf{nil}\ \textbf{then}
\cr
4 & \qquad y \gets x.\mathit{right} \cr
5 & \qquad \textbf{while}\ y \ne \textbf{nil}\ \textbf{do}\ \text{append }
y \text{ to } \pi;\ y \gets y.\mathit{left} \cr
6 & \quad \textbf{else} \cr
7 & \qquad \textbf{repeat} \cr
8 & \qquad\quad y \gets \text{the last node of } \pi;
\ \text{remove it from } \pi \cr
9 & \qquad \textbf{until}\ \pi \text{ is empty }\ \textbf{or}
\ y \ne ( \text{the last node of } \pi ).\mathit{right}
\end{array}}
\]
- Precondition
- not at the end
◆ operator--() [1/2]
template<class O, class P>
to the previous node, returning the iterator before the step
◆ operator--() [2/2]
template<class O, class P>
to the previous node in symmetric order, from the end to the last node
In pseudocode (beyond the book), operator++() with left and right swapped, the end going to the rightmost node:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{prev}() \cr
2 & \quad \textbf{if}\ \pi \text{ is empty }\ \textbf{then}
\ \text{append to } \pi \text{ the rightmost path from the root} \cr
3 & \quad \textbf{else}\ \mathrm{next}() \text{ with left and right }
\text{swapped}
\end{array}}
\]
- Precondition
- not on the first node
◆ operator==()
template<class O, class P>
equal on the same node, or both at the end
The documentation for this class was generated from the following file: