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

TupleCombinations: size_hint and count #763

Merged

Conversation

Philippe-Cholet
Copy link
Member

@Philippe-Cholet Philippe-Cholet commented Sep 27, 2023

This was definitely simpler to implement than it was for Combinations (with vector items). The only difficulty is that it's recursive with a macro.

According to my notes, all iterators that should have a size_hint specialization now have. I like that.

The count_ident macro is moved to be available library-wide.

`TupleCombinations` and `Tuple1Combination` merely wrap an iterator so I just call its `size_hint` method.
`Tuple2Combination` chains a wrapped `Tuple1Combination` with a smaller `Tuple2Combination` but this one is not initialized yet so it is full and therefore has `binomial(n, k)` elements.
Similar for `3..=12`, it's just recursive.
Same as `TupleCombinations::size_hint` but simpler.
@Philippe-Cholet
Copy link
Member Author

@jswrenn Ooops... I missed that checked_binomial in combinations.rs is behind the use_alloc feature. Where should I move it? In adaptors/mod.rs I guess as it seems to be the easiest move?

@jswrenn
Copy link
Member

jswrenn commented Sep 27, 2023

Yes, in adaptors/mod.rs is fine.

Just cut/paste, and fixed imports.
It is moved because it is now needed even without heap-allocation.
Copy link
Member

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

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

For consistency, could you add a specialization test for this to tests/specializations.rs?

@jswrenn jswrenn added this pull request to the merge queue Sep 28, 2023
Merged via the queue into rust-itertools:master with commit a9aaeb4 Sep 28, 2023
8 checks passed
@Philippe-Cholet Philippe-Cholet deleted the tuple-combinations-size branch September 28, 2023 20:25
@jswrenn jswrenn mentioned this pull request Nov 14, 2023
@jswrenn jswrenn added this to the next milestone Nov 14, 2023
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