net.jpountz.xxhash.XXHash32.hash()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(232)

本文整理了Java中net.jpountz.xxhash.XXHash32.hash()方法的一些代码示例,展示了XXHash32.hash()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XXHash32.hash()方法的具体详情如下:
包路径:net.jpountz.xxhash.XXHash32
类名称:XXHash32
方法名:hash

XXHash32.hash介绍

[英]Compute the hash of the given ByteBuffer. The ByteBuffer#position() is moved in order to reflect bytes which have been read.
[中]计算给定字节缓冲区的哈希。字节缓冲#position()会被移动,以反映已读取的字节。

代码示例

代码示例来源:origin: apache/kafka

CHECKSUM.hash(in.array(), in.arrayOffset() + in.position(), len, 0) :
        CHECKSUM.hash(in, in.position(), len, 0);
in.position(in.position() + len);
if (in.get() != (byte) ((hash >> 8) & 0xFF)) {

代码示例来源:origin: apache/kafka

CHECKSUM.hash(in.array(), in.arrayOffset() + in.position(), blockSize, 0) :
      CHECKSUM.hash(in, in.position(), blockSize, 0);
in.position(in.position() + blockSize);
if (hash != in.getInt()) {

代码示例来源:origin: apache/kafka

/**
 * Writes the magic number and frame descriptor to the underlying {@link OutputStream}.
 *
 * @throws IOException
 */
private void writeHeader() throws IOException {
  ByteUtils.writeUnsignedIntLE(buffer, 0, MAGIC);
  bufferOffset = 4;
  buffer[bufferOffset++] = flg.toByte();
  buffer[bufferOffset++] = bd.toByte();
  // TODO write uncompressed content size, update flg.validate()
  // compute checksum on all descriptor fields
  int offset = 4;
  int len = bufferOffset - offset;
  if (this.useBrokenFlagDescriptorChecksum) {
    len += offset;
    offset = 0;
  }
  byte hash = (byte) ((checksum.hash(buffer, offset, len, 0) >> 8) & 0xFF);
  buffer[bufferOffset++] = hash;
  // write out frame descriptor
  out.write(buffer, 0, bufferOffset);
  bufferOffset = 0;
}

代码示例来源:origin: apache/kafka

/**
 * Compresses buffered data, optionally computes an XXHash32 checksum, and writes the result to the underlying
 * {@link OutputStream}.
 *
 * @throws IOException
 */
private void writeBlock() throws IOException {
  if (bufferOffset == 0) {
    return;
  }
  int compressedLength = compressor.compress(buffer, 0, bufferOffset, compressedBuffer, 0);
  byte[] bufferToWrite = compressedBuffer;
  int compressMethod = 0;
  // Store block uncompressed if compressed length is greater (incompressible)
  if (compressedLength >= bufferOffset) {
    bufferToWrite = buffer;
    compressedLength = bufferOffset;
    compressMethod = LZ4_FRAME_INCOMPRESSIBLE_MASK;
  }
  // Write content
  ByteUtils.writeUnsignedIntLE(out, compressedLength | compressMethod);
  out.write(bufferToWrite, 0, compressedLength);
  // Calculate and write block checksum
  if (flg.isBlockChecksumSet()) {
    int hash = checksum.hash(bufferToWrite, 0, compressedLength, 0);
    ByteUtils.writeUnsignedIntLE(out, hash);
  }
  bufferOffset = 0;
}

代码示例来源:origin: sixt/ja-micro

@Override
public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
  List<PartitionInfo> partitions = cluster.partitionsForTopic(topic);
  int numPartitions = partitions.size();
  if (keyBytes == null) {
    int nextValue = roundRobin.getAndIncrement();
    return Utils.toPositive(nextValue) % numPartitions;
  } else {
    // hash the keyBytes to choose a partition
    return Utils.toPositive(xxHasher.hash(keyBytes, 0, keyBytes.length, SEED)) % numPartitions;
  }
}

代码示例来源:origin: apache/kafka

int hash = XXHashFactory.fastestInstance().hash32().hash(compressed, off, len, 0);

代码示例来源:origin: io.gridgo/gridgo-utils

@Override
  public int calcHashCode(byte[] bytes) {
    return hasher.hash(bytes, 0, bytes.length, this.seed);
  }
}

代码示例来源:origin: opendedup/sdfs

public int hashCode(byte[] bytes, int seed) {
  return HASHER.hash(bytes, 0, bytes.length, seed);
}

代码示例来源:origin: org.mapdb/mapdb

public int hashCode(byte[] bytes, int seed) {
  return HASHER.hash(bytes, 0, bytes.length, seed);
}

代码示例来源:origin: org.apache.carbondata/carbondata-core

/**
 * This method will calculate the hash code for given data
 *
 * @return
 */
@Override public int hashCode() {
 if (null != xxHash32) {
  return xxHash32.hash(data, 0, data.length, 0);
 }
 int result = Arrays.hashCode(data);
 result = 31 * result;
 return result;
}

代码示例来源:origin: net.jpountz.lz4/lz4

/**
 * Compute the hash of the given {@link ByteBuffer}. The
 * {@link ByteBuffer#position() position} is moved in order to reflect bytes
 * which have been read.
 */
public final int hash(ByteBuffer buf, int seed) {
 final int hash = hash(buf, buf.position(), buf.remaining(), seed);
 buf.position(buf.limit());
 return hash;
}

代码示例来源:origin: com.github.swri-robotics/lz4

/**
 * Compute the hash of the given {@link ByteBuffer}. The
 * {@link ByteBuffer#position() position} is moved in order to reflect bytes
 * which have been read.
 */
public final int hash(ByteBuffer buf, int seed) {
 final int hash = hash(buf, buf.position(), buf.remaining(), seed);
 buf.position(buf.limit());
 return hash;
}

代码示例来源:origin: com.github.swri-robotics/lz4

/**
 * Writes the magic number and frame descriptor to the underlying {@link OutputStream}.
 *
 * @throws IOException
 */
private void writeHeader() throws IOException {
 final ByteBuffer headerBuffer = ByteBuffer.allocate(LZ4_MAX_HEADER_LENGTH).order(ByteOrder.LITTLE_ENDIAN);
 headerBuffer.putInt(MAGIC);
 headerBuffer.put(frameInfo.getFLG().toByte());
 headerBuffer.put(frameInfo.getBD().toByte());
 if (frameInfo.isEnabled(FLG.Bits.CONTENT_SIZE)) {
  headerBuffer.putLong(knownSize);
 }
 // compute checksum on all descriptor fields
 final int hash = (checksum.hash(headerBuffer.array(), INTEGER_BYTES, headerBuffer.position() - INTEGER_BYTES, 0) >> 8) & 0xFF;
 headerBuffer.put((byte) hash);
 // write out frame descriptor
 out.write(headerBuffer.array(), 0, headerBuffer.position());
}

代码示例来源:origin: me.jeffshaw.kafka/kafka-clients

/**
 * Reads the magic number and frame descriptor from the underlying {@link InputStream}.
 *  
 * @throws IOException
 */
private void readHeader() throws IOException {
 byte[] header = new byte[LZ4_MAX_HEADER_LENGTH];
 
 // read first 6 bytes into buffer to check magic and FLG/BD descriptor flags
 bufferOffset = 6;
 if (in.read(header, 0, bufferOffset) != bufferOffset) {
  throw new IOException(PREMATURE_EOS);
 }
 if (MAGIC != Utils.readUnsignedIntLE(header, bufferOffset-6)) {
  throw new IOException(NOT_SUPPORTED);
 }
 flg = FLG.fromByte(header[bufferOffset-2]);
 bd = BD.fromByte(header[bufferOffset-1]);
 // TODO read uncompressed content size, update flg.validate()
 // TODO read dictionary id, update flg.validate()
 
 // check stream descriptor hash
 byte hash = (byte) ((checksum.hash(header, 0, bufferOffset, 0) >> 8) & 0xFF);
 header[bufferOffset++] = (byte) in.read();
 if (hash != header[bufferOffset-1]) {
  throw new IOException(DESCRIPTOR_HASH_MISMATCH);
 }
}

代码示例来源:origin: com.github.swri-robotics/lz4

@Override
public int hash(ByteBuffer buf, int off, int len, int seed) {
 if (buf.isDirect()) {
  checkRange(buf, off, len);
  return XXHashJNI.XXH32BB(buf, off, len, seed);
 } else if (buf.hasArray()) {
  return hash(buf.array(), off + buf.arrayOffset(), len, seed);
 } else {
  XXHash32 safeInstance = SAFE_INSTANCE;
  if (safeInstance == null) {
   safeInstance = SAFE_INSTANCE = XXHashFactory.safeInstance().hash32();
  }
  return safeInstance.hash(buf, off, len, seed);
 }
}

代码示例来源:origin: net.jpountz.lz4/lz4

