combinatoricslib
combinatoricslib copied to clipboard
Using an iterator rather than a vector?
From PeterVermont on December 19, 2012 23:40:45
I would like the equivalent of the Python itertools.combinations(iterable, r)
See: http://docs.python.org/2/library/itertools.html#itertools.combinations I wish to make a SimpleCombination of Integers over a range. As best as I can tell, all of your code requires generating a vector the size of the entire range which could be hundreds of thousands.
Thanks!
Original issue: http://code.google.com/p/combinatoricslib/issues/detail?id=5
From PeterVermont on December 20, 2012 10:26:45
On using the library I understand better why the code is structured as it is -- given that you are going to returning the vector objects in the combinations, there is little harm in having the user create them up front. I can also use the Range factory method.
I ended up really liking this way of doing things. By changing the items I sent in my original vector I got very useful control over exactly what was iterated which eliminated costly post hoc filtering.
It still might be useful to not require a vector in which case you would return a combination just made of indices into a specified range.