Skip to content

Commit

Permalink
Permutations: use boxed slices internally
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet authored and phimuemue committed Jan 25, 2024
1 parent b785403 commit 8dd75f1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/permutations.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::boxed::Box;
use alloc::vec::Vec;
use std::fmt;
use std::iter::once;
Expand Down Expand Up @@ -33,8 +34,8 @@ enum PermutationState {
Buffered { k: usize, min_n: usize },
/// All values from the iterator are known so `n` is known.
Loaded {
indices: Vec<usize>,
cycles: Vec<usize>,
indices: Box<[usize]>,
cycles: Box<[usize]>,
},
/// No permutation left to generate.
End,
Expand Down Expand Up @@ -89,8 +90,8 @@ where
} else {
let n = *min_n;
let prev_iteration_count = n - *k + 1;
let mut indices: Vec<_> = (0..n).collect();
let mut cycles: Vec<_> = (n - k..n).rev().collect();
let mut indices: Box<[_]> = (0..n).collect();
let mut cycles: Box<[_]> = (n - k..n).rev().collect();
// Advance the state to the correct point.
for _ in 0..prev_iteration_count {
if advance(&mut indices, &mut cycles) {
Expand Down

0 comments on commit 8dd75f1

Please sign in to comment.