Class PrimesCache
java.lang.Object
org.mariuszgromada.math.mxparser.mathcollection.PrimesCache
Class for generating prime numbers cache using
Eratosthenes Sieve.
- Version:
- 6.1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanEmpty cache status(package private) booleanCaching process statusstatic final booleanCache ready to use(package private) doubleTime in seconds showing how long did it take to finalize prime numbers caching.static final intDefault range of integer to store in cache(package private) booleanInternal flag marking that primes cache initialization was successful;static final intIndicator if given number is not a primestatic final intIndicator if given number is a prime(package private) boolean[]Integers table to store number and indicate whether they are prime or not(package private) intPrimes between 0 ...static final intIndicator that the value is not stored in cache(package private) intNumber of cached prime numbers -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor - setting prime cache for a default range if integersPrimesCache(int maxNumInCache) Constructor - setting prime cache for a given range if integers -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCounting found primesprivate voidEratosthenes Sieve implementationbooleanReturns cache statusdoubleReturns computing time of Eratosthenes SieveintReturns cache range.intReturns number of found primes.(package private) boolean[]Gets underlying primes cache boolean tablebooleanReturns true in case when primes cache initialization was successful, otherwise returns false.intprimeTest(int n) Check whether given number is prime
-
Field Details
-
DEFAULT_MAX_NUM_IN_CACHE
public static final int DEFAULT_MAX_NUM_IN_CACHEDefault range of integer to store in cache- See Also:
-
CACHE_EMPTY
public static final boolean CACHE_EMPTYEmpty cache status- See Also:
-
CACHING_FINISHED
public static final boolean CACHING_FINISHEDCache ready to use- See Also:
-
IS_PRIME
public static final int IS_PRIMEIndicator if given number is a prime- See Also:
-
IS_NOT_PRIME
public static final int IS_NOT_PRIMEIndicator if given number is not a prime- See Also:
-
NOT_IN_CACHE
public static final int NOT_IN_CACHEIndicator that the value is not stored in cache- See Also:
-
maxNumInCache
int maxNumInCachePrimes between 0 ... and ... maximumNumberInCache will be cached -
numberOfPrimes
int numberOfPrimesNumber of cached prime numbers -
computingTime
double computingTimeTime in seconds showing how long did it take to finalize prime numbers caching. -
cacheStatus
boolean cacheStatusCaching process status -
isPrime
boolean[] isPrimeIntegers table to store number and indicate whether they are prime or not -
initSuccessful
boolean initSuccessfulInternal flag marking that primes cache initialization was successful;
-
-
Constructor Details
-
PrimesCache
public PrimesCache()Default constructor - setting prime cache for a default range if integers -
PrimesCache
public PrimesCache(int maxNumInCache) Constructor - setting prime cache for a given range if integers- Parameters:
maxNumInCache- Range of integers to be stored in prime cache
-
-
Method Details
-
EratosthenesSieve
private void EratosthenesSieve()Eratosthenes Sieve implementation -
countPrimes
private void countPrimes()Counting found primes -
getComputingTime
public double getComputingTime()Returns computing time of Eratosthenes Sieve- Returns:
- Computing time in seconds
-
getCacheStatus
public boolean getCacheStatus()Returns cache status- Returns:
- PrimesCache.CACHE_EMPTY or PrimesCache.CACHING_FINISHED;
-
getNumberOfPrimes
public int getNumberOfPrimes()Returns number of found primes.- Returns:
- Number of found primes.
-
getMaxNumInCache
public int getMaxNumInCache()Returns cache range.- Returns:
- Maximum integera number in cache/
-
primeTest
public int primeTest(int n) Check whether given number is prime- Parameters:
n- Given integer number.- Returns:
- PrimesCache.IS_PRIME or PrimesCache.IS_NOT_PRIME or PrimesCache.NOT_IN_CACHE
-
isInitSuccessful
public boolean isInitSuccessful()Returns true in case when primes cache initialization was successful, otherwise returns false.- Returns:
- Returns true in case when primes cache initialization was successful, otherwise returns false.
-
getPrimes
boolean[] getPrimes()Gets underlying primes cache boolean table- Returns:
- Underlying primes cache boolean table
-