EratosthenesPrimeSieve constructor

EratosthenesPrimeSieve(
  1. int max
)

Constructs the prime sieve of Eratosthenes.

Implementation

EratosthenesPrimeSieve(super.max) : _isPrime = BitList.filled(max + 1, true) {
  _isPrime[0] = false;
  if (max > 0) _isPrime[1] = false;
  for (var i = 4; i <= max; i += 2) {
    _isPrime[i] = false;
  }
  for (var i = 3; i * i <= max; i += 2) {
    if (_isPrime[i]) {
      for (var j = i * i; j <= max; j += 2 * i) {
        _isPrime[j] = false;
      }
    }
  }
}