Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare > Class Template Reference

Base iterator template for ranked binary search trees. More...

#include <tpl_binNodeXt.H>

Inheritance diagram for Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >:
[legend]

Public Member Functions

 BinTreeXt_Iterator () noexcept
 
 BinTreeXt_Iterator (const TreeType &__tree) noexcept
 
 BinTreeXt_Iterator (const TreeType &__tree, Node *__curr) noexcept
 
 BinTreeXt_Iterator (const TreeType &__tree, const size_t pos) noexcept
 Initialize an iterator on the inorder position pos.
 
 BinTreeXt_Iterator (const BinTreeXt_Iterator &itor) noexcept
 
BinTreeXt_Iterator & operator= (const BinTreeXt_Iterator &itor) noexcept
 
void reset_first () noexcept
 
void reset_last () noexcept
 
void end () noexcept
 
void reset_to_key (const Key &key) noexcept(noexcept(tree_ptr->find_position(key)))
 Put the iterator on the node of a key.
 
void reset_to_node (Node *node) noexcept
 
void reset_to_pos (const size_t pos) noexcept
 Put the iterator on the inorder position pos.
 
Node * get_curr_ne () const noexcept
 Return the current node.
 
Node * get_curr () const noexcept
 Return the current node.
 
size_t get_current_position () const
 
size_t get_pos () const
 
bool has_curr () const noexcept(nothrow_compare_v< Compare, Key >)
 Return true if the iterator has a current node.
 
void prev ()
 
void next_ne () noexcept
 Move the iterator one position forward, without the check of next().
 
void next ()
 
Node * del ()
 
bool operator== (const BinTreeXt_Iterator &itor) const noexcept(nothrow_compare_v< Compare, Key >)
 Return true if this and itor are on the same position.
 
bool operator!= (const BinTreeXt_Iterator &itor) const
 

Protected Attributes

TreeType * tree_ptr
 
Node * curr
 
int curr_pos
 

Static Protected Attributes

static constexpr int Pos_Not_Current = -1
 
static constexpr int Pos_Empty_Container = -2
 
static constexpr int Pos_Not_Updated = -3
 
static constexpr int Pos_Out_Of_Range = std::numeric_limits<int>::min()
 

Private Member Functions

bool is_container_empty () const noexcept
 
bool pos_updated () const noexcept
 
bool curr_updated () const noexcept
 
void update_pos () const noexcept(nothrow_compare_v< Compare, Key >)
 
void update_curr () const noexcept
 

Static Private Member Functions

static int saturated_pos (const size_t pos) noexcept
 

Detailed Description

template<class TreeType, class Node, typename Key, class Compare>
class Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >

Base iterator template for ranked binary search trees.

This template provides a common implementation for iterators on trees that support O(log n) select and position operations via subtree counters.

The TreeType must provide:

  • getRoot() returning Node*&
  • key_comp() returning Compare&
  • remove(const Key&) returning Node*
Template Parameters
TreeTypethe tree class type
Nodethe node type
Keythe key type
Comparecomparison functor

Definition at line 1163 of file tpl_binNodeXt.H.

Constructor & Destructor Documentation

◆ BinTreeXt_Iterator() [1/5]

template<class TreeType , class Node , typename Key , class Compare >
Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::BinTreeXt_Iterator ( )
inlinenoexcept

Definition at line 1245 of file tpl_binNodeXt.H.

◆ BinTreeXt_Iterator() [2/5]

◆ BinTreeXt_Iterator() [3/5]

template<class TreeType , class Node , typename Key , class Compare >
Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::BinTreeXt_Iterator ( const TreeType &  __tree,
Node *  __curr 
)
inlinenoexcept

Definition at line 1255 of file tpl_binNodeXt.H.

◆ BinTreeXt_Iterator() [4/5]

template<class TreeType , class Node , typename Key , class Compare >
Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::BinTreeXt_Iterator ( const TreeType &  __tree,
const size_t  pos 
)
inlinenoexcept

Initialize an iterator on the inorder position pos.

Parameters
[in]__treethe tree to iterate
[in]posinorder position; at size() or past it, the iterator is at the end, without current node, even if an int cannot hold it.

Definition at line 1266 of file tpl_binNodeXt.H.

◆ BinTreeXt_Iterator() [5/5]

template<class TreeType , class Node , typename Key , class Compare >
Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::BinTreeXt_Iterator ( const BinTreeXt_Iterator< TreeType, Node, Key, Compare > &  itor)
inlinenoexcept

Definition at line 1271 of file tpl_binNodeXt.H.

Member Function Documentation

◆ curr_updated()

◆ del()

◆ end()

template<class TreeType , class Node , typename Key , class Compare >
void Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::end ( )
inlinenoexcept

Definition at line 1300 of file tpl_binNodeXt.H.

References put_itor_at_the_end().

◆ get_curr()

template<class TreeType , class Node , typename Key , class Compare >
Node * Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::get_curr ( ) const
inlinenoexcept

Return the current node.

Returns
the current node, or nullptr if there is none.
See also
get_curr_ne()

Definition at line 1365 of file tpl_binNodeXt.H.

References Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::get_curr_ne().

◆ get_curr_ne()

