Class: Prime::EratosthenesSieve

### Home Classes Methods

### In Files

- lib/backports/1.9.1/stdlib/prime.rb

### Parent

Object

### Methods

- #next_to

### Included Modules

- Singleton

### Class/Module Index

Quicksearch

- Prime
- Prime::EratosthenesGenerator
- Prime::EratosthenesSieve
- Prime::Generator23
- Prime::OldCompatibility
- Prime::PseudoPrimeGenerator
- Prime::TrialDivision
- Prime::TrialDivisionGenerator
- Backports
- Backports::MOST_EXTREME_OBJECT_EVER
- Backports::StdLib
- Backports::StdLib::LoadedFeatures
- Enumerator
- Enumerator::GeneratorBP
- Enumerator::Lazy
- Enumerator::Yielder
- Matrix
- Matrix::EigenvalueDecomposition
- Matrix::LUPDecomposition
- Random
- Random::Implementation
- Random::MT19937
- Enumerable
- Enumerable::Enumerator
- File
- File::Constants
- ARGF
- Array
- BasicObject
- Binding
- Complex
- Dir
- ENV
- Fixnum
- Float
- GC
- Hash
- IO
- Integer
- Kernel
- Math
- Method
- Module
- NilClass
- Numeric
- Object
- ObjectSpace
- OpenStruct
- Proc
- Process
- Range
- Regexp
- Set
- StopIteration
- String
- Struct
- Symbol
- UnboundMethod

No matching classes.

# Prime::EratosthenesSieve

Internal use. An implementation of eratosthenes's sieve

### Constants

BITS_PER_ENTRY
ENTRIES_PER_TABLE
FILLED_ENTRY
NUMS_PER_ENTRY
NUMS_PER_TABLE

### Public Instance Methods

next_to(n) click to toggle source

returns the least odd prime number which is greater than `n`.

    # File lib/backports/1.9.1/stdlib/prime.rb, line 428
    def next_to(n)
      n = (n-1).div(2)*2+3 # the next odd number to given n
      table_index, integer_index, bit_index = indices(n)
      loop do
        extend_table until @tables.length > table_index
        for j in integer_index...ENTRIES_PER_TABLE
          if !@tables[table_index][j].zero?
            for k in bit_index...BITS_PER_ENTRY
              return NUMS_PER_TABLE*table_index + NUMS_PER_ENTRY*j + 2*k+1 if !@tables[table_index][j][k].zero?
            end
          end
          bit_index = 0
        end
        table_index += 1; integer_index = 0
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.