daggy icon indicating copy to clipboard operation
daggy copied to clipboard

Iterator over tree ends

Open ghost opened this issue 7 years ago • 2 comments

Is there a walker method that efficiently returns the elements at the end of the tree (leaves)?

I took a look at the raw nodes and it looks like all of the leaf nodes have a next value that looks like next: [EdgeIndex(End), EdgeIndex(6)]. So I could call filter on a recursive walk over all of the nodes in the tree or on .raw_nodes() and check if next[0] == EdgeIndex(End), but that seems like a waste. Is there a better way to do this using the currently available API?

ghost avatar Mar 27 '17 16:03 ghost

For reference, this is an example of what I'm going with for now:

let end_index = EdgeIndex::<u32>::end();
let leaves: Vec<Node> = tree.raw_nodes().iter().filter(|&node| {
      node.next_edge(EdgeDirection::Outgoing) == end_index
    }).collect();

ghost avatar Mar 28 '17 03:03 ghost

Related: https://github.com/mitchmindtree/daggy/issues/24

hellow554 avatar Dec 19 '18 15:12 hellow554