| Crates.io | sieve-of-eratosthenes |
| lib.rs | sieve-of-eratosthenes |
| version | 0.1.2 |
| created_at | 2026-01-04 15:46:49.945023+00 |
| updated_at | 2026-01-04 18:03:53.90965+00 |
| description | A standard implementation of the Sieve of Eratosthenes |
| homepage | |
| repository | https://github.com/michaeltinsley/rust-fundamentals |
| max_upload_size | |
| id | 2022089 |
| size | 22,164 |
A high-performance, memory-efficient, and portable implementation of the Sieve of Eratosthenes algorithm in Rust.
This library is designed for speed and efficiency, using a bit-packed representation (SWAR) to minimize memory usage and maximize CPU cache locality.
Vec<usize> bit-packing (~1 bit per number).unsafe blocks required for public API).Add this to your Cargo.toml:
[dependencies]
sieve-of-eratosthenes = "0.1.0"
use sieve_of_eratosthenes::SieveOfEratosthenes;
fn main() {
// Find all primes up to 100
let sieve = SieveOfEratosthenes::new(100);
// Check individual numbers (O(1) lookup)
assert!(sieve.is_prime(2));
assert!(sieve.is_prime(97));
assert!(!sieve.is_prime(100)); // 100 is composite
// Iterate over primes
for prime in sieve.iter() {
println!("{}", prime);
}
}