proxygen
PreCalculatedPrimeTable Class Reference

#include <prime_tables.h>

Inheritance diagram for PreCalculatedPrimeTable:
PrimeTable PrimeTable PrimeTable

Public Member Functions

 PreCalculatedPrimeTable (int max)
 
virtual ~PreCalculatedPrimeTable ()
 
virtual bool IsPrime (int n) const
 
virtual int GetNextPrime (int p) const
 
 PreCalculatedPrimeTable (int max)
 
virtual ~PreCalculatedPrimeTable ()
 
virtual bool IsPrime (int n) const
 
virtual int GetNextPrime (int p) const
 
 PreCalculatedPrimeTable (int max)
 
virtual ~PreCalculatedPrimeTable ()
 
virtual bool IsPrime (int n) const
 
virtual int GetNextPrime (int p) const
 
- Public Member Functions inherited from PrimeTable
virtual ~PrimeTable ()
 
virtual ~PrimeTable ()
 
virtual ~PrimeTable ()
 

Private Member Functions

void CalculatePrimesUpTo (int max)
 
void operator= (const PreCalculatedPrimeTable &rhs)
 
void CalculatePrimesUpTo (int max)
 
void operator= (const PreCalculatedPrimeTable &rhs)
 
void CalculatePrimesUpTo (int max)
 
void operator= (const PreCalculatedPrimeTable &rhs)
 

Private Attributes

const int is_prime_size_
 
bool *const is_prime_
 

Detailed Description

Definition at line 80 of file prime_tables.h.

Constructor & Destructor Documentation

PreCalculatedPrimeTable::PreCalculatedPrimeTable ( int  max)
inlineexplicit

Definition at line 83 of file prime_tables.h.

84  : is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
86  }
LogLevel max
Definition: LogLevel.cpp:31
void CalculatePrimesUpTo(int max)
Definition: prime_tables.h:102
virtual PreCalculatedPrimeTable::~PreCalculatedPrimeTable ( )
inlinevirtual

Definition at line 87 of file prime_tables.h.

87 { delete[] is_prime_; }
PreCalculatedPrimeTable::PreCalculatedPrimeTable ( int  max)
inlineexplicit

Definition at line 83 of file prime_tables.h.

84  : is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
86  }
LogLevel max
Definition: LogLevel.cpp:31
void CalculatePrimesUpTo(int max)
Definition: prime_tables.h:102
virtual PreCalculatedPrimeTable::~PreCalculatedPrimeTable ( )
inlinevirtual

Definition at line 87 of file prime_tables.h.

87 { delete[] is_prime_; }
PreCalculatedPrimeTable::PreCalculatedPrimeTable ( int  max)
inlineexplicit

Definition at line 83 of file prime_tables.h.

84  : is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
86  }
LogLevel max
Definition: LogLevel.cpp:31
void CalculatePrimesUpTo(int max)
Definition: prime_tables.h:102
virtual PreCalculatedPrimeTable::~PreCalculatedPrimeTable ( )
inlinevirtual

Definition at line 87 of file prime_tables.h.

87 { delete[] is_prime_; }

Member Function Documentation

void PreCalculatedPrimeTable::CalculatePrimesUpTo ( int  max)
inlineprivate

Definition at line 102 of file prime_tables.h.

References i, and max.

102  {
103  ::std::fill(is_prime_, is_prime_ + is_prime_size_, true);
104  is_prime_[0] = is_prime_[1] = false;
105 
106  for (int i = 2; i <= max; i++) {
107  if (!is_prime_[i]) continue;
108 
109  // Marks all multiples of i (except i itself) as non-prime.
110  for (int j = 2*i; j <= max; j += i) {
111  is_prime_[j] = false;
112  }
113  }
114  }
LogLevel max
Definition: LogLevel.cpp:31
void PreCalculatedPrimeTable::CalculatePrimesUpTo ( int  max)
inlineprivate

Definition at line 102 of file prime_tables.h.

References i, max, and folly::detail::rhs.

102  {
103  ::std::fill(is_prime_, is_prime_ + is_prime_size_, true);
104  is_prime_[0] = is_prime_[1] = false;
105 
106  for (int i = 2; i <= max; i++) {
107  if (!is_prime_[i]) continue;
108 
109  // Marks all multiples of i (except i itself) as non-prime.
110  for (int j = 2*i; j <= max; j += i) {
111  is_prime_[j] = false;
112  }
113  }
114  }
LogLevel max
Definition: LogLevel.cpp:31
void PreCalculatedPrimeTable::CalculatePrimesUpTo ( int  max)
inlineprivate

Definition at line 102 of file prime_tables.h.

References i, max, and folly::detail::rhs.

102  {
103  ::std::fill(is_prime_, is_prime_ + is_prime_size_, true);
104  is_prime_[0] = is_prime_[1] = false;
105 
106  for (int i = 2; i <= max; i++) {
107  if (!is_prime_[i]) continue;
108 
109  // Marks all multiples of i (except i itself) as non-prime.
110  for (int j = 2*i; j <= max; j += i) {
111  is_prime_[j] = false;
112  }
113  }
114  }
LogLevel max
Definition: LogLevel.cpp:31
virtual int PreCalculatedPrimeTable::GetNextPrime ( int  p) const
inlinevirtual

Implements PrimeTable.

Definition at line 93 of file prime_tables.h.

93  {
94  for (int n = p + 1; n < is_prime_size_; n++) {
95  if (is_prime_[n]) return n;
96  }
97 
98  return -1;
99  }
virtual int PreCalculatedPrimeTable::GetNextPrime ( int  p) const
inlinevirtual

Implements PrimeTable.

Definition at line 93 of file prime_tables.h.

93  {
94  for (int n = p + 1; n < is_prime_size_; n++) {
95  if (is_prime_[n]) return n;
96  }
97 
98  return -1;
99  }
virtual int PreCalculatedPrimeTable::GetNextPrime ( int  p) const
inlinevirtual

Implements PrimeTable.

Definition at line 93 of file prime_tables.h.

93  {
94  for (int n = p + 1; n < is_prime_size_; n++) {
95  if (is_prime_[n]) return n;
96  }
97 
98  return -1;
99  }
virtual bool PreCalculatedPrimeTable::IsPrime ( int  n) const
inlinevirtual

Implements PrimeTable.

Definition at line 89 of file prime_tables.h.

89  {
90  return 0 <= n && n < is_prime_size_ && is_prime_[n];
91  }
virtual bool PreCalculatedPrimeTable::IsPrime ( int  n) const
inlinevirtual

Implements PrimeTable.

Definition at line 89 of file prime_tables.h.

89  {
90  return 0 <= n && n < is_prime_size_ && is_prime_[n];
91  }
virtual bool PreCalculatedPrimeTable::IsPrime ( int  n) const
inlinevirtual

Implements PrimeTable.

Definition at line 89 of file prime_tables.h.

89  {
90  return 0 <= n && n < is_prime_size_ && is_prime_[n];
91  }
void PreCalculatedPrimeTable::operator= ( const PreCalculatedPrimeTable rhs)
private
void PreCalculatedPrimeTable::operator= ( const PreCalculatedPrimeTable rhs)
private
void PreCalculatedPrimeTable::operator= ( const PreCalculatedPrimeTable rhs)
private

Member Data Documentation

bool *const PreCalculatedPrimeTable::is_prime_
private

Definition at line 117 of file prime_tables.h.

const int PreCalculatedPrimeTable::is_prime_size_
private

Definition at line 116 of file prime_tables.h.


The documentation for this class was generated from the following file: