rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.72k stars 309 forks source link

combinations: `count` and `size_hint` #729

Closed Philippe-Cholet closed 1 year ago

Philippe-Cholet commented 1 year ago

The indices we track (to give combinations in the lexicographic order) can help us count the remaining combinations.

@phimuemue That's all for combinations. Each commit is as small as possible. Similar work for other iterators to come, but this should be the biggest as it prepares work for powerset and combinations_with_replacement.

Philippe-Cholet commented 1 year ago

All changes are done (with a limit of 500 for test_checked_binomial). And I added a TODO about "sum of options" (possible for a MSRV of 1.37, currently 1.36) that would really make remaining_for more readable. (It also pass the test obviously.)

Ready to squash everything into one commit. And the next PR will be easier because of the changes done here.