17 static std::mutex mPrimeMutex;
41 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
42 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
46 std::mutex PrimeFactory<T>::mPrimeMutex;
51 for (
uint res = n + 2; ; res += 2) {
53 for (std::size_t i = 1; !found && (i < pf.
size()); i++) {
54 if (res % pf[i] == 0) found =
true;
56 if (!found)
return res;
62 mpz_nextprime(res.get_mpz_t(), n.get_mpz_t());
66 #ifdef USE_CLN_NUMBERS
68 return cln::nextprobprime(n + 1);
75 if (mNext == mPrimes.size()) {
77 std::lock_guard<std::mutex> guard(mPrimeMutex);
81 return mPrimes[mNext++];
carl is the main namespace for the library.
uint next_prime(const uint &n, const PrimeFactory< uint > &pf)
This class provides a convenient way to enumerate primes.
const T & operator[](std::size_t id) const
Provides const access to the computed primes. Asserts that id is smaller than size().
const T & operator[](std::size_t id)
Provides access to the computed primes. If id is at least size(), the missing primes are computed on-...
std::size_t size() const
Returns the number of already computed primes.
const T & next_prime()
Computed the next prime and returns it.
static std::vector< T > mPrimes