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 2, 2024
1 parent cd2a80b commit 125a19b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/powerset.rs
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(remaining) => {
if !self.increment_k() {
return None;
}
n = remaining;
}
}
}
}

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

0 comments on commit 125a19b

Please sign in to comment.