Skip to content

Commit

Permalink
New private method Powerset::increment_k
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed May 2, 2024
1 parent 350b948 commit cd2a80b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/powerset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ where
}
}

impl<I: Iterator> Powerset<I> {
/// Returns true if `k` has been incremented, false otherwise.
fn increment_k(&mut self) -> bool {
if self.combs.k() < self.combs.n() || self.combs.k() == 0 {
self.combs.reset(self.combs.k() + 1);
true
} else {
false
}
}
}

impl<I> Iterator for Powerset<I>
where
I: Iterator,
Expand All @@ -52,8 +64,7 @@ where
fn next(&mut self) -> Option<Self::Item> {
if let Some(elt) = self.combs.next() {
Some(elt)
} else if self.combs.k() < self.combs.n() || self.combs.k() == 0 {
self.combs.reset(self.combs.k() + 1);
} else if self.increment_k() {
self.combs.next()
} else {
None
Expand Down

0 comments on commit cd2a80b

Please sign in to comment.