Skip to content

Commit

Permalink
Specialize Powerset::nth
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed May 7, 2024
1 parent 54429a0 commit 0f3cbcc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/powerset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ where
}
}

fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
loop {
match self.combs.try_nth(n) {
Ok(item) => return Some(item),
Err(steps) => {
if !self.increment_k() {
return None;
}
n -= steps;
}
}
}
}

fn size_hint(&self) -> SizeHint {
let k = self.combs.k();
// Total bounds for source iterator.
Expand Down

0 comments on commit 0f3cbcc

Please sign in to comment.