Package edu.jas.arith
Class PrimeList
- java.lang.Object
-
- edu.jas.arith.PrimeList
-
- All Implemented Interfaces:
java.lang.Iterable<java.math.BigInteger>
public final class PrimeList extends java.lang.Object implements java.lang.Iterable<java.math.BigInteger>
List of big primes. Provides an Iterator for generating prime numbers. Similar to ALDES/SAC2 SACPOL.PRIME list. See Knuth vol 2, page 390, for list of known primes. See also ALDES/SAC2 SACPOL.PRIME
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PrimeList.Range
Range of probable primes.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<java.math.BigInteger>
LARGE_LIST
private java.math.BigInteger
last
The last prime in the list.private static java.util.List<java.math.BigInteger>
LOW_LIST
private static java.util.List<java.math.BigInteger>
MEDIUM_LIST
private static java.util.List<java.math.BigInteger>
MERSENNE_LIST
private static java.util.List<java.math.BigInteger>
SMALL_LIST
Cache the val list for different sizeprivate java.util.List<java.math.BigInteger>
val
The list of probable primes in requested range.
-
Constructor Summary
Constructors Constructor Description PrimeList()
Constructor for PrimeList.PrimeList(PrimeList.Range r)
Constructor for PrimeList.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addLarge()
Add large sized primes.private void
addLow()
Add low sized primes.private void
addMedium()
Add medium sized primes.private void
addMersenne()
Add Mersenne sized primes.private void
addSmall()
Add small primes.protected boolean
checkPrimes()
Check if the list contains really prime numbers.protected boolean
checkPrimes(int n)
Check if the list contains really prime numbers.java.math.BigInteger
get(int i)
Get prime at index i.static java.math.BigInteger
getLongPrime(int n, int m)
Method to compute a prime as 2**n - m.static java.math.BigInteger
getMersennePrime(int n)
Method to compute a Mersenne prime as 2**n - 1.java.util.Iterator<java.math.BigInteger>
iterator()
Iterator.int
size()
Size of current list.java.lang.String
toString()
-
-
-
Field Detail
-
SMALL_LIST
private static volatile java.util.List<java.math.BigInteger> SMALL_LIST
Cache the val list for different size
-
LOW_LIST
private static volatile java.util.List<java.math.BigInteger> LOW_LIST
-
MEDIUM_LIST
private static volatile java.util.List<java.math.BigInteger> MEDIUM_LIST
-
LARGE_LIST
private static volatile java.util.List<java.math.BigInteger> LARGE_LIST
-
MERSENNE_LIST
private static volatile java.util.List<java.math.BigInteger> MERSENNE_LIST
-
val
private java.util.List<java.math.BigInteger> val
The list of probable primes in requested range.
-
last
private java.math.BigInteger last
The last prime in the list.
-
-
Constructor Detail
-
PrimeList
public PrimeList()
Constructor for PrimeList.
-
PrimeList
public PrimeList(PrimeList.Range r)
Constructor for PrimeList.- Parameters:
r
- size range for primes.
-
-
Method Detail
-
addSmall
private void addSmall()
Add small primes.
-
addLow
private void addLow()
Add low sized primes.
-
addMedium
private void addMedium()
Add medium sized primes.
-
addLarge
private void addLarge()
Add large sized primes.
-
addMersenne
private void addMersenne()
Add Mersenne sized primes.
-
getLongPrime
public static java.math.BigInteger getLongPrime(int n, int m)
Method to compute a prime as 2**n - m.- Parameters:
n
- power for 2.m
- for 2**n - m.- Returns:
- 2**n - m
-
getMersennePrime
public static java.math.BigInteger getMersennePrime(int n)
Method to compute a Mersenne prime as 2**n - 1.- Parameters:
n
- power for 2.- Returns:
- 2**n - 1
-
checkPrimes
protected boolean checkPrimes()
Check if the list contains really prime numbers.- Returns:
- true if all checked numbers are prime
-
checkPrimes
protected boolean checkPrimes(int n)
Check if the list contains really prime numbers.- Parameters:
n
- number of primes to check.- Returns:
- true if all checked numbers are prime
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
size
public int size()
Size of current list.- Returns:
- current size of list.
-
get
public java.math.BigInteger get(int i)
Get prime at index i.- Parameters:
i
- index to get element.- Returns:
- prime at index i.
-
iterator
public java.util.Iterator<java.math.BigInteger> iterator()
Iterator. Always has next, will generate new primes if required.- Specified by:
iterator
in interfacejava.lang.Iterable<java.math.BigInteger>
- Returns:
- iterator over the prime list.
-
-