template<class TreeType , class Node , typename Key , class Compare >
Node * Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::get_curr_ne ( ) const
inlinenoexcept

Return the current node.

A position past the end has no node, whichever way the iterator got there: then it gives nullptr, without the check of select(), which would throw. A node that the iterator already found stays its current one, though: if the tree changes, as when keys before it are removed, it may give that node while has_curr() is false. A change of the tree invalidates the iterator, which must then be put on a position again.

Returns
the current node, or nullptr if there is none.

Definition at line 1353 of file tpl_binNodeXt.H.

References Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr, Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr_updated(), and Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::update_curr().

Referenced by Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::get_curr().

◆ get_current_position()

◆ get_pos()

template<class TreeType , class Node , typename Key , class Compare >
size_t Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::get_pos ( ) const
inline

◆ has_curr()

template<class TreeType , class Node , typename Key , class Compare >
bool Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::has_curr ( ) const
inlinenoexcept

Return true if the iterator has a current node.

Returns
true if the position of the iterator has a node.
Exceptions
anythingthat the comparison throws while it computes the position of a node that the iterator was put on, as reset_to_node() does. It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 1392 of file tpl_binNodeXt.H.

References Aleph::and, Aleph::COUNT(), Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr_pos, Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::pos_updated(), Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::tree_ptr, and Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::update_pos().

Referenced by Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::del(), Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::next(), and Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::prev().

◆ is_container_empty()

◆ next()

template<class TreeType , class Node , typename Key , class Compare >
void Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::next ( )
inline

◆ next_ne()

template<class TreeType , class Node , typename Key , class Compare >
void Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::next_ne ( )
inlinenoexcept

Move the iterator one position forward, without the check of next().

Past the end it goes on to positions without node. It adds 1 as an unsigned: from the greatest int, which a position given near it reaches past the end, it goes to Pos_Out_Of_Range, the least int, instead of overflowing.

Definition at line 1416 of file tpl_binNodeXt.H.

References Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr, and Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr_pos.

Referenced by Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::next().

◆ operator!=()

template<class TreeType , class Node , typename Key , class Compare >
bool Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::operator!= ( const BinTreeXt_Iterator< TreeType, Node, Key, Compare > &  itor) const
inline

Definition at line 1472 of file tpl_binNodeXt.H.

◆ operator=()

◆ operator==()

template<class TreeType , class Node , typename Key , class Compare >
bool Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::operator== ( const BinTreeXt_Iterator< TreeType, Node, Key, Compare > &  itor) const
inlinenoexcept

Return true if this and itor are on the same position.

Parameters
[in]itorthe iterator to compare with.
Returns
true if both iterators are on the same position.
Exceptions
anythingthat the comparison throws while it computes the position of a node that an iterator was put on. It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 1450 of file tpl_binNodeXt.H.

References Aleph::and, Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr, Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr_pos, Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr_updated(), Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::is_container_empty(), Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::pos_updated(), and Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::update_pos().

◆ pos_updated()

◆ prev()

◆ reset_first()

◆ reset_last()

◆ reset_to_key()

template<class TreeType , class Node , typename Key , class Compare >
void Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::reset_to_key ( const Key &  key)
inlinenoexcept

Put the iterator on the node of a key.

The node that the iterator had is dropped, so that get_curr() gives the node of the new position, not the previous one.

Parameters
[in]keyto guide the position; if it is not in the tree, the position is the one that the find_position() of the tree gives.
Exceptions
anythingthat find_position() of the tree throws, as what the comparison throws; then the iterator is left as it was. It is noexcept only if find_position() is.

Definition at line 1316 of file tpl_binNodeXt.H.

References Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr, Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr_pos, and Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::tree_ptr.

◆ reset_to_node()

◆ reset_to_pos()

template<class TreeType , class Node , typename Key , class Compare >
void Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::reset_to_pos ( const size_t  pos)
inlinenoexcept

Put the iterator on the inorder position pos.

Parameters
[in]posinorder position; at size() or past it, the iterator is at the end, without current node, even if an int cannot hold it.

Definition at line 1335 of file tpl_binNodeXt.H.

References Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr, Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::curr_pos, and Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::saturated_pos().

◆ saturated_pos()

template<class TreeType , class Node , typename Key , class Compare >
static int Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::saturated_pos ( const size_t  pos)
inlinestaticprivatenoexcept

◆ update_curr()

◆ update_pos()

Member Data Documentation

◆ curr

◆ curr_pos

◆ Pos_Empty_Container

template<class TreeType , class Node , typename Key , class Compare >
constexpr int Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::Pos_Empty_Container = -2
staticconstexprprotected

◆ Pos_Not_Current

template<class TreeType , class Node , typename Key , class Compare >
constexpr int Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::Pos_Not_Current = -1
staticconstexprprotected

Definition at line 1171 of file tpl_binNodeXt.H.

◆ Pos_Not_Updated

template<class TreeType , class Node , typename Key , class Compare >
constexpr int Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::Pos_Not_Updated = -3
staticconstexprprotected

◆ Pos_Out_Of_Range

template<class TreeType , class Node , typename Key , class Compare >
constexpr int Aleph::BinTreeXt_Iterator< TreeType, Node, Key, Compare >::Pos_Out_Of_Range = std::numeric_limits<int>::min()
staticconstexprprotected

◆ tree_ptr


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