Skip to content
Permalink
Browse files

Rename types.hpp to forward.hpp

And rename Wheel.cpp to LookupTables.cpp
  • Loading branch information
kimwalisch committed Nov 21, 2019
1 parent e15efa5 commit 37755e044b563fd94acffa9ee23ddf6c982e5fee
@@ -48,6 +48,7 @@ set(LIB_SRC src/api-c.cpp
src/iterator-c.cpp
src/iterator.cpp
src/IteratorHelper.cpp
src/LookupTables.cpp
src/MemoryPool.cpp
src/PrimeGenerator.cpp
src/nthPrime.cpp
@@ -57,8 +58,7 @@ set(LIB_SRC src/api-c.cpp
src/PrintPrimes.cpp
src/PrimeSieve.cpp
src/Erat.cpp
src/SievingPrimes.cpp
src/Wheel.cpp)
src/SievingPrimes.cpp)

# Required includes ##################################################

@@ -1,7 +1,7 @@
///
/// @file Erat.hpp
///
/// Copyright (C) 2018 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2019 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
@@ -10,6 +10,7 @@
#ifndef ERAT_HPP
#define ERAT_HPP

#include "forward.hpp"
#include "EratSmall.hpp"
#include "EratMedium.hpp"
#include "EratBig.hpp"
@@ -56,7 +57,6 @@ class Erat
static uint64_t nextPrime(uint64_t*, uint64_t);

private:
static const std::array<uint64_t, 64> bruijnBitValues_;
uint64_t maxPreSieve_ = 0;
uint64_t maxEratSmall_ = 0;
uint64_t maxEratMedium_ = 0;
@@ -82,7 +82,7 @@ inline uint64_t Erat::nextPrime(uint64_t* bits, uint64_t low)
// using a custom De Bruijn bitscan
uint64_t debruijn = 0x3F08A4C6ACB9DBDull;
uint64_t mask = *bits - 1;
uint64_t bitValue = bruijnBitValues_[((*bits ^ mask) * debruijn) >> 58];
uint64_t bitValue = bruijnBitValues[((*bits ^ mask) * debruijn) >> 58];
uint64_t prime = low + bitValue;
*bits &= mask;
return prime;
@@ -1,8 +1,8 @@
///
/// @file types.hpp
/// @brief Types and forward declarations.
/// @file forward.hpp
/// @brief Forward declarations.
///
/// Copyright (C) 2018 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2019 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
@@ -11,12 +11,12 @@
#ifndef TYPES_HPP
#define TYPES_HPP

#include <array>
#include <stdint.h>

