-
Notifications
You must be signed in to change notification settings - Fork 317
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
Faster skipping combinations with nth in Combinations #301
Comments
@Philippe-Cholet Hi there, a fairly efficient way to implement this would be to use the combinatorial number system to compute the indices of the Nth combination. (See this wikipedia article for the basic idea). However, this is complicated by the fact that
To compute the indices belonging to the Nth combination using this 'reversed' ordering, we would need to know the total number of elements so that we can 'invert' the indices: The alternative, which I think #329 pursued, is to repeatedly 'increment' the indices in the way that the |
@kinto-b I disagree on no real efficiency gain of #329 because the generated type |
@Philippe-Cholet Thanks for your prompt reply, and good point! Please see #914 :) |
Solved by #914. |
In
impl Iterator for Combinations
, only thenext
method is defined. It shouldn't be too difficult to permit skipping through combinations, so thatvec![1, 2, 3, 4].into_iter().combinations(2).nth(4)
doesn't unnecessarily waste time going through the first four iterations just to get to the fifth.To do this,
Combinations
would need a field that kept track of how many iterations have already been made (this may replace thefirst
bool field), itsindices
field would need to be settable immediately depending on the iteration number, andnth
should thus be defined (save some pool-filling).The text was updated successfully, but these errors were encountered: