/** * If more than this many consecutive positions are filled in a table of the specified size, * report probable hash flooding. */ static int maxRunBeforeFallback(int tableSize) { return MAX_RUN_MULTIPLIER * IntMath.log2(tableSize, RoundingMode.UNNECESSARY); }
private static int ceilToPowerOfTwo(int x) { return 1 << IntMath.log2(x, RoundingMode.CEILING); }
private static int ceilToPowerOfTwo(int x) { return 1 << IntMath.log2(x, RoundingMode.CEILING); }
/** * If more than this many consecutive positions are filled in a table of the specified size, * report probable hash flooding. */ static int maxRunBeforeFallback(int tableSize) { return MAX_RUN_MULTIPLIER * IntMath.log2(tableSize, RoundingMode.UNNECESSARY); }
private static int ceilToPowerOfTwo(int x) { return 1 << IntMath.log2(x, RoundingMode.CEILING); }
int maxIterations = IntMath.log2(right - left, RoundingMode.CEILING) * 3; while (left < right) { int pivotIndex = (left + right + 1) >>> 1;
this.chars = checkNotNull(chars); try { this.bitsPerChar = log2(chars.length, UNNECESSARY); } catch (ArithmeticException e) { throw new IllegalArgumentException("Illegal alphabet length " + chars.length, e);
public void testLog2ZeroAlwaysThrows() { for (RoundingMode mode : ALL_ROUNDING_MODES) { try { IntMath.log2(0, mode); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } } }
public void testLog2NegativeAlwaysThrows() { for (int x : NEGATIVE_INTEGER_CANDIDATES) { for (RoundingMode mode : ALL_ROUNDING_MODES) { try { IntMath.log2(x, mode); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } } } }
int maxIterations = IntMath.log2(right - left, RoundingMode.CEILING) * 3; while (left < right) { int pivotIndex = (left + right + 1) >>> 1;
this.chars = checkNotNull(chars); try { this.bitsPerChar = log2(chars.length, UNNECESSARY); } catch (ArithmeticException e) { throw new IllegalArgumentException("Illegal alphabet length " + chars.length, e);
int approxSize = IntMath.divide(n * IntMath.log2(n, CEILING), Long.SIZE, CEILING); ArrayList<BigInteger> bignums = new ArrayList<>(approxSize);
int maxIterations = IntMath.log2(right - left, RoundingMode.CEILING) * 3; while (left < right) { int pivotIndex = (left + right + 1) >>> 1;
public void testLog2MatchesBigInteger() { for (int x : POSITIVE_INTEGER_CANDIDATES) { for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) { assertEquals(BigIntegerMath.log2(valueOf(x), mode), IntMath.log2(x, mode)); } } }
this.chars = checkNotNull(chars); try { this.bitsPerChar = log2(chars.length, UNNECESSARY); } catch (ArithmeticException e) { throw new IllegalArgumentException("Illegal alphabet length " + chars.length, e);
int approxSize = IntMath.divide(n * IntMath.log2(n, CEILING), Long.SIZE, CEILING); ArrayList<BigInteger> bignums = new ArrayList<>(approxSize);
int approxSize = IntMath.divide(n * IntMath.log2(n, CEILING), Long.SIZE, CEILING); ArrayList<BigInteger> bignums = new ArrayList<>(approxSize);
public void testLog2Exact() { for (int x : POSITIVE_INTEGER_CANDIDATES) { // We only expect an exception if x was not a power of 2. boolean isPowerOf2 = IntMath.isPowerOfTwo(x); try { assertEquals(x, 1 << IntMath.log2(x, UNNECESSARY)); assertTrue(isPowerOf2); } catch (ArithmeticException e) { assertFalse(isPowerOf2); } } }
public void testWorstCase() { int n = 2000000; int k = 200000; final long[] compareCalls = {0}; Comparator<Integer> cmp = new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { compareCalls[0]++; return o1.compareTo(o2); } }; TopKSelector<Integer> top = TopKSelector.least(k, cmp); top.offer(1); for (int i = 1; i < n; i++) { top.offer(0); } assertThat(top.topK()).containsExactlyElementsIn(Collections.nCopies(k, 0)); assertThat(compareCalls[0]).isAtMost(10L * n * IntMath.log2(k, RoundingMode.CEILING)); } }
public OoaBFilter(int size) { leastSignificantBitsArray = new long[size]; mostSignificantBitsArray = new long[size]; this.sizeMask = IntMath.pow(2, IntMath.log2(size, RoundingMode.CEILING)) - 1; }