com.google.protobuf.Internal.partialHash()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(109)

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

Internal.partialHash介绍

[英]Helper method for continuously hashing bytes.
[中]用于连续散列字节的助手方法。

代码示例

代码示例来源:origin: com.google.protobuf/protobuf-java

  1. /**
  2. * Helper method for implementing {@link LiteralByteString#hashCode()}.
  3. */
  4. static int hashCode(byte[] bytes, int offset, int length) {
  5. // The hash code for a byte array should be the same as the hash code for a
  6. // ByteString with the same content. This is to ensure that the generated
  7. // hashCode() method will return the same value as the pure reflection
  8. // based hashCode() method.
  9. int h = Internal.partialHash(length, bytes, offset, length);
  10. return h == 0 ? 1 : h;
  11. }

代码示例来源:origin: com.google.protobuf/protobuf-java

  1. @Override
  2. protected final int partialHash(int h, int offset, int length) {
  3. return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length);
  4. }

代码示例来源:origin: com.google.protobuf/protobuf-java

  1. /**
  2. * Helper method for implementing {@link Message#hashCode()} for bytes
  3. * field.
  4. */
  5. public static int hashCodeByteBuffer(ByteBuffer bytes) {
  6. if (bytes.hasArray()) {
  7. // Fast path.
  8. int h = partialHash(bytes.capacity(), bytes.array(), bytes.arrayOffset(), bytes.capacity());
  9. return h == 0 ? 1 : h;
  10. } else {
  11. // Read the data into a temporary byte array before calculating the
  12. // hash value.
  13. final int bufferSize = bytes.capacity() > DEFAULT_BUFFER_SIZE
  14. ? DEFAULT_BUFFER_SIZE : bytes.capacity();
  15. final byte[] buffer = new byte[bufferSize];
  16. final ByteBuffer duplicated = bytes.duplicate();
  17. duplicated.clear();
  18. int h = bytes.capacity();
  19. while (duplicated.remaining() > 0) {
  20. final int length = duplicated.remaining() <= bufferSize ?
  21. duplicated.remaining() : bufferSize;
  22. duplicated.get(buffer, 0, length);
  23. h = partialHash(h, buffer, 0, length);
  24. }
  25. return h == 0 ? 1 : h;
  26. }
  27. }

代码示例来源:origin: com.google.protobuf/protobuf-lite

  1. /**
  2. * Helper method for implementing {@link LiteralByteString#hashCode()}.
  3. */
  4. static int hashCode(byte[] bytes, int offset, int length) {
  5. // The hash code for a byte array should be the same as the hash code for a
  6. // ByteString with the same content. This is to ensure that the generated
  7. // hashCode() method will return the same value as the pure reflection
  8. // based hashCode() method.
  9. int h = Internal.partialHash(length, bytes, offset, length);
  10. return h == 0 ? 1 : h;
  11. }

代码示例来源:origin: yeriomin/play-store-api

  1. /**
  2. * Helper method for implementing {@link LiteralByteString#hashCode()}.
  3. */
  4. static int hashCode(byte[] bytes, int offset, int length) {
  5. // The hash code for a byte array should be the same as the hash code for a
  6. // ByteString with the same content. This is to ensure that the generated
  7. // hashCode() method will return the same value as the pure reflection
  8. // based hashCode() method.
  9. int h = Internal.partialHash(length, bytes, offset, length);
  10. return h == 0 ? 1 : h;
  11. }

代码示例来源:origin: yeriomin/play-store-api

  1. @Override
  2. protected final int partialHash(int h, int offset, int length) {
  3. return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length);
  4. }

代码示例来源:origin: com.google.protobuf/protobuf-lite

  1. @Override
  2. protected final int partialHash(int h, int offset, int length) {
  3. return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length);
  4. }

代码示例来源:origin: com.google.protobuf/protobuf-lite

  1. /**
  2. * Helper method for implementing {@link Message#hashCode()} for bytes
  3. * field.
  4. */
  5. public static int hashCodeByteBuffer(ByteBuffer bytes) {
  6. if (bytes.hasArray()) {
  7. // Fast path.
  8. int h = partialHash(bytes.capacity(), bytes.array(), bytes.arrayOffset(), bytes.capacity());
  9. return h == 0 ? 1 : h;
  10. } else {
  11. // Read the data into a temporary byte array before calculating the
  12. // hash value.
  13. final int bufferSize = bytes.capacity() > DEFAULT_BUFFER_SIZE
  14. ? DEFAULT_BUFFER_SIZE : bytes.capacity();
  15. final byte[] buffer = new byte[bufferSize];
  16. final ByteBuffer duplicated = bytes.duplicate();
  17. duplicated.clear();
  18. int h = bytes.capacity();
  19. while (duplicated.remaining() > 0) {
  20. final int length = duplicated.remaining() <= bufferSize ?
  21. duplicated.remaining() : bufferSize;
  22. duplicated.get(buffer, 0, length);
  23. h = partialHash(h, buffer, 0, length);
  24. }
  25. return h == 0 ? 1 : h;
  26. }
  27. }

代码示例来源:origin: yeriomin/play-store-api

  1. /**
  2. * Helper method for implementing {@link Message#hashCode()} for bytes
  3. * field.
  4. */
  5. public static int hashCodeByteBuffer(ByteBuffer bytes) {
  6. if (bytes.hasArray()) {
  7. // Fast path.
  8. int h = partialHash(bytes.capacity(), bytes.array(), bytes.arrayOffset(), bytes.capacity());
  9. return h == 0 ? 1 : h;
  10. } else {
  11. // Read the data into a temporary byte array before calculating the
  12. // hash value.
  13. final int bufferSize = bytes.capacity() > DEFAULT_BUFFER_SIZE
  14. ? DEFAULT_BUFFER_SIZE : bytes.capacity();
  15. final byte[] buffer = new byte[bufferSize];
  16. final ByteBuffer duplicated = bytes.duplicate();
  17. duplicated.clear();
  18. int h = bytes.capacity();
  19. while (duplicated.remaining() > 0) {
  20. final int length = duplicated.remaining() <= bufferSize ?
  21. duplicated.remaining() : bufferSize;
  22. duplicated.get(buffer, 0, length);
  23. h = partialHash(h, buffer, 0, length);
  24. }
  25. return h == 0 ? 1 : h;
  26. }
  27. }

相关文章