Skip to content

Commit

Permalink
CombinationsWithReplacement::nth: slightly faster fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Apr 26, 2024
1 parent a250651 commit 210e6e4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/combinations_with_replacement.rs
Expand Up @@ -107,16 +107,17 @@ where
}

fn nth(&mut self, n: usize) -> Option<Self::Item> {
if self.first {
let times = if self.first {
// In empty edge cases, stop iterating immediately
if !(self.indices.is_empty() || self.pool.get_next()) {
return None;
}
self.first = false;
} else if self.increment_indices() {
return None;
}
for _ in 0..n {
n
} else {
n + 1
};
for _ in 0..times {
if self.increment_indices() {
return None;
}
Expand Down

0 comments on commit 210e6e4

Please sign in to comment.