123456789_123456789_123456789_123456789_123456789_

Class: Prime::TrialDivisionGenerator

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
self, PseudoPrimeGenerator, Enumerable
Inherits: Prime::PseudoPrimeGenerator
Defined in: lib/prime.rb

Overview

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

PseudoPrimeGenerator - Inherited

#each

Iterates the given block for each prime number.

#next

alias of #succ.

#rewind

Rewinds the internal position for enumeration.

#size,
#succ

returns the next pseudo-prime number, and move the internal position forward.

#with_index

see Enumerator#with_index.

#with_object

see Enumerator#with_object.

Constructor Details

.newTrialDivisionGenerator

[ GitHub ]

  
# File 'lib/prime.rb', line 327

def initialize
  @index = -1
  super
end

Instance Method Details

#next

Alias for #succ.

[ GitHub ]

  
# File 'lib/prime.rb', line 338

alias next succ

#rewind

[ GitHub ]

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

def rewind
  initialize
end

#succ Also known as: #next

[ GitHub ]

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

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