itertools icon indicating copy to clipboard operation
itertools copied to clipboard

Allow custom collections for multi cartesian product items

Open aschampion opened this issue 6 years ago • 0 comments

Allow MultiProduct to yield collections other than Vec. The main value is that callers can specify non-allocating types like SmallVec, meaning that iteration over a multi-cartesian product can be non-allocating. Creating the product itself is still an allocation, however.

To not be a breaking change, the multi_cartesian_product method still returns a product iterating over Vec (since method generics can not specify defaults), and a new generic method multi_cartesian_product_with is added (test with VecDeque included).

I'm open to suggestions for a better name for the new method.

As expected, there's no performance regression from master:

test multi_cartesian_product_fold             ... bench:     341,218 ns/iter (+/- 19,384)
test multi_cartesian_product_iterator         ... bench:     346,154 ns/iter (+/- 91,213)

This PR:

test multi_cartesian_product_fold             ... bench:     343,430 ns/iter (+/- 56,536)
test multi_cartesian_product_iterator         ... bench:     341,383 ns/iter (+/- 10,901)

aschampion avatar May 23 '19 12:05 aschampion