More size_hint and count methods#725
Conversation
As I intend to improve the `permutations` algorithm, I first wanted to simplify a few things: - `CompleteStateRemaining` basically stands for `Option<usize>` without its usuability. A doc comment seems enough. - `prefill` is way clearer to see if there are enough values. - `CompleteState::count` method rather than an one-off function. - `0..=x` instead of `0..(x+1)` ; one more fold. Then I encountered a TODO that I fixed: It makes sense to have a `LazyBuffer::size_hint` method which greatly helps in fixing `Permutations::size_hint` and therefore correctly allocate the memory for codes like `(0..n).permutations(k).map(...).collect_vec()`. I think we need to be able to apply any function to both bounds of a `SizeHint`. Here, it avoid repetition and therefore readability. Then permutations' size hints are tested.
size_hint for permutations
|
Size hints for |
|
And |
size_hint for permutationssize_hint and count methods
|
Thanks @Philippe-Cholet, that's quite a bit. I started reviewing the first commit, and if we include this, could we first focus on Please let me know if I'm wrong here. |
|
You're right and it's done (in a new commit), the iterator is fused. I only used it in my EDIT: Yes, that's quite a bit, I started small and each time I saw another related thing to do. |
|
I just noticed that a few |
|
Would you mind doing the lazy buffer in a separate PR? (So we could establish a clean base line.) |
|
All depends on that but ok. |
|
I don’t want to force you to do anything, but I see that the PRs are generally good, but broad. Having smaller PRs helps tremendously with reviewing, and I hope that we can merge them faster this way. |
|
I'm willing to learn how to do things in any better way. The first commit here is big because of I previously started from an outdated master branch, realized that later on and because I was unsure what to do with git, I started again and it resulted in a big commit I did not have the heart to split. But I agree that my first commit is broad, I was a bit overzealous. |
No worries! I really want to include your ideas, but do not have much time at hand, so I try to streamline the review process (admittedly: streamline it on my side) - reviewing (very) small-bite chunks separately is usually easier than looking reviewing the "sum of the chunks" at once. |
|
Well I'm closing this, it became too broad but it will make 4 or 5 nice smaller PR. Let's consider this as a draft. |
As I intend to improve the
permutationsalgorithm (related to #722), I first wanted to simplify a few things:CompleteStateRemainingbasically stands forOption<usize>without its usuability. A doc comment seems enough.prefillis way clearer to see if there are enough values.CompleteState::countmethod rather than an one-off function.0..=xinstead of0..(x+1); one more fold.Then I encountered a TODO that I fixed:
It makes sense to have a
LazyBuffer::size_hintmethod which greatly helps in fixingPermutations::size_hintand therefore correctly allocate the memory for codes like(0..n).permutations(k).map(...).collect_vec().I think we need to be able to apply a function to both bounds of a
SizeHint. Here, it avoids repetition and therefore readability.Then permutations' size hints are tested.