Skip to content
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

Powerset count #735

Merged
merged 11 commits into from
Aug 26, 2023
11 changes: 11 additions & 0 deletions src/powerset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ impl<I> Iterator for Powerset<I>
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
let k = self.combs.k();
// Total bounds for source iterator.
let (n_min, n_max) = self.combs.src().size_hint();
// Total bounds for the current combinations.
let (mut low, mut upp) = self.combs.size_hint();
low = remaining_for(low, n_min, k).unwrap_or(usize::MAX);
upp = upp.and_then(|upp| remaining_for(upp, n_max?, k));
Philippe-Cholet marked this conversation as resolved.
Show resolved Hide resolved
(low, upp)
}

Philippe-Cholet marked this conversation as resolved.
Show resolved Hide resolved
fn count(self) -> usize {
let k = self.combs.k();
let (n, combs_count) = self.combs.n_and_count();
Expand Down