Java Code Examples for com.google.common.math.IntMath#ceilingPowerOfTwo()

The following examples show how to use com.google.common.math.IntMath#ceilingPowerOfTwo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CountMin4.java    From caffeine with Apache License 2.0 5 votes vote down vote up
/**
 * Increases the capacity of this <tt>FrequencySketch</tt> instance, if necessary, to ensure that
 * it can accurately estimate the popularity of elements given the maximum size of the cache. This
 * operation forgets all previous counts when resizing.
 *
 * @param maximumSize the maximum size of the cache
 */
protected void ensureCapacity(long maximumSize) {
  checkArgument(maximumSize >= 0);
  int maximum = (int) Math.min(maximumSize, Integer.MAX_VALUE >>> 1);
  if ((table != null) && (table.length >= maximum)) {
    return;
  }

  table = new long[(maximum == 0) ? 1 : IntMath.ceilingPowerOfTwo(maximum)];
  tableMask = Math.max(0, table.length - 1);
}
 
Example 2
Source File: GuavaIntMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenProformCeilPowOfTwoIntegerValues_shouldReturnResult() {
    int result = IntMath.ceilingPowerOfTwo(20);
    assertEquals(32, result);
}
 
Example 3
Source File: MathUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 往上找出最接近的2的倍数,比如15返回16, 17返回32.
 * 
 * @param value 必须为正数,否则抛出异常.
 */
public static int nextPowerOfTwo(int value) {
	return IntMath.ceilingPowerOfTwo(value);
}
 
Example 4
Source File: MathUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 往上找出最接近的2的倍数,比如15返回16, 17返回32.
 * 
 * @param value 必须为正数,否则抛出异常.
 */
public static int nextPowerOfTwo(int value) {
	return IntMath.ceilingPowerOfTwo(value);
}
 
Example 5
Source File: MathUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * 往上找出最接近的2的倍数,比如15返回16, 17返回32.
 * 
 * @param value必须为正数,否则抛出异常.
 */
public static int nextPowerOfTwo(int value) {
	return IntMath.ceilingPowerOfTwo(value);
}