本文整理汇总了Java中org.apache.commons.math3.primes.Primes.nextPrime方法的典型用法代码示例。如果您正苦于以下问题:Java Primes.nextPrime方法的具体用法?Java Primes.nextPrime怎么用?Java Primes.nextPrime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.primes.Primes
的用法示例。
在下文中一共展示了Primes.nextPrime方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: firstNPrimes
import org.apache.commons.math3.primes.Primes; //导入方法依赖的package包/类
public static List<Integer> firstNPrimes(int count) {
LOGGER.debug("Calculating first {} primes", count);
List<Integer> primes = new ArrayList<>(count);
int prime = 2;
for (int i = 0; i < count; i++) {
primes.add(prime);
prime = Primes.nextPrime(prime + 1);
}
return primes;
}
示例2: setNumberOfReducers
import org.apache.commons.math3.primes.Primes; //导入方法依赖的package包/类
protected void setNumberOfReducers(Job job) throws IOException {
long inputSize = getInputSize();
long targetFileSize = getTargetFileSize();
int numReducers = Math.min(Ints.checkedCast(inputSize / targetFileSize) + 1, getMaxNumReducers());
if (this.usePrimeReducers && numReducers != 1) {
numReducers = Primes.nextPrime(numReducers);
}
job.setNumReduceTasks(numReducers);
}
示例3: setNumberOfReducers
import org.apache.commons.math3.primes.Primes; //导入方法依赖的package包/类
/**
* Refer to {@link MRCompactorAvroKeyDedupJobRunner#setNumberOfReducers(Job)}
*/
protected void setNumberOfReducers(Job job) throws IOException {
// get input size
long inputSize = 0;
for (Path inputPath : this.mapReduceInputPaths) {
inputSize += this.fs.getContentSummary(inputPath).getLength();
}
// get target file size
long targetFileSize = this.state.getPropAsLong(MRCompactorAvroKeyDedupJobRunner.COMPACTION_JOB_TARGET_OUTPUT_FILE_SIZE,
MRCompactorAvroKeyDedupJobRunner.DEFAULT_COMPACTION_JOB_TARGET_OUTPUT_FILE_SIZE);
// get max reducers
int maxNumReducers = state.getPropAsInt(MRCompactorAvroKeyDedupJobRunner.COMPACTION_JOB_MAX_NUM_REDUCERS,
MRCompactorAvroKeyDedupJobRunner.DEFAULT_COMPACTION_JOB_MAX_NUM_REDUCERS);
int numReducers = Math.min(Ints.checkedCast(inputSize / targetFileSize) + 1, maxNumReducers);
// get use prime reducers
boolean usePrimeReducers = state.getPropAsBoolean(MRCompactorAvroKeyDedupJobRunner.COMPACTION_JOB_USE_PRIME_REDUCERS,
MRCompactorAvroKeyDedupJobRunner.DEFAULT_COMPACTION_JOB_USE_PRIME_REDUCERS);
if (usePrimeReducers && numReducers != 1) {
numReducers = Primes.nextPrime(numReducers);
}
job.setNumReduceTasks(numReducers);
}
示例4: nextTwinPrime
import org.apache.commons.math3.primes.Primes; //导入方法依赖的package包/类
/**
* Finds next-largest "twin primes": numbers p and p+2 such that both are prime. Finds the smallest such p
* such that the smaller twin, p, is greater than or equal to n. Returns p+2, the larger of the two twins.
*/
public static int nextTwinPrime(int n) {
if (n > MAX_INT_SMALLER_TWIN_PRIME) {
throw new IllegalArgumentException();
}
if (n <= 3) {
return 5;
}
int next = Primes.nextPrime(n);
while (!Primes.isPrime(next + 2)) {
next = Primes.nextPrime(next + 4);
}
return next + 2;
}
示例5: find_next_prime_number_with_apache_commons
import org.apache.commons.math3.primes.Primes; //导入方法依赖的package包/类
@Test
public void find_next_prime_number_with_apache_commons () {
int nextPrimeNumber = Primes.nextPrime(5780);
assertEquals(5783, nextPrimeNumber);
}