Java Code Examples for com.google.common.math.IntMath#log2()
The following examples show how to use
com.google.common.math.IntMath#log2() .
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: LayersCalculator.java From compass with GNU Affero General Public License v3.0 | 6 votes |
List<List<String>> calculateAllLayers(List<String> addresses) { int depth = IntMath.log2(addresses.size(), RoundingMode.FLOOR); List<List<String>> layers = new ArrayList<>(depth); List<String> last = addresses; layers.add(last); while (depth-- > 0) { log.info("Calculating nodes for depth " + depth); last = calculateNextLayer(last); layers.add(last); } Collections.reverse(layers); return layers; }
Example 2
Source File: PropertyInteger.java From Cleanstone with MIT License | 5 votes |
public PropertyInteger(String key, int minValue, int maxValue) { super(key); this.minValue = minValue; this.maxValue = maxValue; totalValuesAmount = maxValue - minValue + 1; this.maxSerializationBits = IntMath.log2(totalValuesAmount, RoundingMode.CEILING); }
Example 3
Source File: TreeCode.java From digdag with Apache License 2.0 | 5 votes |
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); }
Example 4
Source File: GuavaMathUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void should_round_log2_result() { int result1 = IntMath.log2(5, RoundingMode.FLOOR); assertThat(result1, equalTo(2)); int result2 = IntMath.log2(5, RoundingMode.CEILING); assertThat(result2, equalTo(3)); }
Example 5
Source File: PropertyEnum.java From Cleanstone with MIT License | 4 votes |
public PropertyEnum(String key, Class<E> enumClass) { super(key); this.enumClass = enumClass; totalValuesAmount = enumClass.getEnumConstants().length; maxSerializationBits = IntMath.log2(totalValuesAmount, RoundingMode.CEILING); }
Example 6
Source File: Striped.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
private static int ceilToPowerOfTwo(int x) { return 1 << IntMath.log2(x, RoundingMode.CEILING); }
Example 7
Source File: Striped.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
private static int ceilToPowerOfTwo(int x) { return 1 << IntMath.log2(x, RoundingMode.CEILING); }
Example 8
Source File: Striped.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
private static int ceilToPowerOfTwo(int x) { return 1 << IntMath.log2(x, RoundingMode.CEILING); }
Example 9
Source File: Striped.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
private static int ceilToPowerOfTwo(int x) { return 1 << IntMath.log2(x, RoundingMode.CEILING); }
Example 10
Source File: Striped.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
private static int ceilToPowerOfTwo(int x) { return 1 << IntMath.log2(x, RoundingMode.CEILING); }
Example 11
Source File: BDDFiniteDomain.java From batfish with Apache License 2.0 | 4 votes |
private static int computeBitsRequired(int size) { if (size < 2) { return 0; } return IntMath.log2(size, RoundingMode.CEILING); }
Example 12
Source File: GuavaIntMathUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenLog2IntegerValues_shouldLog2ThemAndReturnTheResultForCeilingRounding() { int result = IntMath.log2(30, RoundingMode.CEILING); assertEquals(5, result); }
Example 13
Source File: GuavaIntMathUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenLog2IntegerValues_shouldog2ThemAndReturnTheResultForFloorRounding() { int result = IntMath.log2(30, RoundingMode.FLOOR); assertEquals(4, result); }
Example 14
Source File: GuavaIntMathUnitTest.java From tutorials with MIT License | 4 votes |
@Test(expected = ArithmeticException.class) public void whenLog2IntegerValues_shouldThrowArithmeticExceptionIfRoundingNotDefinedButNecessary() { IntMath.log2(30, RoundingMode.UNNECESSARY); }