|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_TREE_ITERATOR_PREORDER_H_
2 #define GENESIS_TREE_ITERATOR_PREORDER_H_
40 #include <type_traits>
60 template<
bool is_const = true >
71 using TreeType =
typename std::conditional< is_const, Tree const, Tree >::type;
72 using LinkType =
typename std::conditional< is_const, TreeLink const, TreeLink >::type;
73 using NodeType =
typename std::conditional< is_const, TreeNode const, TreeNode >::type;
74 using EdgeType =
typename std::conditional< is_const, TreeEdge const, TreeEdge >::type;
75 using SubtreeType =
typename std::conditional< is_const, Subtree const, Subtree >::type;
121 push_back_children_( &
link );
122 stack_.push_back( &
link.outer() );
130 : start_( &(subtree.
link()) )
131 , link_( &(subtree.
link()) )
135 push_back_children_( link_ );
157 if( stack_.empty() ) {
167 link_ = stack_.back();
169 push_back_children_(link_);
184 return other.link_ == link_;
189 return !(other == *
this);
198 return link_ == start_;
208 return link_->node();
213 return link_->edge();
223 return start_->node();
237 std::vector<LinkType*> tmp;
240 tmp.push_back( &c->outer() );
243 for(
auto lit = tmp.rbegin(); lit != tmp.rend(); ++lit ) {
244 stack_.push_back( *lit );
255 std::vector<LinkType*> stack_;
262 template<
typename ElementType>
263 utils::Range< IteratorPreorder< true >>
272 template<
typename ElementType>
285 #endif // include guard
IteratorPreorder(LinkType &link)
Start a preorder traversal at a given TreeLink, moving in the direction of the link first.
bool operator==(const self_type &other) const
IteratorPreorder(SubtreeType &subtree)
Start a preorder traversal at the top TreeNode of a Subtree, only traversing the nodes in the subtree...
utils::Range< IteratorPreorder< true > > preorder(ElementType const &element)
IteratorPreorder & operator=(IteratorPreorder const &)=default
LinkType & start_link() const
typename std::conditional< is_const, Subtree const, Subtree >::type SubtreeType
IteratorPreorder(NodeType &node)
Start a preorder traversal at the given TreeNode, moving in the root direction first.
NodeType & start_node() const
~IteratorPreorder()=default
Simple wrapper for typical begin() and end() iterators, to be used in range-based for loops.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
typename std::conditional< is_const, TreeEdge const, TreeEdge >::type EdgeType
typename std::conditional< is_const, TreeNode const, TreeNode >::type NodeType
typename std::conditional< is_const, Tree const, Tree >::type TreeType
std::forward_iterator_tag iterator_category
typename std::conditional< is_const, TreeLink const, TreeLink >::type LinkType
bool is_first_iteration() const
bool operator!=(const self_type &other) const
IteratorPreorder(TreeType &tree)
Start a preorder traversal at the root of the given Tree.