本文整理汇总了Java中com.google.common.primitives.UnsignedLongs类的典型用法代码示例。如果您正苦于以下问题:Java UnsignedLongs类的具体用法?Java UnsignedLongs怎么用?Java UnsignedLongs使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnsignedLongs类属于com.google.common.primitives包,在下文中一共展示了UnsignedLongs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: fromString
import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
* Returns PortNumber instance from String representation.
*
* @param s String representation equivalent to {@link PortNumber#toString()}
* @return {@link PortNumber} instance
* @throws IllegalArgumentException if given String was malformed
*/
public static PortNumber fromString(String s) {
checkNotNull(s);
checkArgument(!s.isEmpty(), "cannot be empty");
if (isAsciiDecimal(s.charAt(0))) {
// unsigned decimal string
return portNumber(s);
} else if (s.startsWith("[")) {
// named PortNumber
Matcher matcher = NAMED.matcher(s);
checkArgument(matcher.matches(), "Invalid named PortNumber %s", s);
String name = matcher.group("name");
String num = matcher.group("num");
return portNumber(UnsignedLongs.parseUnsignedLong(num), name);
}
// Logical
if (s.startsWith("UNKNOWN(") && s.endsWith(")")) {
return portNumber(s.substring("UNKNOWN(".length(), s.length() - 1));
} else {
return Logical.valueOf(s).instance;
}
}
示例3: 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);
}
示例4: 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);
}
示例5: parseUnsignedLong
import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
public static long parseUnsignedLong(String st, TExecutionContext context)
{
Object truncated = CastUtils.truncateNonDigits(st, context);
if (truncated instanceof String)
st = (String)truncated;
else
st = CastUtils.truncateNonDigitPlainString(((BigDecimal)truncated).toPlainString(),
context);
long value;
try
{
value = UnsignedLongs.parseUnsignedLong(st);
} catch (NumberFormatException e) { // overflow error
context.reportOverflow(e.getMessage());
// check wether the value is too big or too small
if (st.charAt(0) == '-')
value = 0;
else
value = UnsignedLongs.MAX_VALUE;
}
return value;
}
示例6: newInstance
import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public YamlProject<T> newInstance(final Branch branch) {
try {
// If the branch name contains '/' then use its MD5 hash
// as the project name, but otherwise use the branch name
// for backwards compatibility.
final String hashedName = UnsignedLongs.toString(Hashing.md5().hashString(
branch.getName(), Charsets.UTF_8).asLong(), 16);
final String projectName =
branch.getName().indexOf('/') == -1 ? branch.getName() : hashedName;
final YamlProject<T> project = new YamlProject<T>(
(YamlMultiBranchProject<T>) getOwner(),
projectName, null /* module */);
// Set the display name so that it is always the branch name.
project.setDisplayName(branch.getName());
project.setBranch(branch);
return decorate(project);
} catch (IOException e) {
logger.log(SEVERE, e.getMessage(), e);
return null;
}
}
示例7: 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());
}
}
}
}
示例8: deserialize
import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
* Deserialize circuit id from byte string.
*
* @param circuitId the circuit id byte string
* @return a Circuit Id
*/
public static CircuitId deserialize(byte[] circuitId) {
String cIdString = new String(circuitId, StandardCharsets.US_ASCII);
List<String> splittedCircuitId = Lists.newArrayList(cIdString.split(SEPARATOR));
checkArgument(splittedCircuitId.size() > 1, "Illegal circuit id.");
// remove last element (vlan id)
String vlanId = splittedCircuitId.remove(splittedCircuitId.size() - 1);
// Reconstruct device Id
String connectPoint = String.join(SEPARATOR, splittedCircuitId);
String[] splittedConnectPoint = connectPoint.split(DEVICE_PORT_SEPARATOR);
// Check connect point is valid or not
checkArgument(splittedConnectPoint.length == 2,
"Connect point must be in \"deviceUri/portNumber\" format");
// Check the port number is a number or not
UnsignedLongs.decode(splittedConnectPoint[1]);
return new CircuitId(connectPoint, VlanId.vlanId(vlanId));
}
示例9: compareTo
import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
* Lexicographically compare two arrays.
*
* @param buffer1 left operand: a byte[] or null
* @param buffer2 right operand: a byte[] or null
* @param memoryOffset1 Where to start comparing in the left buffer (pure memory address if buffer1 is null, or relative otherwise)
* @param memoryOffset2 Where to start comparing in the right buffer (pure memory address if buffer1 is null, or relative otherwise)
* @param length1 How much to compare from the left buffer
* @param length2 How much to compare from the right buffer
* @return 0 if equal, < 0 if left is less than right, etc.
*/
public static int compareTo(Object buffer1, long memoryOffset1, int length1,
Object buffer2, long memoryOffset2, int length2)
{
int minLength = Math.min(length1, length2);
/*
* Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
* time is no slower than comparing 4 bytes at a time even on 32-bit.
* On the other hand, it is substantially faster on 64-bit.
*/
int wordComparisons = minLength & ~7;
for (int i = 0; i < wordComparisons ; i += Longs.BYTES)
{
long lw = theUnsafe.getLong(buffer1, memoryOffset1 + (long) i);
long rw = theUnsafe.getLong(buffer2, memoryOffset2 + (long) i);
if (lw != rw)
{
if (BIG_ENDIAN) {
return UnsignedLongs.compare(lw, rw);
}
return UnsignedLongs.compare(Long.reverseBytes(lw), Long.reverseBytes(rw));
}
}
for (int i = wordComparisons ; i < minLength ; i++)
{
int b1 = theUnsafe.getByte(buffer1, memoryOffset1 + i) & 0xFF;
int b2 = theUnsafe.getByte(buffer2, memoryOffset2 + i) & 0xFF;
if (b1 != b2) {
return b1 - b2;
}
}
return length1 - length2;
}
示例10: 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;
}
示例11: 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);
}
示例12: logState
import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
* Logs the current the state of the permutation.
* Intended only for debugging purposes.
*
* @param message message to be used as title of the current state
*/
private void logState(String message) {
String logEntry = message + "[ ";
for (int y = 0; y < 5; y++) {
logEntry += "\t[ ";
for (int x = 0; x < 5; x++) {
logEntry += "0x" + UnsignedLongs.toString(this.state[x][y], 16) + ", ";
}
logEntry += " ]";
}
logEntry += " ]";
//Log.debug(logEntry);
}
示例13: memcmp
import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
private static final int memcmp(final long laddr, int lStart, int lEnd, final long raddr, int rStart, final int rEnd) {
int lLen = lEnd - lStart;
int rLen = rEnd - rStart;
int n = Math.min(rLen, lLen);
long lPos = laddr + lStart;
long rPos = raddr + rStart;
while (n > 7) {
long leftLong = PlatformDependent.getLong(lPos);
long rightLong = PlatformDependent.getLong(rPos);
if (leftLong != rightLong) {
return UnsignedLongs.compare(Long.reverseBytes(leftLong), Long.reverseBytes(rightLong));
}
lPos += 8;
rPos += 8;
n -= 8;
}
while (n-- != 0) {
byte leftByte = PlatformDependent.getByte(lPos);
byte rightByte = PlatformDependent.getByte(rPos);
if (leftByte != rightByte) {
return ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1;
}
lPos++;
rPos++;
}
if (lLen == rLen) {
return 0;
}
return lLen > rLen ? 1 : -1;
}
示例14: decodeLogicalPort
import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
private String decodeLogicalPort() {
Logical logical = LOGICAL.get().get(number);
if (logical != null) {
// enum name
return logical.toString();
}
return String.format("UNKNOWN(%s)", UnsignedLongs.toString(number));
}
示例15: compareTo
import com.google.common.primitives.UnsignedLongs; //导入依赖的package包/类
/**
* Lexicographically compare two arrays.
*
* @param buffer1 left operand: a byte[] or null
* @param buffer2 right operand: a byte[] or null
* @param memoryOffset1 Where to start comparing in the left buffer (pure memory address if buffer1 is null, or relative otherwise)
* @param memoryOffset2 Where to start comparing in the right buffer (pure memory address if buffer1 is null, or relative otherwise)
* @param length1 How much to compare from the left buffer
* @param length2 How much to compare from the right buffer
* @return 0 if equal, < 0 if left is less than right, etc.
*/
public static int compareTo(Object buffer1, long memoryOffset1, int length1,
Object buffer2, long memoryOffset2, int length2) {
int minLength = Math.min(length1, length2);
/*
* Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
* time is no slower than comparing 4 bytes at a time even on 32-bit.
* On the other hand, it is substantially faster on 64-bit.
*/
int wordComparisons = minLength & ~7;
for (int i = 0; i < wordComparisons; i += Longs.BYTES) {
long lw = THE_UNSAFE.getLong(buffer1, memoryOffset1 + (long) i);
long rw = THE_UNSAFE.getLong(buffer2, memoryOffset2 + (long) i);
if (lw != rw) {
if (BIG_ENDIAN) {
return UnsignedLongs.compare(lw, rw);
}
return UnsignedLongs.compare(Long.reverseBytes(lw), Long.reverseBytes(rw));
}
}
for (int i = wordComparisons; i < minLength; i++) {
int b1 = THE_UNSAFE.getByte(buffer1, memoryOffset1 + i) & 0xFF;
int b2 = THE_UNSAFE.getByte(buffer2, memoryOffset2 + i) & 0xFF;
if (b1 != b2) {
return b1 - b2;
}
}
return length1 - length2;
}