indextree
indextree copied to clipboard
Iterate over Arena in Depth-first order
Hi,
Is there anyway to iterate over all the nodes in an Arena in a depth-first order (iter seems to be in storage order). At the moment, I'm tracking all the root nodeid's (during insertion) in a separate vec, and, then iterating over each of their descendants. I was wondering, if there is a better way to do this? Thanks
Note that this is implemented to NodeId, not arena, because the arena can have multiple unordered top-level nodes. Currently there seems no ways to get toplevel nodes efficiently...
Creating virtual root nodes and using it as the parent of actual top-level nodes would be a workaround.
Note that this is implemented to NodeId, not arena, because the arena can have multiple unordered top-level nodes. Currently there seems no ways to get toplevel nodes efficiently...
Makes sense.
Creating virtual root nodes and using it as the parent of actual top-level nodes would be a workaround.
Having a top level (virtual) l node would still require tracking (passing around) an entity that is external to the arena. Wish there was an easier way to track/get the toplevel nodes, but, this works for now :)
Edit: Added virtual to make clear that the node to be tracked is virtual
I was wondering if arena could have this functionality built in.
I can workaround this issue with the above mentioned virtual root node trick or tracking top level nodes methods, but is this really that hard to implement into the crate itself?
Can arena maybe have a method to return all top level nodes maybe? Then I can simply call descendants on those top level nodes.