当前位置: 首页>>代码示例>>Java>>正文


Java Primes.nextPrime方法代码示例

本文整理汇总了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;
}
 
开发者ID:wipu,项目名称:iwant-demo,代码行数:11,代码来源:Mathlib.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:10,代码来源:MRCompactorJobRunner.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:31,代码来源:CompactionAvroJobConfigurator.java

示例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;
}
 
开发者ID:apsaltis,项目名称:oryx,代码行数:18,代码来源:RandomUtils.java

示例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);
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:8,代码来源:NumberIsPrime.java


注:本文中的org.apache.commons.math3.primes.Primes.nextPrime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。