Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/combinations_with_replacement.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::FusedIterator;
Expand All @@ -16,7 +17,7 @@ where
I: Iterator,
I::Item: Clone,
{
indices: Vec<usize>,
indices: Box<[usize]>,
pool: LazyBuffer<I>,
first: bool,
}
Expand Down Expand Up @@ -46,7 +47,7 @@ where
I: Iterator,
I::Item: Clone,
{
let indices: Vec<usize> = alloc::vec![0; k];
let indices = alloc::vec![0; k].into_boxed_slice();
let pool: LazyBuffer<I> = LazyBuffer::new(iter);

CombinationsWithReplacement {
Expand Down
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