當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。