@@ -96,8 +96,7 @@ impl<I: Iterator> Combinations<I> {
96
96
}
97
97
98
98
/// Initialises the iterator by filling a buffer with elements from the
99
- /// iterator, return a boolean indicating whether or not we've run out of
100
- /// combinations.
99
+ /// iterator. Returns true if there are no combinations, false otherwise.
101
100
fn init ( & mut self ) -> bool {
102
101
self . pool . prefill ( self . k ( ) ) ;
103
102
let done = self . k ( ) > self . n ( ) ;
@@ -110,9 +109,9 @@ impl<I: Iterator> Combinations<I> {
110
109
111
110
/// Increments indices representing the combination to advance to the next
112
111
/// (in lexicographic order by increasing sequence) combination. For example
113
- /// if we have n=3 & k=2 then [0, 1] -> [0, 2] -> [0, 3] -> [1, 2] -> ...
112
+ /// if we have n=4 & k=2 then ` [0, 1] -> [0, 2] -> [0, 3] -> [1, 2] -> ...`
114
113
///
115
- /// Returns a boolean indicating whether or not we've run out of combinations.
114
+ /// Returns true if we've run out of combinations, false otherwise .
116
115
fn increment_indices ( & mut self ) -> bool {
117
116
if self . indices . is_empty ( ) {
118
117
return true ; // Done
@@ -171,7 +170,7 @@ where
171
170
return self . next ( ) ;
172
171
}
173
172
174
- let mut done = if self . first {
173
+ let done = if self . first {
175
174
self . init ( )
176
175
} else {
177
176
self . increment_indices ( )
@@ -181,14 +180,13 @@ where
181
180
return None ;
182
181
}
183
182
184
- for _ in 0 ..( n - 1 ) {
185
- done = self . increment_indices ( ) ;
186
- if done {
183
+ for _ in 0 ..n {
184
+ if self . increment_indices ( ) {
187
185
return None ;
188
186
}
189
187
}
190
188
191
- self . next ( )
189
+ Some ( self . indices . iter ( ) . map ( |i| self . pool [ * i ] . clone ( ) ) . collect ( ) )
192
190
}
193
191
194
192
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
0 commit comments