Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily compute Iterator len #295

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

Dr-Emann
Copy link
Member

@Dr-Emann Dr-Emann commented Oct 16, 2024

Lazily compute the length of an iterator, rather than doing so eagerly at creation time.

Additionally, add more efficient implementations of count, nth, and nth_back.

This required somewhat manually reimplementing std::iter::Flatten, but this is something we'll need to do anyway for #290 / #287.

This is currently built on top of #292, (so the PR currently includes commits from that PR too)

Fixes #294

@Dr-Emann Dr-Emann force-pushed the push-wlprxywvqwns branch 4 times, most recently from d38a11a to 55f5f85 Compare October 17, 2024 01:27
Copy link
Member

@Kerollmops Kerollmops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent implementation of the option 1. Also, when you said that it is O(n), this n is the number of containers, so it's ok and even only called when calling size_hint, so that's pretty good.

I'm just thinking that when you call collect into a Vec, for example, the implementation will call size_hint 🤔 Anyway, it's still much better.

I let you rebase on main, flatten in a single commit and I'll merge, thank you again! Nice work 👌

This means the price of visting every container is only paid when needed: e.g.
when calling `.collect()`

This adds more efficent overrides for `count`, `nth` and `nth_back`, and
implements `FusedIterator`
@Dr-Emann
Copy link
Member Author

@Kerollmops Believe this is ready

Copy link
Member

@Kerollmops Kerollmops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful addition! Thank you! Merging 🙏

@Kerollmops Kerollmops merged commit 07d6bc3 into RoaringBitmap:main Oct 30, 2024
4 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.

Consider removing exact size_hint tracking in iterators
2 participants