primesieve  7.1
Public Member Functions | List of all members
primesieve::iterator Class Reference

primesieve::iterator allows to easily iterate over primes both forwards and backwards. More...

#include <iterator.hpp>

Public Member Functions

 iterator (uint64_t start=0, uint64_t stop_hint=get_max_stop())
 Create a new iterator object. More...
 
void skipto (uint64_t start, uint64_t stop_hint=get_max_stop())
 Reset the primesieve iterator to start. More...
 
uint64_t next_prime ()
 Get the next prime. More...
 
uint64_t prev_prime ()
 Get the previous prime. More...
 

Detailed Description

primesieve::iterator allows to easily iterate over primes both forwards and backwards.

Generating the first prime has a complexity of O(r log log r) operations with r = n^0.5, after that any additional prime is generated in amortized O(log n log log n) operations. The memory usage is PrimePi(n^0.5) * 8 bytes.

Examples:
prev_prime.cpp, and primesieve_iterator.cpp.

Constructor & Destructor Documentation

◆ iterator()

primesieve::iterator::iterator ( uint64_t  start = 0,
uint64_t  stop_hint = get_max_stop() 
)

Create a new iterator object.

Parameters
startGenerate primes > start (or < start).
stop_hintStop number optimization hint, gives significant speed up if few primes are generated. E.g. if you want to generate the primes below 1000 use stop_hint = 1000.

Member Function Documentation

◆ next_prime()

uint64_t primesieve::iterator::next_prime ( )
inline

Get the next prime.

Returns UINT64_MAX if next prime > 2^64.

Examples:
primesieve_iterator.cpp.

◆ prev_prime()

uint64_t primesieve::iterator::prev_prime ( )
inline

Get the previous prime.

prev_prime(n) = 0 if n <= 2.

Examples:
prev_prime.cpp.

◆ skipto()

void primesieve::iterator::skipto ( uint64_t  start,
uint64_t  stop_hint = get_max_stop() 
)

Reset the primesieve iterator to start.

Parameters
startGenerate primes > start (or < start).
stop_hintStop number optimization hint, gives significant speed up if few primes are generated. E.g. if you want to generate the primes below 1000 use stop_hint = 1000.
Examples:
prev_prime.cpp, and primesieve_iterator.cpp.

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