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 Apr 26, 2024
1 parent fae2122 commit 0726a3c
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(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 0726a3c

Please sign in to comment.