本文整理匯總了Java中com.google.common.math.IntMath.pow方法的典型用法代碼示例。如果您正苦於以下問題:Java IntMath.pow方法的具體用法?Java IntMath.pow怎麽用?Java IntMath.pow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.math.IntMath
的用法示例。
在下文中一共展示了IntMath.pow方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: OoaBFilter
import com.google.common.math.IntMath; //導入方法依賴的package包/類
/**
* Constructs a OoaBFilter with an underlying array of the given size, rounded up to the next
* power of two.
*
* 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++;
}
}
示例2: allGetterFlagsAreAccepted
import com.google.common.math.IntMath; //導入方法依賴的package包/類
@Test
public void allGetterFlagsAreAccepted() {
final RequestLogAvailability[] values = RequestLogAvailability.values();
final int end = IntMath.pow(2, values.length);
for (int i = 0; i < end; i++) {
int flags = 0;
for (RequestLogAvailability v : values) {
if ((i & 1 << v.ordinal()) != 0) {
flags |= v.getterFlags();
}
}
if (flags != 0) {
assertThat(RequestLogAvailabilitySet.of(flags)).isNotEmpty();
}
}
}
示例3: testCounts
import com.google.common.math.IntMath; //導入方法依賴的package包/類
@Test
public void testCounts() {
String ascii = "abcdefghijklmnopqrstuvwxyz";
String range = ascii.toLowerCase() + ascii.toUpperCase();
int rangeA = IntMath.pow(range.length(), 1);
assertEquals(rangeA, Iterables.size(new Mutator(range, 1, 1).mutate()));
int rangeB = IntMath.pow(range.length(), 2) + rangeA;
assertEquals(rangeB, Iterables.size(new Mutator(range, 1, 2).mutate()));
int rangeC = IntMath.pow(range.length(), 3) + rangeB;
assertEquals(rangeC, Iterables.size(new Mutator(range, 1, 3).mutate()));
int rangeD = IntMath.pow(range.length(), 4) + rangeC;
assertEquals(rangeD, Iterables.size(new Mutator(range, 1, 4).mutate()));
}
示例4: getInteger
import com.google.common.math.IntMath; //導入方法依賴的package包/類
protected static int getInteger(byte[] b) {
int sum = 0;
for (int i = 0; i < b.length; i++) {
final int reverseIndex = b.length - 1 - i;
final int factor = IntMath.pow(256, reverseIndex);
final int base = UnsignedBytes.toInt(b[i]);
sum += base * factor;
}
return sum;
}
示例5: UnBloomFilter
import com.google.common.math.IntMath; //導入方法依賴的package包/類
/**
* Constructs a OoaBFilter with an underlying array of the given size, rounded up to the next
* power of two.
* <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;
}
示例6: ByteArrayFilter
import com.google.common.math.IntMath; //導入方法依賴的package包/類
/**
* Constructs a ByteArrayFilter with an underlying array of the given size, rounded up to the next
* power of two.
*
* 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);
}
示例7: pow
import com.google.common.math.IntMath; //導入方法依賴的package包/類
@Benchmark int pow(int reps) {
int tmp = 0;
for (int i = 0; i < reps; i++) {
int j = i & ARRAY_MASK;
tmp += IntMath.pow(positive[j], exponent[j]);
}
return tmp;
}
示例8: getBooleanFunctionParamsMap
import com.google.common.math.IntMath; //導入方法依賴的package包/類
/**
* Returns a map that maps each boolean function to the parameters for the function.
*/
public static Map<Integer, int[]> getBooleanFunctionParamsMap(int inputCount, int paramCount,
ParameterizedBooleanFunction booleanFunction) {
Map<Integer, int[]> booleanFunctionParamsMap = new TreeMap<>();
for (int cnt = 0; cnt < IntMath.pow(2, paramCount); cnt++) {
int[] params = getBitsAsIntArray(cnt);
int function = getBooleanFunctionValues(inputCount, booleanFunction, params);
booleanFunctionParamsMap.put(function, params);
}
return booleanFunctionParamsMap;
}
示例9: getBooleanFunctionValues
import com.google.common.math.IntMath; //導入方法依賴的package包/類
/**
* Returns the integer that uniquely represents the boolean function specified by the given
* parameters.
*/
public static int getBooleanFunctionValues(int inputCount,
ParameterizedBooleanFunction booleanFunction, int[] params) {
int value = 0;
for (int inputValue = 0; inputValue < IntMath.pow(2, inputCount); inputValue++) {
value <<= 1;
value |= booleanFunction.getValue(getBitsAsIntArray(inputValue), params);
}
return value;
}
示例10: OoaBFilter
import com.google.common.math.IntMath; //導入方法依賴的package包/類
public OoaBFilter(int size) {
leastSignificantBitsArray = new long[size];
mostSignificantBitsArray = new long[size];
this.sizeMask = IntMath.pow(2, IntMath.log2(size, RoundingMode.CEILING)) - 1;
}
示例11: hashCode
import com.google.common.math.IntMath; //導入方法依賴的package包/類
@Override public int hashCode() {
return getLeft().hashCode() + (IntMath.pow(31, getLeft().size()) * getRight().hashCode());
}
示例12: pow
import com.google.common.math.IntMath; //導入方法依賴的package包/類
/**
* 平方
*
* @param k
* 平方次數,不能為負數, k=0時返回1.
*/
public static int pow(int b, int k) {
return IntMath.pow(b, k);
}