Skip to content

Commit e71604f

Browse files
authored
Housekeeping: Rust/solution_1 updates (#801)
1 parent 37eea50 commit e71604f

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

PrimeRust/solution_1/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# cargo to load the package index from crates.io.
1111
# This allows it to be cached as part of the build
1212
# layer, saving a lot of time on repeated builds.
13-
FROM rust:1.54 AS build
13+
FROM rust:1.57 AS build
1414
RUN cargo search num_cpus -q --limit 1
1515

1616
WORKDIR /app

PrimeRust/solution_1/prime-sieve-rust/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "prime-sieve-rust"
33
version = "0.1.0"
44
authors = ["Michael Barber <60610888+mike-barber@users.noreply.github.com>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

PrimeRust/solution_1/prime-sieve-rust/src/unrolled.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ fn reinterpret_slice_mut_u64_u8(words: &mut [u64]) -> &mut [u8] {
9292
/// approach combined with the elements of the dense-resetting approach in my `bit-storage-striped-hybrid`
9393
/// solution.
9494
pub struct FlagStorageUnrolledHybrid {
95-
words: Vec<u64>,
95+
words: Box<[u64]>,
9696
length_bits: usize,
9797
}
9898

9999
impl FlagStorage for FlagStorageUnrolledHybrid {
100100
fn create_true(size: usize) -> Self {
101101
let num_words = size / 64 + (size % 64).min(1);
102102
Self {
103-
words: vec![0; num_words],
103+
words: vec![0; num_words].into_boxed_slice(),
104104
length_bits: size,
105105
}
106106
}
@@ -118,10 +118,10 @@ impl FlagStorage for FlagStorageUnrolledHybrid {
118118
/// ```ignore
119119
/// // dense reset
120120
/// match skip {
121-
/// 3 => ResetterDenseU64::<3>::reset_dense(&mut self.words),
122-
/// 5 => ResetterDenseU64::<5>::reset_dense(&mut self.words),
121+
/// 3 => ResetterDenseU64::<3>::reset_dense(self.words.as_mut()),
122+
/// 5 => ResetterDenseU64::<5>::reset_dense(self.words.as_mut()),
123123
/// //... etc
124-
/// 129 => ResetterDenseU64::<129>::reset_dense(&mut self.words),
124+
/// 129 => ResetterDenseU64::<129>::reset_dense(self.words.as_mut()),
125125
/// _ => debug_assert!(false, "this case should not occur"),
126126
/// },
127127
/// ```
@@ -135,7 +135,7 @@ impl FlagStorage for FlagStorageUnrolledHybrid {
135135
3,
136136
2,
137137
17,
138-
ResetterSparseU8::<N>::reset_sparse(&mut self.words, skip),
138+
ResetterSparseU8::<N>::reset_sparse(self.words.as_mut(), skip),
139139
debug_assert!(
140140
false,
141141
"this case should not occur skip {} equivalent {}",
@@ -151,7 +151,7 @@ impl FlagStorage for FlagStorageUnrolledHybrid {
151151
3,
152152
2,
153153
129, // 64 unique sets
154-
ResetterDenseU64::<N>::reset_dense(&mut self.words),
154+
ResetterDenseU64::<N>::reset_dense(self.words.as_mut()),
155155
debug_assert!(
156156
false,
157157
"dense reset function should not be called for skip {}",

PrimeRust/solution_1/prime-sieve-rust/src/unrolled_extreme.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use crate::{
1313
/// Performance, as a result, is very similar. This method has a slight edge over the const-generics, and is
1414
/// primarily included to demonstrate how this approach can be used in Rust.
1515
pub struct FlagStorageExtremeHybrid {
16-
words: Vec<u64>,
16+
words: Box<[u64]>,
1717
length_bits: usize,
1818
}
1919

2020
impl FlagStorage for FlagStorageExtremeHybrid {
2121
fn create_true(size: usize) -> Self {
2222
let num_words = size / 64 + (size % 64).min(1);
2323
Self {
24-
words: vec![0; num_words],
24+
words: vec![0; num_words].into_boxed_slice(),
2525
length_bits: size,
2626
}
2727
}
@@ -40,7 +40,7 @@ impl FlagStorage for FlagStorageExtremeHybrid {
4040
3,
4141
2,
4242
17,
43-
ResetterSparseU8::<N>::reset_sparse(&mut self.words, skip),
43+
ResetterSparseU8::<N>::reset_sparse(self.words.as_mut(), skip),
4444
debug_assert!(
4545
false,
4646
"this case should not occur skip {} equivalent {}",
@@ -51,7 +51,7 @@ impl FlagStorage for FlagStorageExtremeHybrid {
5151
}
5252

5353
// dense resets for all odd numbers in {3, 5, ... =129}
54-
let words = &mut self.words[..];
54+
let words = self.words.as_mut();
5555
extreme_reset!(skip);
5656
}
5757

0 commit comments

Comments
 (0)