Documentation ¶
Overview ¶
Package prime provides functionality to produce prime numbers using all available cpu cores. https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes can be an starting point to find more information about how to calculate prime numbers.
The method used in Primes function is Segmented sieve. Segmenting will Reduce memory requirement of process. The space complexity of the algorithm is O(√n).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Primes ¶
Primes is using Segmented sieve. This method will reduce memory usae of Sieve of Eratosthenes considerably. besides memory allocation for Prime numbers slice, there is only O(sqrt(n)) extra memory required for the operation You can learn more about it in https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes.
Example ¶
p := Primes(50) fmt.Println(p)
Output: [2 3 5 7 11 13 17 19 23 29 31 37 41 43 47]
func SieveOfEratosthenes ¶
SieveOfEratosthenes returns a slice of all prime numbers equal or lower than max using Sieve Of Eratosthenes. This is without segmenting.
Types ¶
This section is empty.