Skip to content

feat: DoubleEndedIterator for Iter on Arena. - #43

Merged
LPGhatguy merged 7 commits into
LPGhatguy:mainfrom
dannyhammer:double-ended-iterator
Aug 3, 2026
Merged

feat: DoubleEndedIterator for Iter on Arena.#43
LPGhatguy merged 7 commits into
LPGhatguy:mainfrom
dannyhammer:double-ended-iterator

Conversation

@dannyhammer

Copy link
Copy Markdown
Contributor

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.

@LPGhatguy

Copy link
Copy Markdown
Owner

Hey, sorry for the super long delay on this!

DoubleEndedIterator makes a lot of sense. I'll give this a review and we'll get this out the door! :D

dannyhammer and others added 3 commits August 3, 2026 10:13
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.
@LPGhatguy
LPGhatguy force-pushed the double-ended-iterator branch from 79be3b7 to d5349fa Compare August 3, 2026 14:13
@LPGhatguy

Copy link
Copy Markdown
Owner

I reworked how the iterator types are structured using Enumerate<T> which simplified the slot tracking and made the forward+backward iteration cases look pretty much the same.

Going forward with this version. Thank you very much for the test case and starting the work on this!

@LPGhatguy
LPGhatguy merged commit 1e371f9 into LPGhatguy:main Aug 3, 2026
2 checks passed
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.

2 participants