pruner  0.0-99
treeiterator_meat.hpp
1 #ifndef H_PRUNER
2 #include "tree_bones.hpp"
3 #include "treeiterator_bones.hpp"
4 #endif
5 
6 template <typename Data_Type>
8 
9  this->current_node = tree->POSTORDER.at(0);
10  this->pos_in_pruning_sequence = 0u;
11  this->tree = tree;
12 
13  return;
14 
15 }
16 
17 template <typename Data_Type>
18 inline v_uint::const_iterator TreeIterator<Data_Type>::begin_off() const {
19 
20  return (this->tree)->offspring.at(this->current_node).begin();
21 
22 }
23 
24 template <typename Data_Type>
25 inline v_uint::const_iterator TreeIterator<Data_Type>::end_off() const {
26 
27  return (this->tree)->offspring.at(this->current_node).end();
28 
29 }
30 
31 template <typename Data_Type>
32 inline v_uint::const_iterator TreeIterator<Data_Type>::begin_par() const {
33 
34  return (this->tree)->parents.at(this->current_node).begin();
35 
36 }
37 
38 template <typename Data_Type>
39 inline v_uint::const_iterator TreeIterator<Data_Type>::end_par() const {
40 
41  return (this->tree)->parents.at(this->current_node).end();
42 
43 }
44 
45 // Return codes:
46 // 0: At the requested point
47 // 1: End of road.
48 template <typename Data_Type>
50 
51  if (++this->pos_in_pruning_sequence == this->tree->POSTORDER.size()) {
52  --this->pos_in_pruning_sequence;
53  return 1;
54  }
55 
56  this->current_node = this->tree->POSTORDER[this->pos_in_pruning_sequence];
57  return 0;
58 
59 }
60 
61 template <typename Data_Type>
63 
64  if (this->pos_in_pruning_sequence == 0) {
65  return 1;
66  }
67 
68  this->current_node = this->tree->POSTORDER[--this->pos_in_pruning_sequence];
69  return 0;
70 
71 }
72 
73 template <typename Data_Type>
74 inline int TreeIterator<Data_Type>::operator++() {return this->up();}
75 
76 template <typename Data_Type>
77 inline int TreeIterator<Data_Type>::operator--() {return this->up();}
78 
79 template <typename Data_Type>
80 inline void TreeIterator<Data_Type>::top() {
81  this->current_node = this->tree->POSTORDER[this->tree->POSTORDER.size() - 1u];
82  this->pos_in_pruning_sequence = this->tree->POSTORDER.size() - 1u;
83  return;
84 }
85 
86 template <typename Data_Type>
87 inline void TreeIterator<Data_Type>::bottom() {
88  this->current_node = this->tree->POSTORDER[0u];
89  this->pos_in_pruning_sequence = 0;
90  return;
91 }
92 
93 template <typename Data_Type>
95  return this->tree->n_offspring(this->current_node);
96 }
97 
98 template <typename Data_Type>
100  return this->tree->n_parents(this->current_node);
101 }
102 
103 template <typename Data_Type>
104 inline bool TreeIterator<Data_Type>::is_root() const {
105  return this->tree->parents[current_node].size() == 0u;
106 }
107 
108 template <typename Data_Type>
109 inline bool TreeIterator<Data_Type>::is_tip() const {
110  return this->tree->offspring[current_node].size() == 0u;
111 }
112 
113 template <typename Data_Type>
114 inline uint TreeIterator<Data_Type>::front() const {
115 
116  return this->tree->POSTORDER.front();
117 
118 }
119 
120 template <typename Data_Type>
121 inline uint TreeIterator<Data_Type>::back() const {
122 
123  return this->tree->POSTORDER.back();
124 
125 }
v_uint POSTORDER
Postorder sequence.
Definition: tree_bones.hpp:67
vv_uint offspring
Each nodes&#39; offspring.
Definition: tree_bones.hpp:49
v_uint::const_iterator end_par() const
End of parents const_iterator on the current node.
Definition: treeiterator_meat.hpp:39
int n_parents(uint i) const
Return the number of parents a given node has.
Definition: tree_meat.hpp:488
int down()
Sets the current_node to the previous value as specified in Tree::POSTORDER.
Definition: treeiterator_meat.hpp:62
v_uint::const_iterator begin_off() const
Begin of offpring const_iterator on the current node.
Definition: treeiterator_meat.hpp:18
bool is_root() const
Check whether the current node is root.
Definition: treeiterator_meat.hpp:104
int n_offspring() const
Return the number of offsprings the current node has.
Definition: treeiterator_meat.hpp:94
Tree class.
Definition: tree_bones.hpp:36
vv_uint parents
Each nodes&#39; parents.
Definition: tree_bones.hpp:47
int n_offspring(uint i) const
Return the number of offsprings a given node has.
Definition: tree_meat.hpp:479
bool is_tip() const
Checks whether the current node is a tip (leaf) or not.
Definition: treeiterator_meat.hpp:109
int up()
Sets the current_node to the next value as specified in Tree::POSTORDER.
Definition: treeiterator_meat.hpp:49
Definition: treeiterator_bones.hpp:12
int n_parents() const
Return the number of parents the current node has.
Definition: treeiterator_meat.hpp:99
v_uint::const_iterator end_off() const
End of offpring const_iterator on the current node.
Definition: treeiterator_meat.hpp:25
v_uint::const_iterator begin_par() const
Begin of parents const_iterator on the current node.
Definition: treeiterator_meat.hpp:32