Expand description
Cache-aware prime enumeration with a bit-packed segmented sieve.
Primer generates every prime number up to and including a supplied u64
limit. It tracks only odd candidates, stores one candidate per bit, and
reuses a fixed 32 KiB segment while crossing out composites.
§Memory model
SEGMENT_BYTES is the size of Primer’s reusable segment buffer. It is not
the total memory used by a call:
- bootstrap primes up to
sqrt(limit)require additional memory; - the returned
Vec<u64>stores every generated prime; - normal allocator and process overhead also apply.
Applications that do not want to retain every prime will eventually benefit from a streaming API; version 0.3 keeps the original vector-returning behaviour while establishing a conventional Cargo library interface.
§Example
use primer::sieve_primes;
let primes = sieve_primes(30);
assert_eq!(primes, vec![2, 3, 5, 7, 11, 13, 17, 19, 23, 29]);Constants§
- SEGMENT_
BITS - Number of odd candidates represented by one segment.
- SEGMENT_
BYTES - Size, in bytes, of Primer’s reusable segmented-sieve buffer.
Functions§
- segmented_
sieve - Compatibility name for
sieve_primes. - sieve_
primes - Generate all primes up to and including
limit.