Allow for providing a custom sieve size.

This commit is contained in:
2025-12-10 13:57:23 +01:00
parent f5b971e35f
commit 0b391ed590
2 changed files with 8 additions and 5 deletions

View File

@@ -19,6 +19,9 @@ Import prime numbers from \fIFILE\fR
\fB\-t\fR, \fB\-\-test\fR
Test if n is a prime instead of generation
.TP
\fB\-s\fR, \fB\-\-sieve\fR
Set a custom sieve size
.TP
\fB\-v\fR, \fB\-\-verbose\fR
Print all found primes
.TP

View File

@@ -35,12 +35,12 @@ struct Opt {
test:bool,
#[structopt(help = "Max of the prime to generate or number to test for primality")]
num:usize,
#[structopt(short, long, default_value = "1000", help = "Set a custom sieve size")]
sieve:usize,
//#[structopt(short, long, name = "n", default_value = "1", help = "Number of threads to spawn")]
//jobs:u64,
}
const SEGMENT_SIZE:usize = 0x100000000;
fn main() {
let opts = Opt::from_args();
let mut prime_list = Vec::new();
@@ -69,8 +69,8 @@ fn main() {
(*prime_list.last().unwrap() + 1) as usize
};
while start < opts.num {
let end = if start + SEGMENT_SIZE < opts.num {
start + SEGMENT_SIZE
let end = if start + opts.sieve < opts.num {
start + opts.sieve
} else {
opts.num + 1
};
@@ -83,7 +83,7 @@ fn main() {
}
prime_list.append(&mut new_primes);
start += SEGMENT_SIZE;
start += opts.sieve;
}
if opts.test {