Skip to content

feat: DoubleEndedIterator for Iter on Arena.#43

Open
dannyhammer wants to merge 1 commit into
LPGhatguy:mainfrom
dannyhammer:double-ended-iterator
Open

feat: DoubleEndedIterator for Iter on Arena.#43
dannyhammer wants to merge 1 commit into
LPGhatguy:mainfrom
dannyhammer:double-ended-iterator

Conversation

@dannyhammer

Copy link
Copy Markdown

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.

Implementation of `DoubleEndedIterator`trait on the `Iter` type for `Arena`, including two additional unit tests `iter_rev()` and `iter_both_directions()` in `iter/iters.rs` to confirm expected behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant