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())
| Reinitialize this iterator object to start. More...
uint64_t | next_prime ()
| Advance the iterator by one position. More...
uint64_t | previous_prime ()
| Get the previous prime, or 0 if input <= 2 e.g. 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 about pi(n^0.5) * 16 bytes. primesieve::iterator objects are very convenient to use at the cost of being slightly slower than the callback_primes() functions.

Examples:
  previous_prime.cpp, and primesieve_iterator.cpp.

## Constructor & Destructor Documentation

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

Create a new iterator object.

Parameters

  start | Generate primes > start (or < start).
  stop_hint | Stop 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.

Precondition
  start <= 2^64 - 2^32 * 10

## Member Function Documentation

uint64_t primesieve::iterator::next_prime | ( |  | ) |

inline

Advance the iterator by one position.

Returns
  The next prime.

Examples:
  primesieve_iterator.cpp.

uint64_t primesieve::iterator::previous_prime | ( |  | ) |

inline

Get the previous prime, or 0 if input <= 2 e.g.

previous_prime(2) = 0.

Examples:
  previous_prime.cpp.

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

Reinitialize this iterator object to start.

Parameters

  start | Generate primes > start (or < start).
  stop_hint | Stop 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.

Precondition
  start <= 2^64 - 2^32 * 10

Examples:
  previous_prime.cpp.

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

- iterator.hpp