module Factory.Math.Implementations.Primes.Algorithm(
Algorithm(..)
) where
import qualified Data.Default
import qualified Data.Numbers.Primes
import qualified Factory.Data.PrimeWheel as Data.PrimeWheel
import qualified Factory.Math.Implementations.Primes.SieveOfAtkin as Math.Implementations.Primes.SieveOfAtkin
import qualified Factory.Math.Implementations.Primes.SieveOfEratosthenes as Math.Implementations.Primes.SieveOfEratosthenes
import qualified Factory.Math.Implementations.Primes.TrialDivision as Math.Implementations.Primes.TrialDivision
import qualified Factory.Math.Implementations.Primes.TurnersSieve as Math.Implementations.Primes.TurnersSieve
import qualified Factory.Math.Primes as Math.Primes
data Algorithm
= SieveOfAtkin Integer
| SieveOfEratosthenes Data.PrimeWheel.NPrimes
| TrialDivision Data.PrimeWheel.NPrimes
|
| WheelSieve Int
deriving (Algorithm -> Algorithm -> Bool
(Algorithm -> Algorithm -> Bool)
-> (Algorithm -> Algorithm -> Bool) -> Eq Algorithm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Algorithm -> Algorithm -> Bool
$c/= :: Algorithm -> Algorithm -> Bool
== :: Algorithm -> Algorithm -> Bool
$c== :: Algorithm -> Algorithm -> Bool
Eq, ReadPrec [Algorithm]
ReadPrec Algorithm
Int -> ReadS Algorithm
ReadS [Algorithm]
(Int -> ReadS Algorithm)
-> ReadS [Algorithm]
-> ReadPrec Algorithm
-> ReadPrec [Algorithm]
-> Read Algorithm
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Algorithm]
$creadListPrec :: ReadPrec [Algorithm]
readPrec :: ReadPrec Algorithm
$creadPrec :: ReadPrec Algorithm
readList :: ReadS [Algorithm]
$creadList :: ReadS [Algorithm]
readsPrec :: Int -> ReadS Algorithm
$creadsPrec :: Int -> ReadS Algorithm
Read, Int -> Algorithm -> ShowS
[Algorithm] -> ShowS
Algorithm -> String
(Int -> Algorithm -> ShowS)
-> (Algorithm -> String)
-> ([Algorithm] -> ShowS)
-> Show Algorithm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Algorithm] -> ShowS
$cshowList :: [Algorithm] -> ShowS
show :: Algorithm -> String
$cshow :: Algorithm -> String
showsPrec :: Int -> Algorithm -> ShowS
$cshowsPrec :: Int -> Algorithm -> ShowS
Show)
instance Data.Default.Default Algorithm where
def :: Algorithm
def = Int -> Algorithm
SieveOfEratosthenes Int
7
instance Math.Primes.Algorithmic Algorithm where
primes :: Algorithm -> [i]
primes (SieveOfAtkin Integer
maxPrime) = Int -> i -> [i]
forall i. (NFData i, Ix i, Integral i) => Int -> i -> [i]
Math.Implementations.Primes.SieveOfAtkin.sieveOfAtkin (Integer -> Int
forall i. Integral i => i -> Int
Data.PrimeWheel.estimateOptimalSize Integer
maxPrime) (i -> [i]) -> i -> [i]
forall a b. (a -> b) -> a -> b
$ Integer -> i
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
maxPrime
primes (SieveOfEratosthenes Int
wheelSize) = Int -> [i]
forall i. Integral i => Int -> [i]
Math.Implementations.Primes.SieveOfEratosthenes.sieveOfEratosthenes Int
wheelSize
primes (TrialDivision Int
wheelSize) = Int -> [i]
forall i. Integral i => Int -> [i]
Math.Implementations.Primes.TrialDivision.trialDivision Int
wheelSize
primes Algorithm
TurnersSieve = [i]
forall prime. Integral prime => [prime]
Math.Implementations.Primes.TurnersSieve.turnersSieve
primes (WheelSieve Int
wheelSize) = Int -> [i]
forall i. Integral i => Int -> [i]
Data.Numbers.Primes.wheelSieve Int
wheelSize