daggy
daggy copied to clipboard
Provide roots (and leafs) method
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.
This sounds very useful and would be a welcome addition!
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 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!