Skip to content

Commit 0800d40

Browse files
committed
more
1 parent c384e4f commit 0800d40

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/sys/tree.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,43 @@ pub enum NodeTraversalOrder {
370370
///traverse to tips, proceeed to the next root, etc..
371371
Postorder,
372372
}
373+
374+
struct ChildIterator<'a> {
375+
current_child: Option<NodeId>,
376+
next_child: NodeId,
377+
tree: &'a LLTree<'a>,
378+
}
379+
380+
impl<'a> ChildIterator<'a> {
381+
fn new(tree: &'a LLTree<'a>, u: NodeId) -> Self {
382+
let c = match tree.left_child(u) {
383+
Some(x) => x,
384+
None => NodeId::NULL,
385+
};
386+
387+
ChildIterator {
388+
current_child: None,
389+
next_child: c,
390+
tree,
391+
}
392+
}
393+
}
394+
395+
impl NodeIterator for ChildIterator<'_> {
396+
fn next_node(&mut self) {
397+
self.current_child = match self.next_child {
398+
NodeId::NULL => None,
399+
r => {
400+
assert!(r >= 0);
401+
let cr = Some(r);
402+
debug_assert!(self.tree.right_sib(r).is_some());
403+
self.next_child = self.tree.right_sib(r).unwrap_or(NodeId::NULL);
404+
cr
405+
}
406+
};
407+
}
408+
409+
fn current_node(&mut self) -> Option<NodeId> {
410+
self.current_child
411+
}
412+
}

0 commit comments

Comments
 (0)