Skip to content

Commit

Permalink
Fix implementation of tree preorder stacking. (#160)
Browse files Browse the repository at this point in the history
Fixes #149
  • Loading branch information
molpopgen authored Aug 30, 2021
1 parent fafd457 commit 3dbe8c4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/trees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,13 @@ impl NodeIterator for PreorderNodeIterator<'_> {
self.current_node_ = self.node_stack.pop();
match self.current_node_ {
Some(u) => {
let mut c = self.tree.left_child(u).unwrap();
// NOTE: process children right-to-left
// because we later pop them from a steck
// to generate the expected left-to-right ordering.
let mut c = self.tree.right_child(u).unwrap();
while c != NodeId::NULL {
self.node_stack.push(c);
c = self.tree.right_sib(c).unwrap();
c = self.tree.left_sib(c).unwrap();
}
}
None => {
Expand Down

0 comments on commit 3dbe8c4

Please sign in to comment.