1 #ifndef GENESIS_TREE_ITERATOR_POSTORDER_H_
2 #define GENESIS_TREE_ITERATOR_POSTORDER_H_
41 #include <type_traits>
61 template<
bool is_const = true >
72 using TreeType =
typename std::conditional< is_const, Tree const, Tree >::type;
73 using LinkType =
typename std::conditional< is_const, TreeLink const, TreeLink >::type;
74 using NodeType =
typename std::conditional< is_const, TreeNode const, TreeNode >::type;
75 using EdgeType =
typename std::conditional< is_const, TreeEdge const, TreeEdge >::type;
128 auto link_ptr = &
link;
129 stack_.push_back( link_ptr );
132 stack_.push_back( &link_ptr->outer() );
133 link_ptr = &link_ptr->outer();
136 while( is_inner_( *link_ptr )) {
137 push_back_children_( link_ptr );
138 link_ptr = &link_ptr->next().outer();
145 assert( link_ptr == stack_.back() );
155 : start_( &(subtree.
link()) )
158 auto link_ptr = &(subtree.
link());
159 stack_.push_back( link_ptr );
166 while( is_inner_( *link_ptr )) {
167 push_back_children_( link_ptr );
168 link_ptr = &link_ptr->next().outer();
173 assert( link_ptr == stack_.back() );
197 if( stack_.empty() ) {
203 }
else if( &link_->outer().next() == stack_.back() ) {
207 link_ = stack_.back();
214 link_ = stack_.back();
215 while( is_inner_( *link_ )) {
216 push_back_children_(link_);
217 link_ = &link_->next().outer();
219 assert( link_ == stack_.back() );
235 return other.link_ == link_;
240 return !(other == *
this);
249 return link_ == start_;
259 return link_->node();
264 return link_->edge();
274 return start_->node();
291 stack_.push_back( &c->outer() );
295 assert( stack_.size() >= push_cnt );
296 std::reverse( stack_.end() - push_cnt, stack_.end() );
299 bool is_inner_( TreeLink
const&
link )
312 std::vector<LinkType*> stack_;
319 template<
typename ElementType>
320 utils::Range< IteratorPostorder< true >>
329 template<
typename ElementType>
342 #endif // include guard