From cb066915a34b1baca3e2cf1ffa629c02c32e0911 Mon Sep 17 00:00:00 2001 From: Philippe-Cholet <44676486+Philippe-Cholet@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:15:10 +0200 Subject: [PATCH] Update `CombinationsWithReplacement::next` (2) Use `pool.get_at` once! That way, `next` and `nth` will ressemble each other. --- src/combinations_with_replacement.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/combinations_with_replacement.rs b/src/combinations_with_replacement.rs index 1e2126c1a..7acfee898 100644 --- a/src/combinations_with_replacement.rs +++ b/src/combinations_with_replacement.rs @@ -94,22 +94,15 @@ where type Item = Vec; fn next(&mut self) -> Option { - // If this is the first iteration, return early if self.first { // In empty edge cases, stop iterating immediately - return if !(self.indices.is_empty() || self.pool.get_next()) { - None - // Otherwise, yield the initial state - } else { - self.first = false; - Some(self.pool.get_at(&self.indices)) - }; - } - - if self.increment_indices() { + if !(self.indices.is_empty() || self.pool.get_next()) { + return None; + } + self.first = false; + } else if self.increment_indices() { return None; } - Some(self.pool.get_at(&self.indices)) }