daggy icon indicating copy to clipboard operation
daggy copied to clipboard

Provide roots (and leafs) method

Open hellow554 opened this issue 6 years ago • 3 comments

roots returns a struct that let you iterate over all nodes that have no incoming edges. leafs no outgoing.

Tell me what you think about this, I'll try to implement it then.

hellow554 avatar Dec 15 '18 21:12 hellow554

This sounds very useful and would be a welcome addition!

mitchmindtree avatar Dec 16 '18 13:12 mitchmindtree

I started implementing it and quickly noticed that it's harder than I thought. All impls of the Walker trait require a starting node, but I about iterating over every root node, so I'm not quiet sure if I can use the Walker trait at all. I guess I have to create a new one, that doesn't need a NodeId to start with?

Or would you be fine by using the Iterator trait, but that means borrowing of the Dag.

hellow554 avatar Dec 19 '18 15:12 hellow554

@hellow554 if there doesn't seem to be a nice solution with the Walker trait I would be content with an Iterator that borrowed the Dag. It would still be very useful even if a user just wanted to collect each of the roots/leaves into a collection before then iterating over them in a way that doesn't borrow the Dag.

If you do have an approach in mind that allows for iterating over roots/leaves without borrowing the Dag but is not suited to a Walker impl, perhaps this could simply be done with an inherent impl? I don't think we need to introduce another trait if this new type is the only one likely to implement it.

Thanks for taking a stab at this btw!

mitchmindtree avatar Dec 26 '18 06:12 mitchmindtree