title: Sieve of Eratosthenes with Wheel Factorization
body: <p>I'm implementing a reasonably fast prime number generator and I obtained some nice results with a few optimizations on the <a href="https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="nofollow noreferrer">sieve of Eratosthenes</a>. In particular, during the preliminary part of the algorithm, I skip all multiples of 2 and 3 in this way:</p>
  
  <pre><code>template&lt;class Sieve, class SizeT&gt;
  void PrimeGenerator&lt;Sieve, SizeT&gt;::factorize()
  {
      SizeT c = 2;
      m_sieve[2] = 1;
      m_sieve[3] = 1;
  
      for (SizeT i=5; i&lt;m_size; i += c, c = 6 - c)
          m_sieve[i] = 1;
  }
  </code></pre>
  
  <p>Here <code>m_sieve</code> is a boolean array according to the sieve of Eratosthenes.
  I think this is a sort of Wheel factorization only considering primes 2 and 3, incrementing following the pattern 2, 4, 2, 4,.. </p>
  
  <p>What I would like to do is to implement a greater wheel, maybe considering primes 2,3 and 5.</p>
  
  <p>I already read a lot of documentation about it, but I didn't see any implementation with the sieve of Eratosthenes... a sample code could help a lot, but also some hints would be nice :)
  Thanks.</p>