本文整理匯總了Java中com.google.common.math.IntMath.log2方法的典型用法代碼示例。如果您正苦於以下問題:Java IntMath.log2方法的具體用法?Java IntMath.log2怎麽用?Java IntMath.log2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.math.IntMath
的用法示例。
在下文中一共展示了IntMath.log2方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: trim
import com.google.common.math.IntMath; //導入方法依賴的package包/類
/**
* Quickselects the top k elements from the 2k elements in the buffer. O(k) expected time,
* O(k log k) worst case.
*/
private void trim() {
int left = 0;
int right = 2 * k - 1;
int minThresholdPosition = 0;
// The leftmost position at which the greatest of the k lower elements
// -- the new value of threshold -- might be found.
int iterations = 0;
int maxIterations = IntMath.log2(right - left, RoundingMode.CEILING) * 3;
while (left < right) {
int pivotIndex = (left + right + 1) >>> 1;
int pivotNewIndex = partition(left, right, pivotIndex);
if (pivotNewIndex > k) {
right = pivotNewIndex - 1;
} else if (pivotNewIndex < k) {
left = Math.max(pivotNewIndex, left + 1);
minThresholdPosition = pivotNewIndex;
} else {
break;
}
iterations++;
if (iterations >= maxIterations) {
// We've already taken O(k log k), let's make sure we don't take longer than O(k log k).
Arrays.sort(buffer, left, right, comparator);
break;
}
}
bufferSize = k;
threshold = buffer[minThresholdPosition];
for (int i = minThresholdPosition + 1; i < k; i++) {
if (comparator.compare(buffer[i], threshold) > 0) {
threshold = buffer[i];
}
}
}
示例2: log2
import com.google.common.math.IntMath; //導入方法依賴的package包/類
@Benchmark int log2(int reps) {
int tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
tmp += IntMath.log2(positive[j], mode);
}
return tmp;
}
示例3: add
import com.google.common.math.IntMath; //導入方法依賴的package包/類
public void add(int t)
{
int x = t + 1;
int e = IntMath.log2(x, RoundingMode.FLOOR);
long d = x - (1L << e);
long v = (((1 << e) - 1) << (1 + e)) | d;
int bits = 2 * e + 1;
if (off - bits < 6) {
throw new IllegalStateException("TreeCode overflow");
}
off -= bits;
x63 |= (v << off);
}
示例4: trim
import com.google.common.math.IntMath; //導入方法依賴的package包/類
/**
* Quickselects the top k elements from the 2k elements in the buffer. O(k) expected time, O(k log
* k) worst case.
*/
private void trim() {
int left = 0;
int right = 2 * k - 1;
int minThresholdPosition = 0;
// The leftmost position at which the greatest of the k lower elements
// -- the new value of threshold -- might be found.
int iterations = 0;
int maxIterations = IntMath.log2(right - left, RoundingMode.CEILING) * 3;
while (left < right) {
int pivotIndex = (left + right + 1) >>> 1;
int pivotNewIndex = partition(left, right, pivotIndex);
if (pivotNewIndex > k) {
right = pivotNewIndex - 1;
} else if (pivotNewIndex < k) {
left = Math.max(pivotNewIndex, left + 1);
minThresholdPosition = pivotNewIndex;
} else {
break;
}
iterations++;
if (iterations >= maxIterations) {
// We've already taken O(k log k), let's make sure we don't take longer than O(k log k).
Arrays.sort(buffer, left, right, comparator);
break;
}
}
bufferSize = k;
threshold = buffer[minThresholdPosition];
for (int i = minThresholdPosition + 1; i < k; i++) {
if (comparator.compare(buffer[i], threshold) > 0) {
threshold = buffer[i];
}
}
}
示例5: ceilToPowerOfTwo
import com.google.common.math.IntMath; //導入方法依賴的package包/類
private static int ceilToPowerOfTwo(int x) {
return 1 << IntMath.log2(x, RoundingMode.CEILING);
}
示例6: PathsRec
import com.google.common.math.IntMath; //導入方法依賴的package包/類
public PathsRec(BDDFactory fac, Board board) {
this.fac = fac;
this.board = board;
cache = new BddCacheHavannah();
// this.pathLength = IntMath.log2(
// board.getBoardSize() * board.getBoardSize(),
// RoundingMode.HALF_UP);
// System.out
// .println("all cells: " + board.getColumns() * board.getRows());
// System.out.println("legal cells: " + board.getPositions().size());
Collection<Position> valid = Collections2.filter(board.getPositions(),
new ValidPositionFilter(board));
this.pathLength = IntMath.log2(valid.size(), RoundingMode.HALF_UP);
// this.pathLength = 1;
this.rec = 0;
// System.out.println("starting distance calculation");
// distance = new HashMap<com.strategy.api.logic.BddCache.BddCacheIndex,
// Set<Position>>();
// for (Position p : board.getPositions()) {
// if (!board.isValidField(p)) {
// continue;
// }
// for (Position q : board.getPositions()) {
// if (!board.isValidField(q) || p.equals(q)) {
// continue;
// }
// for (int i = 0; i <= pathLength; i++) {
// distance.put(com.strategy.api.logic.BddCache.BddCacheIndex
// .getIndex(StoneColor.EMPTY, p, q, i),
// getIntermediateNodes(p, q, i));
// }
// }
// }
// System.out.println("finished distance calculation");
Debug initlog = Debug.create("recursively creating reachability");
for (Position p : board.getPositions()) {
// System.out.println("checking for doing for p="+p);
if (!board.isValidField(p)) {
continue;
}
// System.out.println("doing for p="+p);
for (Position q : board.getPositions()) {
// System.out.println("checking for doing for q="+p);
if (!board.isValidField(q) || p.equals(q) || p.isNeighbour(q)) {
continue;
}
// System.out.println("doing for q= "+q);
getPathTransitiveClosure(p, q, StoneColor.WHITE);
getPathTransitiveClosure(p, q, StoneColor.BLACK);
}
}
initlog.log();
// System.out.println("path length: "+pathLength);
}