Open installgentoo opened 5 months ago
I'm not sure what exactly your code is trying to do, but you can filter nodes by id using something like this:
arena
.iter()
.map(|node| arena.get_node_id(node).expect("conversion infallible for iteration"))
.filter(|node_id| my_cool_filter_function(node_id));
Arena::get_node_id
is actually quite cheap to call; it simply does some bound checks and constructs the NodeId
. It shouldn't be much more expensive than indexing into a Vec
.
I'm not sure what exactly your code is trying to do, but you can filter nodes by id using something like this:
arena .iter() .map(|node| arena.get_node_id(node).expect("conversion infallible for iteration")) .filter(|node_id| my_cool_filter_function(node_id));
Arena::get_node_id
is actually quite cheap to call; it simply does some bound checks and constructs theNodeId
. It shouldn't be much more expensive than indexing into aVec
.
i do
pub fn traverse<T>(a: &Arena<T>) -> impl '_ + Iterator<Item = NodeId> {
(1..=a.count()).map(|i| a.get_node_id_at(i.try_into().valid()).valid())
}
Seeing as i'm never gonna remove nodes in my specific code.
But my point is, the way to traverse ids should be there already. If you just iter -> map -> getnodeid, that method should be in the library. I, the user, do not know by default that this is cheap, and i should not even concern myself with this, as iterating over the keys/values is a very common case for a container. I initially expected arena.iter() to give you pairs.
Yeah, it'd be nice to have Arena::iter
return Iterator<Item = (&Node<T>, NodeId)>
, it'd also be cheap to do, since bound checking isn't needed for we already iterate over valid nodes.
How am i supposed to filter some ids from arena, for further manipulations? get_node_id searches the entire arena.
Also, how are you supposed to do memoized recursion
can't pass arena to to a method, if you're invoking it on something inside arena.