Flowdock
method

extend_table

Importance_0
v1_9_1_378 - Show latest stable - 0 notes - Class: EratosthenesSieve
extend_table() private

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/prime.rb, line 433
    def extend_table
      orig_len = @table.length
      new_len = [orig_len**2, orig_len+256].min
      lbound = orig_len*32
      ubound = new_len*32
      @table.fill(0xFFFF, orig_len...new_len)
      (3..Integer(Math.sqrt(ubound))).step(2) do |p|
        i, j = p.divmod(32)
        next if @table[i][j.div(2)].zero?

        start = (lbound.div(2*p)*2+1)*p    # odd multiple of p which is greater than or equal to lbound
        (start...ubound).step(2*p) do |n|
          i, j = n.divmod(32)
          @table[i] &= 0xFFFF ^ (1<<(j.div(2)))
        end
      end
    end
Register or log in to add new notes.