Skip to content

[NUMBERS-133] Use iteration algorithm from bounded trial division in Primes.nextPrime(int) #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
NUMBERS-133: Rename method potentialPrimes(int) to potentialPrimesGTE…
…(int)
  • Loading branch information
Schamschi committed Jul 25, 2019
commit a2e75b76d53f93d16a67e8477bef61895d482662
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static int nextPrime(int n) {
}
return SmallPrimes.PRIMES[index];
} else {
PrimitiveIterator.OfInt potentialPrimesIterator = SmallPrimes.potentialPrimes(n);
PrimitiveIterator.OfInt potentialPrimesIterator = SmallPrimes.potentialPrimesGTE(n);
while (true) {
// Integer.MAX_VALUE is a prime number, so no risk of overflow
int candidate = potentialPrimesIterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SmallPrimes {
* {@code product - 1}, because if {@code product ≡ 0 mod p}, then
* {@code product - 1 ≡ -1 mod p}, and {@code 0 ≢ -1 mod p} for any prime number p.</p>
*
* @see #potentialPrimes(int)
* @see #potentialPrimesGTE(int)
*/
static final Entry<Set<Integer>, int[]> PRIME_NUMBERS_AND_COPRIME_EQUIVALENCE_CLASSES;

Expand Down Expand Up @@ -175,7 +175,7 @@ static int smallTrialDivision(int n,
static int boundedTrialDivision(int n,
int maxFactor,
List<Integer> factors) {
PrimitiveIterator.OfInt potentialPrimesIterator = potentialPrimes(PRIMES_LAST + 2);
PrimitiveIterator.OfInt potentialPrimesIterator = potentialPrimesGTE(PRIMES_LAST + 2);

boolean done = false;
while (!done) {
Expand Down Expand Up @@ -266,7 +266,7 @@ static boolean millerRabinPrimeTest(final int n) {

/**
* Returns an iterator that iterates, in ascending oder, over all positive
* integers greater than or equal to the passed lower bound, skipping
* integers greater than or equal to ("GTE") the passed lower bound, skipping
* numbers that are a multiple of any of the prime numbers contained in the
* key of {@link #PRIME_NUMBERS_AND_COPRIME_EQUIVALENCE_CLASSES}.
*
Expand All @@ -282,7 +282,7 @@ static boolean millerRabinPrimeTest(final int n) {
* @param lowerBound the lower bound for the iteration results
* @return an iterator as described above
*/
static PrimitiveIterator.OfInt potentialPrimes(final int lowerBound) {
static PrimitiveIterator.OfInt potentialPrimesGTE(final int lowerBound) {
/*
* The numbers that should be iterated over are of the form k*m + c,
* where k >= 0, m is the least common multiple, that is, the product of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testPotentialPrimes() {
}

private void testPotentialPrimes(int lowerBound, int maxIterations) {
PrimitiveIterator.OfInt potentialPrimesIterator = SmallPrimes.potentialPrimes(lowerBound);
PrimitiveIterator.OfInt potentialPrimesIterator = SmallPrimes.potentialPrimesGTE(lowerBound);

int iterationCount = 0;
boolean overflow = false;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy