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

Complete Permutations::size_hint #739

Merged
merged 9 commits into from
Sep 6, 2023
15 changes: 14 additions & 1 deletion src/permutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,20 @@ where
upp = upp.and_then(|n| CompleteState::Start { n, k }.remaining());
(low, upp)
}
PermutationState::OngoingUnknownLen { .. } => (0, None), // TODO can we improve this lower bound?
PermutationState::OngoingUnknownLen { k, min_n } => {
let prev_iteration_count = min_n - k + 1;
let (mut low, mut upp) = self.vals.size_hint();
low = CompleteState::Start { n: low, k }
.remaining()
.unwrap_or(usize::MAX)
.saturating_sub(prev_iteration_count);
upp = upp.and_then(|n| {
CompleteState::Start { n, k }
.remaining()
.map(|count| count.saturating_sub(prev_iteration_count))
jswrenn marked this conversation as resolved.
Show resolved Hide resolved
});
(low, upp)
}
PermutationState::Complete(ref state) => match state.remaining() {
Some(count) => (count, Some(count)),
None => (::std::usize::MAX, None)
Expand Down