@Override
public int hash(ByteBuffer buf, int off, int len, int seed) {
 if (buf.isDirect()) {
  checkRange(buf, off, len);
  return XXHashJNI.XXH32BB(buf, off, len, seed);
 } else if (buf.hasArray()) {
  return hash(buf.array(), off, len, seed);
 } else {
  XXHash32 safeInstance = SAFE_INSTANCE;
  if (safeInstance == null) {
   safeInstance = SAFE_INSTANCE = XXHashFactory.safeInstance().hash32();
  }
  return safeInstance.hash(buf, off, len, seed);
 }
}

代码示例来源:origin: me.jeffshaw.kafka/kafka-clients

/**
 * Writes the magic number and frame descriptor to the underlying {@link OutputStream}.
 *  
 * @throws IOException
 */
private void writeHeader() throws IOException {
 Utils.writeUnsignedIntLE(buffer, 0, MAGIC);
 bufferOffset = 4;
 buffer[bufferOffset++] = flg.toByte();
 buffer[bufferOffset++] = bd.toByte();
 // TODO write uncompressed content size, update flg.validate()
 // TODO write dictionary id, update flg.validate()
 // compute checksum on all descriptor fields 
 int hash = (checksum.hash(buffer, 0, bufferOffset, 0) >> 8) & 0xFF;
 buffer[bufferOffset++] = (byte) hash;
 // write out frame descriptor
 out.write(buffer, 0, bufferOffset);
 bufferOffset = 0;
}

代码示例来源:origin: me.jeffshaw.kafka/kafka-clients

int hash = checksum.hash(bufferToWrite, 0, compressedLength, 0);
Utils.writeUnsignedIntLE(out, hash);

代码示例来源:origin: net.jpountz.lz4/lz4

private XXHashFactory(String impl) throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
 this.impl = impl;
 hash32 = classInstance("net.jpountz.xxhash.XXHash32" + impl);
 streamingHash32Factory = classInstance("net.jpountz.xxhash.StreamingXXHash32" + impl + "$Factory");
 hash64 = classInstance("net.jpountz.xxhash.XXHash64" + impl);
 streamingHash64Factory = classInstance("net.jpountz.xxhash.StreamingXXHash64" + impl + "$Factory");
 // make sure it can run
 final byte[] bytes = new byte[100];
 final Random random = new Random();
 random.nextBytes(bytes);
 final int seed = random.nextInt();
 final int h1 = hash32.hash(bytes, 0, bytes.length, seed);
 final StreamingXXHash32 streamingHash32 = newStreamingHash32(seed);
 streamingHash32.update(bytes, 0, bytes.length);
 final int h2 = streamingHash32.getValue();
 final long h3 = hash64.hash(bytes, 0, bytes.length, seed);
 final StreamingXXHash64 streamingHash64 = newStreamingHash64(seed);
 streamingHash64.update(bytes, 0, bytes.length);
 final long h4 = streamingHash64.getValue();
 if (h1 != h2) {
  throw new AssertionError();
 }
 if (h3 != h4) {
  throw new AssertionError();
 }
}

代码示例来源:origin: com.github.swri-robotics/lz4

private XXHashFactory(String impl) throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
 this.impl = impl;
 hash32 = classInstance("net.jpountz.xxhash.XXHash32" + impl);
 streamingHash32Factory = classInstance("net.jpountz.xxhash.StreamingXXHash32" + impl + "$Factory");
 hash64 = classInstance("net.jpountz.xxhash.XXHash64" + impl);
 streamingHash64Factory = classInstance("net.jpountz.xxhash.StreamingXXHash64" + impl + "$Factory");
 // make sure it can run
 final byte[] bytes = new byte[100];
 final Random random = new Random();
 random.nextBytes(bytes);
 final int seed = random.nextInt();
 final int h1 = hash32.hash(bytes, 0, bytes.length, seed);
 final StreamingXXHash32 streamingHash32 = newStreamingHash32(seed);
 streamingHash32.update(bytes, 0, bytes.length);
 final int h2 = streamingHash32.getValue();
 final long h3 = hash64.hash(bytes, 0, bytes.length, seed);
 final StreamingXXHash64 streamingHash64 = newStreamingHash64(seed);
 streamingHash64.update(bytes, 0, bytes.length);
 final long h4 = streamingHash64.getValue();
 if (h1 != h2) {
  throw new AssertionError();
 }
 if (h3 != h4) {
  throw new AssertionError();
 }
}

相关文章

XXHash32类方法