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


Java ByteBufferUtils.findCommonPrefix方法代码示例

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


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

示例1: addKV

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
private int addKV(int prevKeyOffset, DataOutputStream out,
    ByteBuffer in, int prevKeyLength) throws IOException {
  int keyLength = in.getInt();
  int valueLength = in.getInt();

  if (prevKeyOffset == -1) {
    // copy the key, there is no common prefix with none
    ByteBufferUtils.putCompressedInt(out, keyLength);
    ByteBufferUtils.putCompressedInt(out, valueLength);
    ByteBufferUtils.putCompressedInt(out, 0);
    ByteBufferUtils.moveBufferToStream(out, in, keyLength + valueLength);
  } else {
    // find a common prefix and skip it
    int common = ByteBufferUtils.findCommonPrefix(
        in, prevKeyOffset + KeyValue.ROW_OFFSET,
        in.position(),
        Math.min(prevKeyLength, keyLength));

    ByteBufferUtils.putCompressedInt(out, keyLength - common);
    ByteBufferUtils.putCompressedInt(out, valueLength);
    ByteBufferUtils.putCompressedInt(out, common);

    ByteBufferUtils.skip(in, common);
    ByteBufferUtils.moveBufferToStream(out, in, keyLength - common
        + valueLength);
  }

  return keyLength;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:30,代码来源:PrefixKeyDeltaEncoder.java

示例2: internalEncode

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
@Override
public int internalEncode(KeyValue kv, HFileBlockDefaultEncodingContext encodingContext,
    DataOutputStream out) throws IOException {
  byte[] kvBuf = kv.getBuffer();
  int klength = kv.getKeyLength();
  int vlength = kv.getValueLength();
  EncodingState state = encodingContext.getEncodingState();
  if (state.prevKv == null) {
    // copy the key, there is no common prefix with none
    ByteBufferUtils.putCompressedInt(out, klength);
    ByteBufferUtils.putCompressedInt(out, vlength);
    ByteBufferUtils.putCompressedInt(out, 0);
    out.write(kvBuf, kv.getKeyOffset(), klength + vlength);
  } else {
    // find a common prefix and skip it
    int common = ByteBufferUtils.findCommonPrefix(state.prevKv.getBuffer(),
        state.prevKv.getKeyOffset(), state.prevKv.getKeyLength(), kvBuf, kv.getKeyOffset(),
        kv.getKeyLength());
    ByteBufferUtils.putCompressedInt(out, klength - common);
    ByteBufferUtils.putCompressedInt(out, vlength);
    ByteBufferUtils.putCompressedInt(out, common);
    out.write(kvBuf, kv.getKeyOffset() + common, klength - common + vlength);
  }
  int size = klength + vlength + KeyValue.KEYVALUE_INFRASTRUCTURE_SIZE;
  size += afterEncodingKeyValue(kv, out, encodingContext);
  state.prevKv = kv;
  return size;
}
 
开发者ID:shenli-uiuc,项目名称:PyroDB,代码行数:29,代码来源:PrefixKeyDeltaEncoder.java

示例3: findCommonPrefixInFlatKey

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
/**
 * Find length of common prefix in keys of the cells, considering key as byte[] if serialized in
 * {@link KeyValue}. The key format is <2 bytes rk len><rk><1 byte cf
 * len><cf><qualifier><8 bytes timestamp><1 byte type>
 * @param c1
 *          the cell
 * @param c2
 *          the cell
 * @param bypassFamilyCheck
 *          when true assume the family bytes same in both cells. Pass it as true when dealing
 *          with Cells in same CF so as to avoid some checks
 * @param withTsType
 *          when true check timestamp and type bytes also.
 * @return length of common prefix
 */
public static int findCommonPrefixInFlatKey(Cell c1, Cell c2, boolean bypassFamilyCheck,
    boolean withTsType) {
  // Compare the 2 bytes in RK length part
  short rLen1 = c1.getRowLength();
  short rLen2 = c2.getRowLength();
  int commonPrefix = KeyValue.ROW_LENGTH_SIZE;
  if (rLen1 != rLen2) {
    // early out when the RK length itself is not matching
    return ByteBufferUtils.findCommonPrefix(Bytes.toBytes(rLen1), 0, KeyValue.ROW_LENGTH_SIZE,
        Bytes.toBytes(rLen2), 0, KeyValue.ROW_LENGTH_SIZE);
  }
  // Compare the RKs
  int rkCommonPrefix = ByteBufferUtils.findCommonPrefix(c1.getRowArray(), c1.getRowOffset(),
      rLen1, c2.getRowArray(), c2.getRowOffset(), rLen2);
  commonPrefix += rkCommonPrefix;
  if (rkCommonPrefix != rLen1) {
    // Early out when RK is not fully matching.
    return commonPrefix;
  }
  // Compare 1 byte CF length part
  byte fLen1 = c1.getFamilyLength();
  if (bypassFamilyCheck) {
    // This flag will be true when caller is sure that the family will be same for both the cells
    // Just make commonPrefix to increment by the family part
    commonPrefix += KeyValue.FAMILY_LENGTH_SIZE + fLen1;
  } else {
    byte fLen2 = c2.getFamilyLength();
    if (fLen1 != fLen2) {
      // early out when the CF length itself is not matching
      return commonPrefix;
    }
    // CF lengths are same so there is one more byte common in key part
    commonPrefix += KeyValue.FAMILY_LENGTH_SIZE;
    // Compare the CF names
    int fCommonPrefix = ByteBufferUtils.findCommonPrefix(c1.getFamilyArray(),
        c1.getFamilyOffset(), fLen1, c2.getFamilyArray(), c2.getFamilyOffset(), fLen2);
    commonPrefix += fCommonPrefix;
    if (fCommonPrefix != fLen1) {
      return commonPrefix;
    }
  }
  // Compare the Qualifiers
  int qLen1 = c1.getQualifierLength();
  int qLen2 = c2.getQualifierLength();
  int qCommon = ByteBufferUtils.findCommonPrefix(c1.getQualifierArray(), c1.getQualifierOffset(),
      qLen1, c2.getQualifierArray(), c2.getQualifierOffset(), qLen2);
  commonPrefix += qCommon;
  if (!withTsType || Math.max(qLen1, qLen2) != qCommon) {
    return commonPrefix;
  }
  // Compare the timestamp parts
  int tsCommonPrefix = ByteBufferUtils.findCommonPrefix(Bytes.toBytes(c1.getTimestamp()), 0,
      KeyValue.TIMESTAMP_SIZE, Bytes.toBytes(c2.getTimestamp()), 0, KeyValue.TIMESTAMP_SIZE);
  commonPrefix += tsCommonPrefix;
  if (tsCommonPrefix != KeyValue.TIMESTAMP_SIZE) {
    return commonPrefix;
  }
  // Compare the type
  if (c1.getTypeByte() == c2.getTypeByte()) {
    commonPrefix += KeyValue.TYPE_SIZE;
  }
  return commonPrefix;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:79,代码来源:CellUtil.java

示例4: seekToKeyInBlock

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
@Override
public int seekToKeyInBlock(byte[] key, int offset, int length,
    boolean seekBefore) {
  int commonPrefix = 0;
  previous.invalidate();
  do {
    int comp;
    if (samePrefixComparator != null) {
      commonPrefix = Math.min(commonPrefix, current.lastCommonPrefix);

      // extend commonPrefix
      commonPrefix += ByteBufferUtils.findCommonPrefix(
          key, offset + commonPrefix, length - commonPrefix,
          current.keyBuffer, commonPrefix,
          current.keyLength - commonPrefix);

      comp = samePrefixComparator.compareIgnoringPrefix(commonPrefix, key,
          offset, length, current.keyBuffer, 0, current.keyLength);
    } else {
      comp = comparator.compare(key, offset, length,
          current.keyBuffer, 0, current.keyLength);
    }

    if (comp == 0) { // exact match
      if (seekBefore) {
        if (!previous.isValid()) {
          // The caller (seekBefore) has to ensure that we are not at the
          // first key in the block.
          throw new IllegalStateException("Cannot seekBefore if " +
              "positioned at the first key in the block: key=" +
              Bytes.toStringBinary(key, offset, length));
        }
        moveToPrevious();
        return 1;
      }
      return 0;
    }

    if (comp < 0) { // already too large, check previous
      if (previous.isValid()) {
        moveToPrevious();
      }
      return 1;
    }

    // move to next, if more data is available
    if (currentBuffer.hasRemaining()) {
      previous.copyFromNext(current);
      decodeNext();
    } else {
      break;
    }
  } while (true);

  // we hit the end of the block, not an exact match
  return 1;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:58,代码来源:BufferedDataBlockEncoder.java

示例5: seekToKeyInBlock

import org.apache.hadoop.hbase.util.ByteBufferUtils; //导入方法依赖的package包/类
@Override
public int seekToKeyInBlock(byte[] key, int offset, int length,
    boolean seekBefore) {
  int commonPrefix = 0;
  previous.invalidate();
  do {
    int comp;
    if (samePrefixComparator != null) {
      commonPrefix = Math.min(commonPrefix, current.lastCommonPrefix);

      // extend commonPrefix
      commonPrefix += ByteBufferUtils.findCommonPrefix(
          key, offset + commonPrefix, length - commonPrefix,
          current.keyBuffer, commonPrefix,
          current.keyLength - commonPrefix);

      comp = samePrefixComparator.compareIgnoringPrefix(commonPrefix, key,
          offset, length, current.keyBuffer, 0, current.keyLength);
    } else {
      comp = comparator.compareFlatKey(key, offset, length,
          current.keyBuffer, 0, current.keyLength);
    }

    if (comp == 0) { // exact match
      if (seekBefore) {
        if (!previous.isValid()) {
          // The caller (seekBefore) has to ensure that we are not at the
          // first key in the block.
          throw new IllegalStateException("Cannot seekBefore if " +
              "positioned at the first key in the block: key=" +
              Bytes.toStringBinary(key, offset, length));
        }
        moveToPrevious();
        return 1;
      }
      return 0;
    }

    if (comp < 0) { // already too large, check previous
      if (previous.isValid()) {
        moveToPrevious();
      } else {
        return HConstants.INDEX_KEY_MAGIC; // using optimized index key
      }
      return 1;
    }

    // move to next, if more data is available
    if (currentBuffer.hasRemaining()) {
      previous.copyFromNext(current);
      decodeNext();
    } else {
      break;
    }
  } while (true);

  // we hit the end of the block, not an exact match
  return 1;
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:60,代码来源:BufferedDataBlockEncoder.java


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