Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement sieve_lt, sieve_geq and sieve_segment, as well as their supporting types #21

Merged
merged 22 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ to store in the binary and the size of the sieve used during evaluation. The sie
of the square root of the largest encountered value:
```rust
// ceil(sqrt(5_000_000_063)) = 70_711
const PRIMES_GEQ: Result<[u64; 3], const_primes::Error> = primes_geq::<3, 70_711>(5_000_000_031);
const PRIMES_GEQ: Result<[u64; 3], GenerationError> = primes_geq::<3, 70_711>(5_000_000_031);
assert_eq!(PRIMES_GEQ, Ok([5_000_000_039, 5_000_000_059, 5_000_000_063]));
```
```rust
const N: usize = 70711;
const PRIME_STATUS_LT: [bool; N] = sieve_lt(5_000_000_031);
// 5_000_000_028 5_000_000_029 5_000_000_030
assert_eq!(PRIME_STATUS_LT[N - 3..], [false, true, false]);
const PRIME_STATUS_LT: Result<[bool; N], SieveError> = sieve_lt::<3, 70_711>(5_000_000_031);
// 5_000_000_028 5_000_000_029 5_000_000_030
assert_eq!(PRIME_STATUS_LT, Ok([false, true, false]));
```
The sieving functions have yet to be modified for two generics, and must save the entire sieve in the binary.
The sieve size can be computed by the crate by using the macro `primes_segment!` and `sieve_segment!`.
## Other functionality
Use `is_prime` to test whether a given number is prime:
```rust
Expand Down
4 changes: 2 additions & 2 deletions benches/prime_benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ fn benchmarks(c: &mut Criterion) {
b.iter(|| black_box(sieve::<N>()))
});
sieving.bench_function(format!("{N} integers < 100000000"), |b| {
b.iter(|| black_box(sieve_lt::<N>(100000000)))
b.iter(|| black_box(sieve_lt::<N, N>(100000000)))
});
sieving.bench_function(format!("{N} integers >= 99990000"), |b| {
b.iter(|| black_box(sieve_geq::<N>(99990000)))
b.iter(|| black_box(sieve_geq::<N, N>(99990000)))
});
}
}
Expand Down
40 changes: 0 additions & 40 deletions src/error.rs

This file was deleted.

Loading
Loading