List of usage examples for com.google.common.math IntMath log2
@SuppressWarnings("fallthrough") public static int log2(int x, RoundingMode mode)
From source file:se.toxbee.sleepfighter.utils.math.Conversion.java
/** * Converts an integer with unknown base to a boolean array. * * @param i the integer./*from w w w .ja v a 2s. c om*/ * @return the resultant boolean array. */ public static boolean[] intToBoolArray(final int i) { return intToBoolArray(i, IntMath.log2(i, RoundingMode.FLOOR)); }
From source file:spimedb.util.bloom.ByteArrayFilter.java
/** * Constructs a ByteArrayFilter with an underlying array of the given size, rounded up to the next * power of two./* w ww . ja v a 2s .c o m*/ * * This rounding occurs because the hashing is much faster on an array the size of a power of two. * If you really want a different sized array, used the AtomicReferenceArray constructor. * * @param size The size of the underlying array. */ public ByteArrayFilter(int size) { if (size <= 0) { throw new IllegalArgumentException("array size must be greater than zero, was " + size); } if (size > MAX_SIZE) { throw new IllegalArgumentException( "array size may not be larger than 2**31-1, but will be rounded to larger. was " + size); } // round to the next largest power of two int poweredSize = IntMath.pow(2, IntMath.log2(size, RoundingMode.CEILING)); this.sizeMask = poweredSize - 1; this.array = new AtomicReferenceArray<>(poweredSize); }
From source file:spimedb.util.bloom.UnBloomFilter.java
/** * Constructs a OoaBFilter with an underlying array of the given size, rounded up to the next * power of two.// w w w.j av a2 s . c om * <p> * This rounding occurs because the hashing is much faster on an array the size of a power of two. * * @param size The size of the underlying array. * @param asBytes */ public UnBloomFilter(int size, Function<X, byte[]> asBytes) { final int MAX_SIZE = 1 << 30; if (size <= 0 || size > MAX_SIZE) { throw new IllegalArgumentException( "array size must be greater than 0 and array size may not be larger than 2**31-1, but will be rounded to larger. was " + size); } this.asBytes = asBytes; int poweredSize = IntMath.pow(2, IntMath.log2(size, RoundingMode.CEILING)); // round to the next largest power of two this.array = new AtomicReferenceArray(poweredSize); this.sizeMask = poweredSize - 1; }
From source file:spimedb.util.bloom.OoaBFilter.java
/** * Constructs a OoaBFilter with an underlying array of the given size, rounded up to the next * power of two./* w w w.j ava2s. com*/ * * This rounding occurs because the hashing is much faster on an array the size of a power of two. * * @param size The size of the underlying array. * @param bufSize The size of the buffers occupying each slot in the array. */ public OoaBFilter(int size, int bufSize) { if (size <= 0) { throw new IllegalArgumentException("array size must be greater than zero, was " + size); } if (size > MAX_SIZE) { throw new IllegalArgumentException( "array size may not be larger than 2**31-1, but will be rounded to larger. was " + size); } // round to the next largest power of two int poweredSize = IntMath.pow(2, IntMath.log2(size, RoundingMode.CEILING)); this.sizeMask = poweredSize - 1; this.array = new ByteBuffer[poweredSize]; // pre-allocate a ByteBuffer for each slot in the array int i = 0; while (i < poweredSize) { array[i] = ByteBuffer.allocate(bufSize); i++; } }
From source file:graphene.util.ooab.ByteArrayFilter.java
/** * Constructs a ByteArrayFilter with an underlying array of the given size, rounded up to the next * power of two./*from w ww. ja v a 2s . c om*/ * * This rounding occurs because the hashing is much faster on an array the size of a power of two. * If you really want a different sized array, used the AtomicReferenceArray constructor. * * @param size The size of the underlying array. */ public ByteArrayFilter(int size) { if (size <= 0) { throw new IllegalArgumentException("array size must be greater than zero, was " + size); } if (size > MAX_SIZE) { throw new IllegalArgumentException( "array size may not be larger than 2**31-1, but will be rounded to larger. was " + size); } // round to the next largest power of two int poweredSize = IntMath.pow(2, IntMath.log2(size, RoundingMode.CEILING)); this.sizeMask = poweredSize - 1; this.array = new AtomicReferenceArray<byte[]>(poweredSize); }