method
extend_table

v1_9_1_378 -
Show latest stable
-
0 notes -
Class: EratosthenesSieve
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378 (0)
- 1_9_2_180 (0)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10
- 2_2_9
- 2_4_6
- 2_5_5
- 2_6_3
- What's this?
extend_table()
private
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