Complete Permutations::size_hint#739
Merged
bors[bot] merged 9 commits intoSep 6, 2023
Merged
Conversation
Known/Overflow variants have the advantage of the readability but it's less handy than options. A doc comment seems enough to me to say that None means it would overflow.
Clearer. And `prefill` extending the buffer seems better performance wise than push items to the buffer one by one with `get_next`.
We are at the very beginning. We prefilled `k` values, but did not generate any item yet. There are `n!/(n-k)!` items to come (safely done in remaining). But `n` might be unknown.
We generated `prev_iteration_count` items (`n` still unknown). So the same as `PermutationState::StartUnknownLen` minus `prev_iteration_count`.
jswrenn
requested changes
Aug 31, 2023
phimuemue
requested changes
Sep 5, 2023
Ideally, the lower bound of the size hint would remain `usize::MAX` but I don't see how we could make this happen. Small bugfix: `n+1` might overflow.
jswrenn
approved these changes
Sep 6, 2023
Member
|
bors r+ |
Contributor
|
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@phimuemue
This series of size hint/count improvements ends where it started: with a TODO I wanted to fix.
The end user will mostly enjoy that
(0..n).permutations(k).map(...).collect_vec()will now allocate to the resulting vector in one go (PermutationState::StartUnknownLencase).In the first commit, you probably will want me to unwrap but
panic!(message)is more similar toexpectthanunwrap. Which is why I previously usedexpecttoo.The 2nd commit (about
enough_vals) is off topic but I really don't see why it would not be a (minor) improvement.I have a test
permutations_inexact_size_hintsready if you want (similar tocombinations_inexact_size_hints).