From b477f9133d5c77856c1a4add706f0e7629d515a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Bystr=C3=B6m=20Ericsson?= Date: Wed, 6 Dec 2023 12:43:23 +0100 Subject: [PATCH] Cleanup (#114). --- Sources/NBKCoreKit/Models/NBKPrimeSieve.swift | 12 +++++++++++- Tests/NBKCoreKitTests/Models/NBKPrimeSieve.swift | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/NBKCoreKit/Models/NBKPrimeSieve.swift b/Sources/NBKCoreKit/Models/NBKPrimeSieve.swift index 69833e4d..4f2b29dd 100644 --- a/Sources/NBKCoreKit/Models/NBKPrimeSieve.swift +++ b/Sources/NBKCoreKit/Models/NBKPrimeSieve.swift @@ -131,7 +131,10 @@ extension NBKPrimeSieve { // MARK: Transformations //=------------------------------------------------------------------------= - /// Sieves the next page of ``NBKPrimeSieve/increment`` number of values. + /// Sieves the next page of numbers. + /// + /// A page contains `1` odd number per bit in `cache`. + /// @inline(never) @inlinable public func increment() { Swift.assert(self.cache.base.allSatisfy({ $0.onesComplement().isZero })) //=--------------------------------------= @@ -587,6 +590,9 @@ extension NBKPrimeSieve { //=--------------------------------------------------------------------= /// Patterns grow multiplicatively, so chunking reduces memory cost. + /// + /// g([3, 5, 7, 11, 13]) -> [f([2, 13]), f([5, 11]), f([7])] + /// @usableFromInline static func patterns(primes: [UInt]) -> [[UInt]] { var patterns = [[UInt]]() var lhsIndex = primes.startIndex @@ -605,6 +611,10 @@ extension NBKPrimeSieve { return patterns as [[UInt]] } + /// A cyclical pattern marking each odd multiple of prime in `primes`. + /// + /// - Note: The sieve culls even numbers by omission. + /// @usableFromInline static func pattern(primes: [UInt]) -> [UInt] { var pattern = [UInt](repeating: UInt.max, count: Int(primes.reduce(1, *))) var next:(prime: UInt, product: UInt); next.prime = primes.first!; next.product = next.prime diff --git a/Tests/NBKCoreKitTests/Models/NBKPrimeSieve.swift b/Tests/NBKCoreKitTests/Models/NBKPrimeSieve.swift index 58f9ed96..65ef48c0 100644 --- a/Tests/NBKCoreKitTests/Models/NBKPrimeSieve.swift +++ b/Tests/NBKCoreKitTests/Models/NBKPrimeSieve.swift @@ -295,7 +295,7 @@ final class NBKPrimeSieveTests: XCTestCase { let/**/ cache: T.Cache = T.Cache.words(256 / UInt.bitWidth) for/**/ wheel: T.Wheel in [.x02, .x03, .x05, .x07, .x11] { for culls: T.Culls in [.x11, .x13, .x17, .x19, .x23, .x29, .x31] { - let ((sieve)) = T(cache: cache, wheel: wheel, culls: culls, capacity: 000309) + let ((sieve)) = T(cache: cache, wheel: wheel, culls: culls, capacity: 000309) check(sieve, limit: 000511, count: 000097, last: 000509) sieve.increment()