本文整理汇总了Java中com.google.common.primitives.UnsignedLongs.remainder方法的典型用法代码示例。如果您正苦于以下问题:Java UnsignedLongs.remainder方法的具体用法?Java UnsignedLongs.remainder怎么用?Java UnsignedLongs.remainder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.UnsignedLongs
的用法示例。
在下文中一共展示了UnsignedLongs.remainder方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: squareMod
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
long squareMod(long a, long m) {
long aHi = a >>> 32; // < 2^31
long aLo = a & 0xFFFFFFFFL; // < 2^32
/*
* a^2 == aHi^2 * 2^64 + aHi * aLo * 2^33 + aLo^2
* == (aHi^2 * 2^32 + aHi * aLo * 2) * 2^32 + aLo^2
* We carry out this computation in modular arithmetic. Since times2ToThe32Mod accepts any
* unsigned long, we don't have to do a mod on every operation, only when intermediate
* results can exceed 2^63.
*/
long result = times2ToThe32Mod(aHi * aHi /* < 2^62 */, m); // < m < 2^63
long hiLo = aHi * aLo * 2;
if (hiLo < 0) {
hiLo = UnsignedLongs.remainder(hiLo, m);
}
// hiLo < 2^63
result += hiLo; // result < 2^64
result = times2ToThe32Mod(result, m); // result < m < 2^63
return plusMod(
result,
UnsignedLongs.remainder(aLo * aLo /* < 2^64 */, m),
m);
}
示例2: mulMod
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
long mulMod(long a, long b, long m) {
long aHi = a >>> 32; // < 2^31
long bHi = b >>> 32; // < 2^31
long aLo = a & 0xFFFFFFFFL; // < 2^32
long bLo = b & 0xFFFFFFFFL; // < 2^32
/*
* a * b == aHi * bHi * 2^64 + (aHi * bLo + aLo * bHi) * 2^32 + aLo * bLo.
* == (aHi * bHi * 2^32 + aHi * bLo + aLo * bHi) * 2^32 + aLo * bLo
*
* We carry out this computation in modular arithmetic. Since times2ToThe32Mod accepts any
* unsigned long, we don't have to do a mod on every operation, only when intermediate
* results can exceed 2^63.
*/
long result = times2ToThe32Mod(aHi * bHi /* < 2^62 */, m); // < m < 2^63
result += aHi * bLo; // aHi * bLo < 2^63, result < 2^64
if (result < 0) {
result = UnsignedLongs.remainder(result, m);
}
// result < 2^63 again
result += aLo * bHi; // aLo * bHi < 2^63, result < 2^64
result = times2ToThe32Mod(result, m); // result < m < 2^63
return plusMod(result, UnsignedLongs.remainder(aLo * bLo /* < 2^64 */, m), m);
}
示例3: squareMod
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
long squareMod(long a, long m) {
long aHi = a >>> 32; // < 2^31
long aLo = a & 0xFFFFFFFFL; // < 2^32
/*
* a^2 == aHi^2 * 2^64 + aHi * aLo * 2^33 + aLo^2
* == (aHi^2 * 2^32 + aHi * aLo * 2) * 2^32 + aLo^2
* We carry out this computation in modular arithmetic. Since times2ToThe32Mod accepts any
* unsigned long, we don't have to do a mod on every operation, only when intermediate
* results can exceed 2^63.
*/
long result = times2ToThe32Mod(aHi * aHi /* < 2^62 */, m); // < m < 2^63
long hiLo = aHi * aLo * 2;
if (hiLo < 0) {
hiLo = UnsignedLongs.remainder(hiLo, m);
}
// hiLo < 2^63
result += hiLo; // result < 2^64
result = times2ToThe32Mod(result, m); // result < m < 2^63
return plusMod(result, UnsignedLongs.remainder(aLo * aLo /* < 2^64 */, m), m);
}
示例4: assemble
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
void assemble(M68KAssemblyContext context) throws IOException {
context.sizeNotAllowed();
if (context.requireNumberOfOperands(1)) {
final Value alignmentValue = evaluateExpressionOperand(context, 0);
if (alignmentValue != null) {
final CardinalValueVisitor alignmentVisitor = context.cardinalValueVisitor;
alignmentVisitor.reset(1, NEGATIVE_VALUE_ERROR_FACTORY);
Value.accept(alignmentValue, alignmentVisitor);
final long alignment = alignmentVisitor.getValue();
if (alignment != 0) {
final long remainder = UnsignedLongs.remainder(context.programCounter, alignment);
final long paddingSize = remainder == 0 ? 0 : alignment - remainder;
for (long i = 0; UnsignedLongs.compare(i, paddingSize) < 0; i++) {
context.appendByte((byte) 0);
}
} else {
context.addTentativeMessage(new AlignmentMustNotBeZeroOrNegativeErrorMessage());
}
}
}
}
示例5: times2ToThe32Mod
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
/**
* Returns (a * 2^32) mod m. a may be any unsigned long.
*/
private long times2ToThe32Mod(long a, long m) {
int remainingPowersOf2 = 32;
do {
int shift = Math.min(remainingPowersOf2, Long.numberOfLeadingZeros(a));
// shift is either the number of powers of 2 left to multiply a by, or the biggest shift
// possible while keeping a in an unsigned long.
a = UnsignedLongs.remainder(a << shift, m);
remainingPowersOf2 -= shift;
} while (remainingPowersOf2 > 0);
return a;
}
示例6: mulMod
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
long mulMod(long a, long b, long m) {
long aHi = a >>> 32; // < 2^31
long bHi = b >>> 32; // < 2^31
long aLo = a & 0xFFFFFFFFL; // < 2^32
long bLo = b & 0xFFFFFFFFL; // < 2^32
/*
* a * b == aHi * bHi * 2^64 + (aHi * bLo + aLo * bHi) * 2^32 + aLo * bLo.
* == (aHi * bHi * 2^32 + aHi * bLo + aLo * bHi) * 2^32 + aLo * bLo
*
* We carry out this computation in modular arithmetic. Since times2ToThe32Mod accepts any
* unsigned long, we don't have to do a mod on every operation, only when intermediate
* results can exceed 2^63.
*/
long result = times2ToThe32Mod(aHi * bHi /* < 2^62 */, m); // < m < 2^63
result += aHi * bLo; // aHi * bLo < 2^63, result < 2^64
if (result < 0) {
result = UnsignedLongs.remainder(result, m);
}
// result < 2^63 again
result += aLo * bHi; // aLo * bHi < 2^63, result < 2^64
result = times2ToThe32Mod(result, m); // result < m < 2^63
return plusMod(
result,
UnsignedLongs.remainder(aLo * bLo /* < 2^64 */, m),
m);
}
示例7: times2ToThe32Mod
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
/**
* Returns (a * 2^32) mod m. a may be any unsigned long.
*/
private long times2ToThe32Mod(long a, long m) {
int remainingPowersOf2 = 32;
do {
int shift = Math.min(remainingPowersOf2, Long.numberOfLeadingZeros(a));
// shift is either the number of powers of 2 left to multiply a by, or the biggest shift
// possible while keeping a in an unsigned long.
a = UnsignedLongs.remainder(a << shift, m);
remainingPowersOf2 -= shift;
} while (remainingPowersOf2 > 0);
return a;
}
示例8: times2ToThe32Mod
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
/** Returns (a * 2^32) mod m. a may be any unsigned long. */
private long times2ToThe32Mod(long a, long m) {
int remainingPowersOf2 = 32;
do {
int shift = Math.min(remainingPowersOf2, Long.numberOfLeadingZeros(a));
// shift is either the number of powers of 2 left to multiply a by, or the biggest shift
// possible while keeping a in an unsigned long.
a = UnsignedLongs.remainder(a << shift, m);
remainingPowersOf2 -= shift;
} while (remainingPowersOf2 > 0);
return a;
}
示例9: getWantedSlot
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
private static long getWantedSlot(long hash, long capacity) {
return UnsignedLongs.remainder(hash, capacity);
}