From 06706479e25c51002fa24050d05e5e2d455fa4dd Mon Sep 17 00:00:00 2001 From: Philippe-Cholet <44676486+Philippe-Cholet@users.noreply.github.com> Date: Thu, 25 Jan 2024 13:59:09 +0100 Subject: [PATCH 1/2] `Permutations`: use boxed slices internally --- src/permutations.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/permutations.rs b/src/permutations.rs index 534ca59c9..cf5973c8c 100644 --- a/src/permutations.rs +++ b/src/permutations.rs @@ -1,3 +1,4 @@ +use alloc::boxed::Box; use alloc::vec::Vec; use std::fmt; use std::iter::once; @@ -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, - cycles: Vec, + indices: Box<[usize]>, + cycles: Box<[usize]>, }, /// No permutation left to generate. End, @@ -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) { From cc0123fecf3717513c2d90160ca59d8f893fbf75 Mon Sep 17 00:00:00 2001 From: Philippe-Cholet <44676486+Philippe-Cholet@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:03:24 +0100 Subject: [PATCH 2/2] `CombinationsWithReplacement`: use a boxed slice internally --- src/combinations_with_replacement.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/combinations_with_replacement.rs b/src/combinations_with_replacement.rs index 88d858b5f..ee3497849 100644 --- a/src/combinations_with_replacement.rs +++ b/src/combinations_with_replacement.rs @@ -1,3 +1,4 @@ +use alloc::boxed::Box; use alloc::vec::Vec; use std::fmt; use std::iter::FusedIterator; @@ -16,7 +17,7 @@ where I: Iterator, I::Item: Clone, { - indices: Vec, + indices: Box<[usize]>, pool: LazyBuffer, first: bool, } @@ -46,7 +47,7 @@ where I: Iterator, I::Item: Clone, { - let indices: Vec = alloc::vec![0; k]; + let indices = alloc::vec![0; k].into_boxed_slice(); let pool: LazyBuffer = LazyBuffer::new(iter); CombinationsWithReplacement {