lima.mathematical.factorisation.trialdivision
Class EratosthenesSieve

java.lang.Object
  |
  +--lima.mathematical.factorisation.trialdivision.EratosthenesSieve

public class EratosthenesSieve
extends java.lang.Object

A class to represent a Sieve of Eratosthenes. Objects of this class are capable of generating prime numbers within a configurable range.


Nested Class Summary
 class EratosthenesSieve.Iterator
          An object of this class is created by a Sieve of Eratosthenes object.
 
Constructor Summary
EratosthenesSieve(int sieveLength)
          Construct a new Sieve of Eratosthenes object, with the specified sieve length.
 
Method Summary
 boolean isComposite(int n)
          Determine whether or not the specified integer is composite, with absolute certainty.
 boolean isPrime(int n)
          Determine whether or not the specified integer is prime, with absolute certainty.
 EratosthenesSieve.Iterator iterator()
          Create a new iterator object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EratosthenesSieve

public EratosthenesSieve(int sieveLength)
Construct a new Sieve of Eratosthenes object, with the specified sieve length. The sieve length determines the range of integers to check for primality. Specifying a sieve length of n, will result in the creation of a sieve object that can test integers in the range 0, ... , (n - 1) for primality with complete certainty.

Parameters:
sieveLength - - the length of sieve to create.
Method Detail

isComposite

public boolean isComposite(int n)
Determine whether or not the specified integer is composite, with absolute certainty.

Parameters:
n - - the integer to check for compositeness.

isPrime

public boolean isPrime(int n)
Determine whether or not the specified integer is prime, with absolute certainty.

Parameters:
n - - the integer to check for primality.

iterator

public EratosthenesSieve.Iterator iterator()
Create a new iterator object. An iterator object will iteratively supply each of those prime numbers that were generated when the sieve object was initially constructed, in order of their increasing size.

Returns:
EratosthenesSieve.Iterator