Class: Prime::TrialDivisionGenerator

Inherits:
PseudoPrimeGenerator show all
Defined in:
lib/prime.rb

Overview

An implementation of PseudoPrimeGenerator which uses a prime table generated by trial division.

Instance Method Summary collapse

Methods inherited from PseudoPrimeGenerator

#each, #upper_bound, #upper_bound=, #with_object

Constructor Details

#initializeTrialDivisionGenerator

Returns a new instance of TrialDivisionGenerator


326
327
328
329
# File 'lib/prime.rb', line 326

def initialize
  @index = -1
  super
end

Instance Method Details

#rewindObject


334
335
336
# File 'lib/prime.rb', line 334

def rewind
  initialize
end

#succObject Also known as: next


331
332
333
# File 'lib/prime.rb', line 331

def succ
  TrialDivision.instance[@index += 1]
end