Skip to content

Commit 8dd75f1

Browse files
Philippe-Choletphimuemue
authored andcommitted
Permutations: use boxed slices internally
1 parent b785403 commit 8dd75f1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/permutations.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::boxed::Box;
12
use alloc::vec::Vec;
23
use std::fmt;
34
use std::iter::once;
@@ -33,8 +34,8 @@ enum PermutationState {
3334
Buffered { k: usize, min_n: usize },
3435
/// All values from the iterator are known so `n` is known.
3536
Loaded {
36-
indices: Vec<usize>,
37-
cycles: Vec<usize>,
37+
indices: Box<[usize]>,
38+
cycles: Box<[usize]>,
3839
},
3940
/// No permutation left to generate.
4041
End,
@@ -89,8 +90,8 @@ where
8990
} else {
9091
let n = *min_n;
9192
let prev_iteration_count = n - *k + 1;
92-
let mut indices: Vec<_> = (0..n).collect();
93-
let mut cycles: Vec<_> = (n - k..n).rev().collect();
93+
let mut indices: Box<[_]> = (0..n).collect();
94+
let mut cycles: Box<[_]> = (n - k..n).rev().collect();
9495
// Advance the state to the correct point.
9596
for _ in 0..prev_iteration_count {
9697
if advance(&mut indices, &mut cycles) {

0 commit comments

Comments
 (0)