@@ -345,22 +345,26 @@ where
345
345
fn new ( mut indices : I , offset : usize , n : usize ) -> Self {
346
346
let k = indices. as_mut ( ) . len ( ) ;
347
347
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
+ }
354
356
}
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." )
361
367
}
362
- } else {
363
- panic ! ( "Offset should be inside the bounds of the possible combinations." )
364
368
}
365
369
}
366
370
@@ -545,8 +549,10 @@ fn decrement_indices(indices: &mut [usize], n: usize) {
545
549
546
550
// Decrement index, and reset the ones to its right
547
551
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;
550
556
}
551
557
}
552
558
0 commit comments