本文整理汇总了Java中com.google.common.primitives.UnsignedLongs.compare方法的典型用法代码示例。如果您正苦于以下问题:Java UnsignedLongs.compare方法的具体用法?Java UnsignedLongs.compare怎么用?Java UnsignedLongs.compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.UnsignedLongs
的用法示例。
在下文中一共展示了UnsignedLongs.compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: compareTo
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
public int compareTo(@Nonnull U128 o) {
int msb = UnsignedLongs.compare(this.raw1, o.raw1);
if(msb != 0)
return msb;
else
return UnsignedLongs.compare(this.raw2, o.raw2);
}
示例6: add
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
public U128 add(U128 other) {
long newRaw2 = this.raw2 + other.raw2;
long newRaw1 = this.raw1 + other.raw1;
if(UnsignedLongs.compare(newRaw2, this.raw2) < 0) {
// raw2 overflow
newRaw1+=1;
}
return U128.of(newRaw1, newRaw2);
}
示例7: subtract
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
public U128 subtract(U128 other) {
long newRaw2 = this.raw2 - other.raw2;
long newRaw1 = this.raw1 - other.raw1;
if(UnsignedLongs.compare(this.raw2, other.raw2) < 0) {
newRaw1 -= 1;
}
return U128.of(newRaw1, newRaw2);
}
示例8: assemble
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
void assemble(M68KAssemblyContext context, long count, long itemSize) throws IOException {
// If count * itemSize is greater than UnsignedLongs.MAX_VALUE, don't even try.
if (UnsignedLongs.compare(count, UnsignedLongs.divide(UnsignedLongs.MAX_VALUE, itemSize)) > 0) {
throw new OutOfMemoryError();
}
final long byteCount = count * itemSize;
for (long i = 0; i < byteCount; i++) {
context.appendByte((byte) 0);
}
}
示例9: compareTo
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
public int compareTo(IPv6Address o) {
int res = UnsignedLongs.compare(raw1, o.raw1);
if(res != 0)
return res;
else
return UnsignedLongs.compare(raw2, o.raw2);
}
示例10: compare
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
public int compare(long aPrefix, long bPrefix) {
return UnsignedLongs.compare(aPrefix, bPrefix);
}
示例11: isLessThanUnsigned
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
/**
* Work around lack of unsigned types in Java.
*/
public static boolean isLessThanUnsigned(long n1, long n2) {
return UnsignedLongs.compare(n1, n2) < 0;
}
示例12: isLessThanOrEqualToUnsigned
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
/**
* Work around lack of unsigned types in Java.
*/
public static boolean isLessThanOrEqualToUnsigned(long n1, long n2) {
return UnsignedLongs.compare(n1, n2) <= 0;
}
示例13: compare
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
public int compare(ByteBuffer left, ByteBuffer right) {
if (!left.hasArray() || !right.hasArray()) {
// TODO: might nonetheless be faster to copy bytes out of buffers in chunks of 8
return UnsignedByteBuffer.lexicographicalComparatorJavaImpl().compare(left, right);
}
int initialLeftPosition = left.position();
int initialRightPosition = right.position();
try {
int minLength = Math.min(left.remaining(), right.remaining());
int minWords = minLength / Longs.BYTES;
byte[] leftArray = left.array();
byte[] rightArray = right.array();
int leftOffset = left.arrayOffset() + initialLeftPosition;
int rightOffset = right.arrayOffset() + initialRightPosition;
/* 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. */
for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) {
long lw = theUnsafe.getLong(leftArray, BYTE_ARRAY_BASE_OFFSET + leftOffset + (long) i);
long rw = theUnsafe.getLong(rightArray, BYTE_ARRAY_BASE_OFFSET + rightOffset + (long) i);
if (lw != rw) {
if (BIG_ENDIAN) {
return UnsignedLongs.compare(lw, rw);
}
/* We want to compare only the first index where left[index] != right[index]. This
* corresponds to the least significant nonzero byte in lw ^ rw, since lw and rw are
* little-endian. Long.numberOfTrailingZeros(diff) tells us the least significant nonzero
* bit, and zeroing out the first three bits of L.nTZ gives us the shift to get that least
* significant nonzero byte. */
int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7;
return ((int) ((lw >>> n) & UNSIGNED_MASK)) - ((int) ((rw >>> n) & UNSIGNED_MASK));
}
}
// The epilogue to cover the last (minLength % 8) elements.
for (int i = minWords * Longs.BYTES; i < minLength; i++) {
int result = UnsignedBytes.compare(leftArray[leftOffset + i], rightArray[rightOffset + i]);
if (result != 0) {
return result;
}
}
return left.remaining() - right.remaining();
} finally {
left.position(initialLeftPosition);
right.position(initialRightPosition);
}
}
示例14: compare
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
public int compare(long aPrefix, long bPrefix) {
return UnsignedLongs.compare(aPrefix, bPrefix);
}
示例15: doCompare
import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
protected int doCompare(TInstance typeA, ValueSource sourceA, TInstance typeB, ValueSource sourceB) {
return UnsignedLongs.compare(sourceA.getInt64(), sourceB.getInt64());
}