Skip to content

v0.17.0

Latest
Compare
Choose a tag to compare
@oscbyspro oscbyspro released this 06 Dec 13:10
· 197 commits to main since this release

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 from 7 by skipping even numbers.
  • 2.2 from 3.6 by using [UInt] as a wannabe-bit-set.
  • 1.7 from 2.2 by wheeling 3, 5, 7.
  • 1.5 from 1.7 by using wrapping arithmetic in hotspot.
  • 0.9 from 1.5 by chunking it (wheeling has not been reimplemented yet).
  • 0.8 from 0.9 by reimplementing wheeling in increment().
  • 0.6 from 0.8 with NBKPrimeSieve(cache: .KiB(128), wheel: .x11, culls: .x31).
  • 0.58 from 0.64 by adding a capacity reservation option.