16 vector<const Node*> nodes = tree_.getNodes();
17 for (
size_t i = 0; i < nodes.size(); ++i)
19 nodeToVisited_[nodes[i]->getId()] =
false;
20 nodeToSonVisited_[nodes[i]->getId()] =
false;
28 nodeToVisited_[currNode_->getId()] =
true;
29 if (currNode_->hasFather())
31 nodeToSonVisited_[currNode_->getFatherId()] =
true;
32 for (
size_t i = 0; i < currNode_->getFather()->getNumberOfSons(); ++i)
34 if (currNode_ == currNode_->getFather()->getSon(i))
35 nodeToLastVisitedSonIndex_[currNode_->getFatherId()] = i;
54 if (nodeToSonVisited_[startNode->
getId()])
55 nextPos = nodeToLastVisitedSonIndex_[startNode->
getId()] + 1;
74 if (!currNode_->hasFather())
81 size_t lastVisitedBrotherPos = nodeToLastVisitedSonIndex_[currNode_->getFatherId()];
83 if (lastVisitedBrotherPos == numOfBrothers - 1)
85 currNode_ = currNode_->getFather();
90 size_t nextSiblingPos = lastVisitedBrotherPos + 1;
91 currNode_ = currNode_->getFather()->getSon(nextSiblingPos);
92 currNode_ = getLeftMostPredecessor(currNode_);
96 nodeToVisited_[currNode_->getId()] =
true;
97 if (currNode_->hasFather())
99 if (!nodeToSonVisited_[currNode_->getFatherId()])
101 nodeToSonVisited_[currNode_->getFatherId()] =
true;
102 nodeToLastVisitedSonIndex_[currNode_->getFatherId()] = 0;
106 nodeToLastVisitedSonIndex_[currNode_->getFatherId()] = nodeToLastVisitedSonIndex_[currNode_->getFatherId()] + 1;
116 vector<int> leafIds = tree_.getLeavesId();
117 bool hasVisitedSons = nodeToSonVisited_[currNode_->getId()];
121 if (currNode_->getId() == leafIds[leafIds.size() - 1])
127 if (!hasVisitedSons && numOfSons > 0)
129 currNode_ = currNode_->getSon(0);
132 else if (hasVisitedSons && nodeToLastVisitedSonIndex_[currNode_->getId()] < numOfSons - 1)
135 currNode_ = currNode_->getSon(nodeToLastVisitedSonIndex_[currNode_->getId()] + 1);
140 currNode_ = currNode_->getFather();
141 size_t lastVisitedSonPos = nodeToLastVisitedSonIndex_[currNode_->getId()];
142 numOfSons = currNode_->getNumberOfSons();
143 while (lastVisitedSonPos == numOfSons - 1)
145 currNode_ = currNode_->getFather();
146 lastVisitedSonPos = nodeToLastVisitedSonIndex_[currNode_->getId()];
147 numOfSons = currNode_->getNumberOfSons();
149 currNode_ = currNode_->getSon(lastVisitedSonPos + 1);
152 if (currNode_->hasFather())
154 if (nodeToSonVisited_[currNode_->getFatherId()])
155 nodeToLastVisitedSonIndex_[currNode_->getFatherId()] = nodeToLastVisitedSonIndex_[currNode_->getFatherId()] + 1;
158 nodeToSonVisited_[currNode_->getFatherId()] =
true;
159 nodeToLastVisitedSonIndex_[currNode_->getFatherId()] = 0;
162 nodeToVisited_[currNode_->getId()] =
true;
171 size_t lastVisitedSon;
172 if (nodeToSonVisited_[node->
getId()])
173 lastVisitedSon = nodeToLastVisitedSonIndex_[node->
getId()];
175 bool is_visited = nodeToVisited_[node->
getId()];
178 if (!nodeToSonVisited_[node->
getId()] && numOfSons > 0)
182 else if (nodeToSonVisited_[node->
getId()] && lastVisitedSon <
static_cast<size_t>(floor(numOfSons / 2) - 1))
184 return node->
getSon(lastVisitedSon + 1);
188 else if (numOfSons > 1 && lastVisitedSon ==
static_cast<size_t>(floor(numOfSons / 2) - 1) && !is_visited)
194 else if (nodeToSonVisited_[node->
getId()] && lastVisitedSon < numOfSons - 1)
196 return node->
getSon(lastVisitedSon + 1);
211 vector<int> leafIds = tree_.getLeavesId();
214 if (currNode_->getId() == leafIds[leafIds.size() - 1])
220 while (nodeToVisited_[currNode_->getId()]
221 || (!nodeToSonVisited_[currNode_->getId()] && !currNode_->isLeaf()) || (nodeToSonVisited_[currNode_->getId()] && nodeToLastVisitedSonIndex_[currNode_->getId()] <
static_cast<size_t>(floor(currNode_->getNumberOfSons() / 2) - 1) && !currNode_->isLeaf()))
223 currNode_ = doStep(currNode_);
227 if (currNode_->hasFather())
229 if (nodeToSonVisited_[currNode_->getFatherId()])
230 nodeToLastVisitedSonIndex_[currNode_->getFatherId()] = nodeToLastVisitedSonIndex_[currNode_->getFatherId()] + 1;
233 nodeToSonVisited_[currNode_->getFatherId()] =
true;
234 nodeToLastVisitedSonIndex_[currNode_->getFatherId()] = 0;
237 nodeToVisited_[currNode_->getId()] =
true;
const Node * doStep(const Node *node)
The phylogenetic node class.
virtual int getId() const
Get the node's id.
virtual const Node * getSon(size_t pos) const
virtual const Node * getFather() const
Get the father of this node is there is one.
virtual size_t getNumberOfSons() const
const Node * getLeftMostPredecessor(const Node *startNode)
TreeIterator & operator++()
Defines the basic types of data flow nodes.