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

prunable combinations iterator #671

Closed danieleades closed 7 months ago

danieleades commented 1 year ago

This might be specific enough that i need to roll my own solution, but here goes.

I have a set of objects from which i need to iterate over all possible combinations. The combinations iterator is perfect, except...

basically i want to be able to use a predicate to prune combinations early. If I add the pruning step after the combinations function then it is prohibitively expensive to count the combinations, even if the total number of valid combinations is very small

Philippe-Cholet commented 1 year ago

You might have to roll your own solution (if you did not already did) but as I know the internal well enough after contributing to it, maybe this is simple/general enough.

First, what do you mean by early? Just to avoid to allocate each item to a vector but still going through them one by one? Or early knowing the X next items would be wrong? Something else?

There is tuple_combinations too, which has really different internals.