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

allows initializing WeightedShuffle with an ExactSizeIterator #4796

Conversation

behzadnouri
Copy link

Problem

Using an ExactSizeIterator instead of a slice may allow to bypass the allocation to collect an iterator into a vector.

Summary of Changes

The commit allows initializing WeightedShuffle with an ExactSizeIterator.

@behzadnouri behzadnouri force-pushed the weighted-shuffle-weights-exact-size-iter branch from ad3af77 to 1a9e088 Compare February 5, 2025 00:23
Using an ExactSizeIterator instead of a slice may allow to bypass the
allocation to collect an iterator into a vector.
@behzadnouri behzadnouri force-pushed the weighted-shuffle-weights-exact-size-iter branch from 1a9e088 to 1f6b51e Compare February 5, 2025 00:26
Copy link

@gregcusack gregcusack left a comment

Choose a reason for hiding this comment

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

looks good. but what do you mean by "may" here: "Using an ExactSizeIterator instead of a slice may allow to bypass the allocation to collect an iterator into a vector."

@behzadnouri
Copy link
Author

looks good. but what do you mean by "may" here: "Using an ExactSizeIterator instead of a slice may allow to bypass the allocation to collect an iterator into a vector."

Not every iterator is an ExactSizeIterator.
So if you have an iterator which is not ExactSizeIterator you still need to collect::<Vec<_>>() before you can it pass it here.

Copy link

@gregcusack gregcusack left a comment

Choose a reason for hiding this comment

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

lgtm!

@behzadnouri behzadnouri merged commit b538fab into anza-xyz:master Feb 5, 2025
66 checks passed
@behzadnouri behzadnouri deleted the weighted-shuffle-weights-exact-size-iter branch February 5, 2025 16:29
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