-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move code from generate.hpp to generate.cpp (#75)
- Loading branch information
1 parent
80a6ad9
commit 60d585f
Showing
7 changed files
with
121 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/// | ||
/// @file generate.hpp | ||
/// | ||
/// Copyright (C) 2023 Kim Walisch, <[email protected]> | ||
/// Copyright (C) 2024 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
|
@@ -10,53 +10,84 @@ | |
#ifndef GENERATE_HPP | ||
#define GENERATE_HPP | ||
|
||
#include <primesieve.hpp> | ||
#include <Vector.hpp> | ||
|
||
#include <type_traits> | ||
#include <stdint.h> | ||
|
||
namespace primecount { | ||
|
||
/// Generate a vector with the primes <= max. | ||
/// defined in generate.cpp | ||
Vector<int32_t> generate_primes_i32(int64_t max); | ||
Vector<uint32_t> generate_primes_u32(int64_t max); | ||
Vector<int64_t> generate_primes_i64(int64_t max); | ||
Vector<uint64_t> generate_primes_u64(int64_t max); | ||
Vector<int32_t> generate_n_primes_i32(int64_t n); | ||
|
||
/// Returns a vector with the primes <= max. | ||
/// The primes vector uses 1-indexing i.e. primes[1] = 2. | ||
/// | ||
template <typename T> | ||
typename std::enable_if<std::is_same<T, int32_t>::value, Vector<int32_t>>::type | ||
generate_primes(int64_t max) | ||
{ | ||
return generate_primes_i32(max); | ||
} | ||
|
||
/// Returns a vector with the primes <= max. | ||
/// The primes vector uses 1-indexing i.e. primes[1] = 2. | ||
/// | ||
template <typename T> | ||
typename std::enable_if<std::is_same<T, uint32_t>::value, Vector<uint32_t>>::type | ||
generate_primes(int64_t max) | ||
{ | ||
return generate_primes_u32(max); | ||
} | ||
|
||
/// Returns a vector with the primes <= max. | ||
/// The primes vector uses 1-indexing i.e. primes[1] = 2. | ||
/// | ||
template <typename T> | ||
typename std::enable_if<std::is_same<T, int64_t>::value, Vector<int64_t>>::type | ||
generate_primes(int64_t max) | ||
{ | ||
return generate_primes_i64(max); | ||
} | ||
|
||
/// Returns a vector with the primes <= max. | ||
/// The primes vector uses 1-indexing i.e. primes[1] = 2. | ||
/// | ||
template <typename T> | ||
Vector<T> generate_primes(int64_t max) | ||
typename std::enable_if<std::is_same<T, uint64_t>::value, Vector<uint64_t>>::type | ||
generate_primes(int64_t max) | ||
{ | ||
Vector<T> primes; | ||
primes.resize(1); | ||
primes[0] = 0; | ||
primesieve::generate_primes(max, &primes); | ||
return primes; | ||
return generate_primes_u64(max); | ||
} | ||
|
||
/// Generate a vector with the first n primes. | ||
/// Returns a vector with the first n primes. | ||
/// The primes vector uses 1-indexing i.e. primes[1] = 2. | ||
// | ||
template <typename T> | ||
Vector<T> generate_n_primes(int64_t n) | ||
typename std::enable_if<std::is_same<T, int32_t>::value, Vector<int32_t>>::type | ||
generate_n_primes(int64_t n) | ||
{ | ||
Vector<T> primes; | ||
primes.reserve(n + 1); | ||
primes.push_back(0); | ||
primesieve::generate_n_primes(n, &primes); | ||
return primes; | ||
return generate_n_primes_i32(n); | ||
} | ||
|
||
/// Generate a vector with Möbius function values | ||
/// Returns a vector with Möbius function values | ||
Vector<int32_t> generate_moebius(int64_t max); | ||
|
||
/// Generate a vector with the least prime | ||
/// Returns a vector with the least prime | ||
/// factors of the integers <= max. | ||
/// | ||
Vector<int32_t> generate_lpf(int64_t max); | ||
|
||
/// Generate a vector with the largest prime | ||
/// Returns a vector with the largest prime | ||
/// factors of the integers <= max. | ||
/// | ||
Vector<int32_t> generate_mpf(int64_t max); | ||
|
||
/// Generate a vector with the prime counts <= max | ||
/// Returns a vector with the prime counts <= max | ||
/// using the sieve of Eratosthenes. | ||
/// | ||
Vector<int32_t> generate_pi(int64_t max); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters