当前位置: 首页>>代码示例>>Java>>正文


Java UnsignedLongs.compare方法代码示例

本文整理汇总了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());
            }
        }
    }
}
 
开发者ID:reasm,项目名称:reasm-m68k,代码行数:24,代码来源:AlignDirective.java

示例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;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:50,代码来源:FastByteOperations.java

示例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;

}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:36,代码来源:ByteFunctionHelpers.java

示例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;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:46,代码来源:FastByteOperations.java

示例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);
}
 
开发者ID:o3project,项目名称:openflowj-otn,代码行数:9,代码来源:U128.java

示例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);
}
 
开发者ID:o3project,项目名称:openflowj-otn,代码行数:11,代码来源:U128.java

示例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);
}
 
开发者ID:o3project,项目名称:openflowj-otn,代码行数:10,代码来源:U128.java

示例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);
    }
}
 
开发者ID:reasm,项目名称:reasm-m68k,代码行数:13,代码来源:DsRsDirective.java

示例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);
}
 
开发者ID:floodlight,项目名称:loxigen-artifacts,代码行数:9,代码来源:IPv6Address.java

示例10: compare

import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
public int compare(long aPrefix, long bPrefix) {
  return UnsignedLongs.compare(aPrefix, bPrefix);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:5,代码来源:PrefixComparators.java

示例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;
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:7,代码来源:Utils.java

示例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;
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:7,代码来源:Utils.java

示例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);
    }
}
 
开发者ID:tracingplane,项目名称:tracingplane-java,代码行数:53,代码来源:UnsignedByteBuffer.java

示例14: compare

import com.google.common.primitives.UnsignedLongs; //导入方法依赖的package包/类
@Override
public int compare(long aPrefix, long bPrefix) {
    return UnsignedLongs.compare(aPrefix, bPrefix);
}
 
开发者ID:shunfei,项目名称:indexr,代码行数:5,代码来源:PrefixComparators.java

示例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());
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:5,代码来源:MNumeric.java


注:本文中的com.google.common.primitives.UnsignedLongs.compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。