Skip to content

Commit 5bbbe24

Browse files
committed
Make Clippy happy
1 parent 73598ce commit 5bbbe24

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/iter/combinations.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,22 +345,26 @@ where
345345
fn new(mut indices: I, offset: usize, n: usize) -> Self {
346346
let k = indices.as_mut().len();
347347
let total = checked_binomial(n, k).expect(OVERFLOW_MSG);
348-
if offset == total {
349-
unrank(indices.as_mut(), offset - 1, n);
350-
Self {
351-
indices,
352-
n,
353-
position: IndicesPosition::End,
348+
match offset.cmp(&total) {
349+
Ordering::Equal => {
350+
unrank(indices.as_mut(), offset - 1, n);
351+
Self {
352+
indices,
353+
n,
354+
position: IndicesPosition::End,
355+
}
354356
}
355-
} else if offset < total {
356-
unrank(indices.as_mut(), offset, n);
357-
Self {
358-
indices,
359-
n,
360-
position: IndicesPosition::Middle,
357+
Ordering::Less => {
358+
unrank(indices.as_mut(), offset, n);
359+
Self {
360+
indices,
361+
n,
362+
position: IndicesPosition::Middle,
363+
}
364+
}
365+
Ordering::Greater => {
366+
panic!("Offset should be inside the bounds of the possible combinations.")
361367
}
362-
} else {
363-
panic!("Offset should be inside the bounds of the possible combinations.")
364368
}
365369
}
366370

@@ -545,8 +549,10 @@ fn decrement_indices(indices: &mut [usize], n: usize) {
545549

546550
// Decrement index, and reset the ones to its right
547551
indices[i] -= 1;
548-
for j in i + 1..indices.len() {
549-
indices[j] = n - k + j;
552+
for (j, index) in indices.iter_mut().enumerate().skip(i + 1) {
553+
*index = n - k + j;
554+
for (j, index) in indices.iter_mut().enumerate().skip(i + 1) {
555+
*index = n - k + j;
550556
}
551557
}
552558

0 commit comments

Comments
 (0)