HashFunction hashBytes - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for HashFunction hashBytes method.

This code example shows how to use the following methods:hashBytes
   * 
   * @param data data to hash 
   * @return 128 bits of hash result 
   */ 
  public byte[] hash(byte[] data) {
    HashCode hashCode = byteArrayHasher.hashBytes(data);
 
    return hashCode.asBytes();
  } 
 
  public long hashToLong(byte[] data) {
    HashCode hashCode = byteArrayHasher.hashBytes(data);
 
    return hashCode.asLong();
  } 
 
 
  /** 
   * A special version for long integers 
   * 
5
CodeRank
This code example shows how to use the following methods:hashBytes
key.indexTo(depth);
        int startPosition = key.getIndex();
        key.indexTo(depth + 1);
        int endPosition = key.getIndex();
        return hashFunction.hashBytes(key.getEncodedBytes(), startPosition, endPosition - startPosition).asLong();
    } 
 
    // Object state 
 
    private final HashFunction hashFunction = Hashing.goodFastHash(64); // Because we're returning longs
} 
5
CodeRank
This code example shows how to use the following methods:hashBytes
      return processor.getResult();
    } 
 
    @Override 
    public HashCode hash(HashFunction hashFunction) throws IOException {
      return hashFunction.hashBytes(bytes);
    } 
 
    // TODO(user): Possibly override slice() 
 
    @Override 
    public String toString() {
      return "ByteSource.wrap(" 
          + Ascii.truncate(BaseEncoding.base16().encode(bytes), 30, "...") + ")";
    } 
  } 
 
  private static final class EmptyByteSource extends ByteArrayByteSource { 
 
    private static final EmptyByteSource INSTANCE = new EmptyByteSource();
4
CodeRank
This code example shows how to use the following methods:hashBytes
   * 
   * @param id The byte array that may have been previously seen. 
   * @return Whether the byte array is contained in the ByteArrayFilter. 
   */ 
  public boolean containsAndAdd(byte[] id) {
    HashCode code = HASH_FUNC.hashBytes(id);
    int index = Math.abs(code.asInt()) & sizeMask;
    byte[] oldId = array.getAndSet(index, id);
    return Arrays.equals(id, oldId);
  } 
 
  /** 
   * Returns the size of the underlying array. Welp. 
   * 
   * @return The size of the underlying array. 
   */ 
  public int getSize() { 
    return array.length();
  } 
} 
4
CodeRank
hashBytes Method Overview
Shortcut for newHasher().putBytes(input, off, len).hash().
See Code Examples for other Guava HashFunction Methods: