Skip to content

Commit

Permalink
feat: add a bitmap mask primality check using a prime mask generator
Browse files Browse the repository at this point in the history
  • Loading branch information
h5law committed May 18, 2024
1 parent ab40861 commit 28dd240
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions masks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package primality

// MaskOfEratosthenes uses a bitmask produced by a modified sieve of
// Eratosthenes in order to compare the desired integer against the
// corresponding index in the mask
func MaskOfEratosthenes(n int) bool {
if n < 2 || ((n > 2) && n&1 == 0) {
return false
}
bz := SieveOfEratosthenes(uint64(n))
return bz[n] != 0
}

0 comments on commit 28dd240

Please sign in to comment.