Skip to content

Commit

Permalink
Cleanup (#114).
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Dec 6, 2023
1 parent 6514050 commit b477f91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Sources/NBKCoreKit/Models/NBKPrimeSieve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
//=--------------------------------------=
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/NBKCoreKitTests/Models/NBKPrimeSieve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b477f91

Please sign in to comment.