LPGhatguy / thunderdome

Arena type inspired by generational-arena
Apache License 2.0
197 stars 15 forks source link

feat: `DoubleEndedIterator` for `Iter` on `Arena`. #43

Open dannyhammer opened 1 year ago

dannyhammer commented 1 year ago

Implementation of DoubleEndedIteratortrait on the Iter type for Arena, including two additional unit tests iter_rev() and iter_both_directions() in iter/iter.rs to confirm expected behavior.

I'm using thunderdome in another project, and I found myself needing to do arena.iter().collect::<Vec<_>>().into_par_iter().rev(), which is disgusting and not optimal. I looked into the iterator for Arena and saw that it was using a slice::Iter internally, which implements DoubleEndedIterator, so I made some additions and wrote some tests to confirm it works.

I hope the code aligns with your methodology. Given that arena.iter() doesn't define an explicit order, I see no reason why "backwards iteration" would yield undesirable outcomes. I am unsure if the check for self.slot > self.len on next() and next_back() is strictly necessary, but it felt appropriate to include.