-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Currently when e.g. iterating over children(node)
you can mutate the tree while the iteration is happening. This will likely lead to unexpected behavior (note: changing or updating the AbstractElement
is fine).
We should minimally document that you should not do that. However, I wonder if there is something else we could do to make sure that you don't get bad behavior. A few options:
-
Collect
Node
s into an array when iterator is constructed and then naively iterate over that array instead. If some of them get unlinked etc., then that won't affect the iteration per se. However, this will mean allocating a potentially big array (especially in the whole-tree case).. we could have an keyword argument for iterator functions to allow for unsafe, but efficient iteration (e.g.children(node, unsafe=true)
? -
Make the tree immutable during iterators. This would mean attaching some global metadata to each node (e.g. something as simple as a
Ref{Bool}
).