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


Java UnsignedBytes.compare方法代码示例

本文整理汇总了Java中com.google.common.primitives.UnsignedBytes.compare方法的典型用法代码示例。如果您正苦于以下问题:Java UnsignedBytes.compare方法的具体用法?Java UnsignedBytes.compare怎么用?Java UnsignedBytes.compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.primitives.UnsignedBytes的用法示例。


在下文中一共展示了UnsignedBytes.compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compareToCurrentToken

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/**
 * Compare only the bytes within the window of the current token
 * @param key
 * @return return -1 if key is lessThan (before) this, 0 if equal, and 1 if key is after
 */
protected int compareToCurrentToken(Cell key) {
  int startIndex = rowLength - currentRowNode.getTokenLength();
  int endIndexExclusive = startIndex + currentRowNode.getTokenLength();
  for (int i = startIndex; i < endIndexExclusive; ++i) {
    if (i >= key.getRowLength()) {// key was shorter, so it's first
      return -1;
    }
    byte keyByte = CellUtil.getRowByte(key, i);
    byte thisByte = rowBuffer[i];
    if (keyByte == thisByte) {
      continue;
    }
    return UnsignedBytes.compare(keyByte, thisByte);
  }
  if (!currentRowNode.hasOccurrences() && rowLength >= key.getRowLength()) { // key was shorter
      return -1;
  }
  return 0;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:25,代码来源:PrefixTreeArraySearcher.java

示例2: compare

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compare(ByteBuffer left, ByteBuffer right) {
    int initialLeftPosition = left.position();
    int initialRightPosition = right.position();
    try {
        int minLength = Math.min(left.remaining(), right.remaining());
        for (int i = 0; i < minLength; i++) {
            int result = UnsignedBytes.compare(left.get(), right.get());
            if (result != 0) {
                return result;
            }
        }
        return left.remaining() - right.remaining();
    } finally {
        left.position(initialLeftPosition);
        right.position(initialRightPosition);
    }
}
 
开发者ID:tracingplane,项目名称:tracingplane-java,代码行数:19,代码来源:UnsignedByteBuffer.java

示例3: compareToCurrentToken

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/**
 * Compare only the bytes within the window of the current token
 * @param key
 * @return return -1 if key is lessThan (before) this, 0 if equal, and 1 if key is after
 */
protected int compareToCurrentToken(Cell key) {
  int startIndex = rowLength - currentRowNode.getTokenLength();
  int endIndexExclusive = startIndex + currentRowNode.getTokenLength();
  for (int i = startIndex; i < endIndexExclusive; ++i) {
    if (i >= key.getRowLength()) {// key was shorter, so it's first
      return -1;
    }
    byte keyByte = CellUtil.getRowByte(key, i);
    byte thisByte = rowBuffer[i];
    if (keyByte == thisByte) {
      continue;
    }
    return UnsignedBytes.compare(keyByte, thisByte);
  }
  return 0;
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:22,代码来源:PrefixTreeArraySearcher.java

示例4: getBinarySubtype

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
protected static BinarySubtype getBinarySubtype(byte readByte) {
  switch (readByte) {
    case 0x00:
      return BinarySubtype.GENERIC;
    case 0x01:
      return BinarySubtype.FUNCTION;
    case 0x02:
      return BinarySubtype.OLD_BINARY;
    case 0x03:
      return BinarySubtype.OLD_UUID;
    case 0x04:
      return BinarySubtype.UUID;
    case 0x05:
      return BinarySubtype.MD5;
    default: {
      if (UnsignedBytes.compare(readByte, FIRST_USER_DEFINED) >= 0) {
        return BinarySubtype.USER_DEFINED;
      } else {
        throw new AssertionError(
            "Unrecognized binary type 0x" + UnsignedBytes.toString(readByte, 16));
      }
    }
  }
}
 
开发者ID:torodb,项目名称:mongowp,代码行数:25,代码来源:ParsingTools.java

示例5: getBinarySubtype

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
protected static BinarySubtype getBinarySubtype(byte readByte) {
  switch (readByte) {
    case 0x00:
      return BinarySubtype.GENERIC;
    case 0x01:
      return BinarySubtype.FUNCTION;
    case 0x02:
      return BinarySubtype.OLD_BINARY;
    case 0x03:
      return BinarySubtype.OLD_UUID;
    case 0x04:
      return BinarySubtype.UUID;
    case 0x05:
      return BinarySubtype.MD5;
    default:
    {
      if (UnsignedBytes.compare(readByte, FIRST_USER_DEFINED) >= 0) {
        return BinarySubtype.USER_DEFINED;
      } else {
        throw new AssertionError(
                "Unrecognized binary type 0x" + UnsignedBytes.toString(readByte, 16));
      }
    }
  }
}
 
开发者ID:torodb,项目名称:mongowp,代码行数:26,代码来源:MongoBsonTranslator.java

示例6: compareTo

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
private static int compareTo(byte[] left, byte[] right) {
  if (isEmpty(left)) {
    if (isEmpty(right)) {
      return 0;
    }
    return 1;
  } else if (isEmpty(right)) {
    return -1;
  }

  int minLength = Math.min(left.length, right.length);
  for (int i = 0; i < minLength; i++) {
    int result = UnsignedBytes.compare(left[i], right[i]);
    if (result != 0) {
      return result;
    }
  }
  return left.length - right.length;
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:20,代码来源:C5Compare.java

示例7: compareTo

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(@Nonnull ComparableByteString other) {
  requireNonNull(other, "other is null");
  ByteString otherBytes = other.bytes;
  int n = Math.min(bytes.size(), otherBytes.size());
  for (int i = 0, j = 0; i < n; i++, j++) {
    int cmp = UnsignedBytes.compare(bytes.byteAt(i), otherBytes.byteAt(j));
    if (cmp != 0) return cmp;
  }
  // one is the prefix of other then the longer is larger
  return bytes.size() - otherBytes.size();
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:13,代码来源:Comparables.java

示例8: compareTo

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(IpAddress o) {
    // Compare first the version
    if (this.version != o.version) {
        return this.version.compareTo(o.version);
    }

    // Compare the bytes, one-by-one
    for (int i = 0; i < this.octets.length; i++) {
        if (this.octets[i] != o.octets[i]) {
            return UnsignedBytes.compare(this.octets[i], o.octets[i]);
        }
    }
    return 0;       // Equal
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:IpAddress.java

示例9: compare

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override public int compare(byte[] left, byte[] right) {
    int minLength = Math.min(left.length, right.length);
    for (int i = 0; i < minLength; i++) {
        int result = UnsignedBytes.compare(left[i], right[i]);
        if (result != 0) {
            return result;
        }
    }
    return left.length - right.length;
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:11,代码来源:ClientUtils.java

示例10: compareTo

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(AtriumIpAddress o) {
    // Compare first the version
    if (this.version != o.version) {
        return this.version.compareTo(o.version);
    }

    // Compare the bytes, one-by-one
    for (int i = 0; i < this.octets.length; i++) {
        if (this.octets[i] != o.octets[i]) {
            return UnsignedBytes.compare(this.octets[i], o.octets[i]);
        }
    }
    return 0;       // Equal
}
 
开发者ID:onfsdn,项目名称:atrium-odl,代码行数:16,代码来源:AtriumIpAddress.java

示例11: compareTo

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(KIdentifier o) {
  for(int i=0; i<super.binaryValue.length; i++){
    int byteComparison=UnsignedBytes.compare(binaryValue[i], o.binaryValue[i]);
    if(byteComparison!=0){
      return byteComparison;
    }
  }
  return 0;
}
 
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:11,代码来源:KIdentifier.java

示例12: compareTo

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/**
 * Lexicographically compare two arrays.
 *
 * @param buffer1 left operand
 * @param buffer2 right operand
 * @param offset1 Where to start comparing in the left buffer
 * @param offset2 Where to start comparing in the right buffer
 * @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.
 */
@Override
public int compareTo(byte[] buffer1, int offset1, int length1,
    byte[] buffer2, int offset2, int length2) {
  // Short circuit equal case
  if (buffer1 == buffer2 &&
      offset1 == offset2 &&
      length1 == length2) {
    return 0;
  }
  int minLength = Math.min(length1, length2);
  int minWords = minLength / Longs.BYTES;
  int offset1Adj = offset1 + BYTE_ARRAY_BASE_OFFSET;
  int offset2Adj = offset2 + BYTE_ARRAY_BASE_OFFSET;

  /*
   * 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(buffer1, offset1Adj + (long) i);
    long rw = theUnsafe.getLong(buffer2, offset2Adj + (long) i);
    long diff = lw ^ rw;

    if (diff != 0) {
      if (!littleEndian) {
        return lessThanUnsigned(lw, rw) ? -1 : 1;
      }

      // Use binary search
      int n = 0;
      int y;
      int x = (int) diff;
      if (x == 0) {
        x = (int) (diff >>> 32);
        n = 32;
      }

      y = x << 16;
      if (y == 0) {
        n += 16;
      } else {
        x = y;
      }

      y = x << 8;
      if (y == 0) {
        n += 8;
      }
      return (int) (((lw >>> n) & 0xFFL) - ((rw >>> n) & 0xFFL));
    }
  }

  // The epilogue to cover the last (minLength % 8) elements.
  for (int i = minWords * Longs.BYTES; i < minLength; i++) {
    int result = UnsignedBytes.compare(
        buffer1[offset1 + i],
        buffer2[offset2 + i]);
    if (result != 0) {
      return result;
    }
  }
  return length1 - length2;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:76,代码来源:FastByteComparisons.java

示例13: compareTo

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/**
 * Lexicographically compare two arrays.
 *
 * @param buffer1 left operand
 * @param buffer2 right operand
 * @param offset1 Where to start comparing in the left buffer
 * @param offset2 Where to start comparing in the right buffer
 * @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.
 */
@Override
public int compareTo(final byte[] buffer1, final int offset1, final int length1, final byte[] buffer2,
        final int offset2, final int length2) {
    // Short circuit equal case
    if (buffer1 == buffer2 && offset1 == offset2 && length1 == length2) {
        return 0;
    }
    final int minLength = Math.min(length1, length2);
    final int minWords = minLength / Longs.BYTES;
    final int offset1Adj = offset1 + BYTE_ARRAY_BASE_OFFSET;
    final int offset2Adj = offset2 + BYTE_ARRAY_BASE_OFFSET;

    /*
     * 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) {
        final long lw = theUnsafe.getLong(buffer1, offset1Adj + (long) i);
        final long rw = theUnsafe.getLong(buffer2, offset2Adj + (long) i);
        final long diff = lw ^ rw;

        if (diff != 0) {
            if (!littleEndian) {
                return lessThanUnsigned(lw, rw) ? -1 : 1;
            }

            // Use binary search
            int n = 0;
            int y;
            int x = (int) diff;
            if (x == 0) {
                x = (int) (diff >>> 32);
                n = 32;
            }

            y = x << 16;
            if (y == 0) {
                n += 16;
            } else {
                x = y;
            }

            y = x << 8;
            if (y == 0) {
                n += 8;
            }
            return (int) ((lw >>> n & 0xFFL) - (rw >>> n & 0xFFL));
        }
    }

    // The epilogue to cover the last (minLength % 8) elements.
    for (int i = minWords * Longs.BYTES; i < minLength; i++) {
        final int result = UnsignedBytes.compare(buffer1[offset1 + i], buffer2[offset2 + i]);
        if (result != 0) {
            return result;
        }
    }
    return length1 - length2;
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:73,代码来源:FastByteComparison.java

示例14: compareTo

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(VlanPcp o) {
    return UnsignedBytes.compare(pcp, o.pcp);
}
 
开发者ID:o3project,项目名称:openflowj-otn,代码行数:5,代码来源:VlanPcp.java

示例15: compareTo

import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compareTo(U8 o) {
    return UnsignedBytes.compare(raw, o.raw);
}
 
开发者ID:o3project,项目名称:openflowj-otn,代码行数:5,代码来源:U8.java


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