namespace primesieve {


using uint_t = unsigned int;
extern const std::array<uint64_t, 64> bruijnBitValues;

int get_num_threads();
int get_sieve_size();
@@ -52,18 +52,6 @@ const array<uint8_t, 37> unsetLarger =

namespace primesieve {

const array<uint64_t, 64> Erat::bruijnBitValues_ =
{
7, 47, 11, 49, 67, 113, 13, 53,
89, 71, 161, 101, 119, 187, 17, 233,
59, 79, 91, 73, 133, 139, 163, 103,
149, 121, 203, 169, 191, 217, 19, 239,
43, 61, 109, 83, 157, 97, 181, 229,
77, 131, 137, 143, 199, 167, 211, 41,
107, 151, 179, 227, 127, 197, 209, 37,
173, 223, 193, 31, 221, 29, 23, 241
};

Erat::Erat() = default;

Erat::Erat(uint64_t start, uint64_t stop) :
@@ -1,18 +1,34 @@
///
/// @file Wheel.cpp
/// @brief Precomputed arrays for wheel factorization.
/// @file LookupTables.cpp
/// @brief Static gobal arrays.
///
/// Copyright (C) 2017 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2019 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#include <primesieve/Wheel.hpp>
#include <primesieve/bits.hpp>
#include <primesieve/forward.hpp>
#include <primesieve/Wheel.hpp>

#include <array>
#include <stdint.h>

namespace primesieve {

const std::array<uint64_t, 64> bruijnBitValues =
{
7, 47, 11, 49, 67, 113, 13, 53,
89, 71, 161, 101, 119, 187, 17, 233,
59, 79, 91, 73, 133, 139, 163, 103,
149, 121, 203, 169, 191, 217, 19, 239,
43, 61, 109, 83, 157, 97, 181, 229,
77, 131, 137, 143, 199, 167, 211, 41,
107, 151, 179, 227, 127, 197, 209, 37,
173, 223, 193, 31, 221, 29, 23, 241
};

const WheelInit wheel30Init[30] =
{
{1, 0}, {0, 0}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1},
@@ -9,10 +9,10 @@
///

#include <primesieve/config.hpp>
#include <primesieve/forward.hpp>
#include <primesieve/ParallelSieve.hpp>
#include <primesieve/PrimeSieve.hpp>
#include <primesieve/pmath.hpp>
#include <primesieve/types.hpp>

#include <stdint.h>
#include <algorithm>
@@ -13,11 +13,11 @@
///

#include <primesieve/Erat.hpp>
#include <primesieve/forward.hpp>
#include <primesieve/PreSieve.hpp>
#include <primesieve/PrimeGenerator.hpp>
#include <primesieve/pmath.hpp>
#include <primesieve/SievingPrimes.hpp>
#include <primesieve/types.hpp>

#include <stdint.h>
#include <algorithm>
@@ -10,12 +10,12 @@
/// file in the top level directory.
///

#include <primesieve/forward.hpp>
#include <primesieve/PrimeSieve.hpp>
#include <primesieve/ParallelSieve.hpp>
#include <primesieve/pmath.hpp>
#include <primesieve/PrintPrimes.hpp>
#include <primesieve/PreSieve.hpp>
#include <primesieve/types.hpp>

#include <stdint.h>
#include <algorithm>
@@ -1,23 +1,23 @@
///
/// @file PrintPrimes.cpp
/// @brief PrintPrimes is used for printing primes to stdout and
/// for counting primes. After a segment has been sieved
/// (using Erat) PrintPrimes is used to reconstruct primes
/// and prime k-tuplets from 1 bits of the sieve array.
/// @brief PrintPrimes is used for printing primes to stdout and for
/// counting primes. After a segment has been sieved (using
/// Erat) PrintPrimes is used to reconstruct primes and prime
/// k-tuplets from 1 bits of the sieve array.
///
/// Copyright (C) 2019 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#include <primesieve/forward.hpp>
#include <primesieve/littleendian_cast.hpp>
#include <primesieve/pmath.hpp>
#include <primesieve/PrintPrimes.hpp>
#include <primesieve/PrimeSieve.hpp>
#include <primesieve/Erat.hpp>
#include <primesieve/SievingPrimes.hpp>
#include <primesieve/types.hpp>

#include <stdint.h>
#include <algorithm>
@@ -62,7 +62,7 @@ PrintPrimes::PrintPrimes(PrimeSieve& ps) :
///
void PrintPrimes::initCounts()
{
for (uint_t i = 1; i < counts_.size(); i++)
for (unsigned i = 1; i < counts_.size(); i++)
{
if (!ps_.isCount(i))
continue;
@@ -124,7 +124,7 @@ void PrintPrimes::countPrimes()
void PrintPrimes::countkTuplets()
{
// i = 1 twins, i = 2 triplets, ...
for (uint_t i = 1; i < counts_.size(); i++)
for (unsigned i = 1; i < counts_.size(); i++)
{
if (!ps_.isCount(i))
continue;
@@ -170,10 +170,10 @@ void PrintPrimes::printPrimes() const
/// Print prime k-tuplets to stdout
void PrintPrimes::printkTuplets() const
{
ostringstream kTuplets;
// i = 1 twins, i = 2 triplets, ...
uint_t i = 1;
unsigned i = 1;
uint64_t low = low_;
ostringstream kTuplets;

for (; !ps_.isPrint(i); i++);

@@ -9,9 +9,9 @@
///

#include <primesieve.h>
#include <primesieve/forward.hpp>
#include <primesieve/IteratorHelper.hpp>
#include <primesieve/PrimeGenerator.hpp>
#include <primesieve/types.hpp>

#include <stdint.h>
#include <cerrno>
@@ -8,10 +8,10 @@
///

#include <primesieve/iterator.hpp>
#include <primesieve/forward.hpp>
#include <primesieve/PrimeSieve.hpp>
#include <primesieve/pmath.hpp>
#include <primesieve/primesieve_error.hpp>
#include <primesieve/types.hpp>

#include <stdint.h>
#include <algorithm>

0 comments on commit 37755e0

Please sign in to comment.
You can’t perform that action at this time.