Added a prime sieve to NBKCoreKit.
GitHub (v0.16.0...v0.17.0)
- #114 A prime sieve
NBKPrimeSieve
public final class NBKPrimeSieve {
/// Creates a new instance and sieves the first page.
public init(cache: Cache = .KiB(32), wheel: Wheel = .x07, culls: Culls = .x11, capacity: Int? = nil)
/// The highest value checked for primality.
public var limit: UInt { get }
/// A list of all primes from zero through `limit`.
public var elements: [UInt] { get }
/// Sieves the next page of numbers.
public func increment()
}
NBKPrimeSieve: Changelog
Time (s) to append primes up to 109 on a MacBook Pro, 13-inch, M1, 2020:
3.6
from7
by skipping even numbers.2.2
from3.6
by using [UInt] as a wannabe-bit-set.1.7
from2.2
by wheeling 3, 5, 7.1.5
from1.7
by using wrapping arithmetic in hotspot.0.9
from1.5
by chunking it (wheeling has not been reimplemented yet).0.8
from0.9
by reimplementing wheeling in increment().0.6
from0.8
with NBKPrimeSieve(cache: .KiB(128), wheel: .x11, culls: .x31).0.58
from0.64
by adding a capacity reservation option.