-
Notifications
You must be signed in to change notification settings - Fork 0
/
primes.h
executable file
·38 lines (28 loc) · 976 Bytes
/
primes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include <cstdint>
#include <vector>
#include <memory>
#include <future>
const uint32_t L1D_CACHE_SIZE = 32768;
class threaded_bitpack;
class Primes
{
public:
// Member functions
Primes();
~Primes();
// Test 1 number for primality
bool isPrime(uint64_t n) const;
// Creates an internal data structure with all primes up to limit
// Speeds up isPrime() and is used internally for getList()
void sieve(uint64_t limit, std::size_t threads = std::thread::hardware_concurrency());
// Calculate pi(x), number of primes below x
// Returns the exact number if available, otherwise
// it returns an upper bound
uint64_t pi(uint64_t x) const;
// Get a vector full of primes up to limit
const std::vector<uint64_t>& getList(uint64_t limit = 0);
private:
std::unique_ptr<threaded_bitpack> pSieve;
std::vector<uint64_t> pList;
};