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.6from7by skipping even numbers.2.2from3.6by using [UInt] as a wannabe-bit-set.1.7from2.2by wheeling 3, 5, 7.1.5from1.7by using wrapping arithmetic in hotspot.0.9from1.5by chunking it (wheeling has not been reimplemented yet).0.8from0.9by reimplementing wheeling in increment().0.6from0.8with NBKPrimeSieve(cache: .KiB(128), wheel: .x11, culls: .x31).0.58from0.64by adding a capacity reservation option.