|
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_PATH_SET_H_
2 #define GENESIS_TREE_ITERATOR_PATH_SET_H_
41 #include <type_traits>
95 template<
bool is_const = true >
105 using TreeType =
typename std::conditional< is_const, Tree const, Tree >::type;
106 using LinkType =
typename std::conditional< is_const, TreeLink const, TreeLink >::type;
107 using NodeType =
typename std::conditional< is_const, TreeNode const, TreeNode >::type;
108 using EdgeType =
typename std::conditional< is_const, TreeEdge const, TreeEdge >::type;
134 : start_( &start.
node().primary_link() )
135 , finish_( &finish.
node().primary_link() )
136 , lca_( &lca.
node().primary_link() )
140 if( start_ == finish_ ) {
142 if( lca_ != start_ ) {
143 throw std::runtime_error(
144 "Invalid LCA provided for iterating a path with identical start/finish node."
150 doing_first_part_ =
false;
155 }
else if( start_ == lca_ ) {
156 doing_first_part_ =
false;
181 if( ! doing_first_part_ ) {
184 if( link_ == lca_ ) {
192 if(
is_root( link_->node() )) {
193 throw std::runtime_error(
"Found invalid LCA while iterating path." );
198 link_ = &link_->outer().node().primary_link();
201 if( doing_first_part_ ) {
205 if( link_ == lca_ ) {
206 doing_first_part_ =
false;
213 if(
is_root( link_->node() )) {
214 throw std::runtime_error(
"Found invalid LCA while iterating path." );
230 return other.link_ == link_;
235 return !(other == *
this);
244 return link_ == lca_;
259 return link_->node();
264 return link_->edge();
274 return start_->node();
284 return finish_->node();
308 bool doing_first_part_ =
true;
315 template<
typename ElementType>
317 path_set( ElementType
const& start, ElementType
const& finish, ElementType
const& lca )
325 template<
typename ElementType>
327 path_set( ElementType& start, ElementType& finish, ElementType& lca )
338 #endif // include guard
bool operator==(const self_type &other) const
IteratorPathSet(NodeType &start, NodeType &finish, NodeType &lca)
NodeType & start_node() const
IteratorPathSet & operator=(IteratorPathSet const &)=default
bool is_last_common_ancestor() const
NodeType & finish_node() const
~IteratorPathSet()=default
NodeType & lca_node() const
LinkType & finish_link() const
Iterate the path between two TreeNodes (non-linearily), given their lowest common ancestor (LCA).
bool is_root(TreeLink const &link)
Return whether the link belongs to the root node of its Tree.
bool operator!=(const self_type &other) const
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, TreeLink const, TreeLink >::type LinkType
typename std::conditional< is_const, TreeNode const, TreeNode >::type NodeType
utils::Range< IteratorPathSet< true > > path_set(ElementType const &start, ElementType const &finish, ElementType const &lca)
IteratorPathSet(LinkType &start, LinkType &finish, LinkType &lca)
typename std::conditional< is_const, Tree const, Tree >::type TreeType
typename std::conditional< is_const, TreeEdge const, TreeEdge >::type EdgeType
LinkType & start_link() const
LinkType & lca_link() const
std::forward_iterator_tag iterator_category