Top Description Constructors Methods
com.google.common.hash

pack-priv abstract Class AbstractHashFunction

extends Object
implements HashFunction
Class Inheritance
All Implemented Interfaces
com.google.common.hash.HashFunction
Known Direct Subclasses
com.google.common.hash.AbstractNonStreamingHashFunction, com.google.common.hash.ChecksumHashFunction, com.google.common.hash.Crc32cHashFunction, com.google.common.hash.MacHashFunction, com.google.common.hash.MessageDigestHashFunction, com.google.common.hash.Murmur3_128HashFunction, com.google.common.hash.Murmur3_32HashFunction, com.google.common.hash.SipHashFunction, com.google.common.hash.AbstractCompositeHashFunction
Annotations
@Immutable
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkPositionIndexes

Skeleton implementation of HashFunction in terms of newHasher().

TODO(lowasser): make public

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public HashCode
hashBytes(byte[] input)

Implements com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input).hash().
public HashCode
hashBytes(byte[] input, int off, int len)

Implements com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input, off, len).hash().
public HashCode
hashBytes(ByteBuffer input)

Implements com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input).hash().
public HashCode
hashInt(int input)

Implements com.google.common.hash.HashFunction.hashInt.

Shortcut for newHasher().putInt(input).hash(); returns the hash code for the given int value, interpreted in little-endian byte order.
public HashCode
hashLong(long input)

Implements com.google.common.hash.HashFunction.hashLong.

Shortcut for newHasher().putLong(input).hash(); returns the hash code for the given long value, interpreted in little-endian byte order.
public <T extends @Nullable Object> HashCode
hashObject(T instance, Funnel<? super T> funnel)

Implements com.google.common.hash.HashFunction.hashObject.

Shortcut for newHasher().putObject(instance, funnel).hash().
public HashCode
hashString(CharSequence input, Charset charset)

Implements com.google.common.hash.HashFunction.hashString.

Shortcut for newHasher().putString(input, charset).hash().
public HashCode
hashUnencodedChars(CharSequence input)

Implements com.google.common.hash.HashFunction.hashUnencodedChars.

Shortcut for newHasher().putUnencodedChars(input).hash().
public Hasher
newHasher(int expectedInputSize)

Implements com.google.common.hash.HashFunction.newHasher.

Begins a new hash code computation as newHasher(), but provides a hint of the expected size of the input (in bytes).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AbstractHashFunctionback to summary
pack-priv AbstractHashFunction()

Method Detail

hashBytesback to summary
public HashCode hashBytes(byte[] input)

Implements com.google.common.hash.HashFunction.hashBytes.

Doc from com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashBytesback to summary
public HashCode hashBytes(byte[] input, int off, int len)

Implements com.google.common.hash.HashFunction.hashBytes.

Doc from com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input, off, len).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashBytesback to summary
public HashCode hashBytes(ByteBuffer input)

Implements com.google.common.hash.HashFunction.hashBytes.

Doc from com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashIntback to summary
public HashCode hashInt(int input)

Implements com.google.common.hash.HashFunction.hashInt.

Doc from com.google.common.hash.HashFunction.hashInt.

Shortcut for newHasher().putInt(input).hash(); returns the hash code for the given int value, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashLongback to summary
public HashCode hashLong(long input)

Implements com.google.common.hash.HashFunction.hashLong.

Doc from com.google.common.hash.HashFunction.hashLong.

Shortcut for newHasher().putLong(input).hash(); returns the hash code for the given long value, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashObjectback to summary
public <T extends @Nullable Object> HashCode hashObject(T instance, Funnel<? super T> funnel)

Implements com.google.common.hash.HashFunction.hashObject.

Doc from com.google.common.hash.HashFunction.hashObject.

Shortcut for newHasher().putObject(instance, funnel).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashStringback to summary
public HashCode hashString(CharSequence input, Charset charset)

Implements com.google.common.hash.HashFunction.hashString.

Doc from com.google.common.hash.HashFunction.hashString.

Shortcut for newHasher().putString(input, charset).hash(). Characters are encoded using the given Charset. The implementation might perform better than its longhand equivalent, but should not perform worse.

Warning

This method, which reencodes the input before hashing it, is useful only for cross-language compatibility. For other use cases, prefer hashUnencodedChars, which is faster, produces the same output across Java releases, and hashes every char in the input, even if some are invalid.

Annotations
@Override
hashUnencodedCharsback to summary
public HashCode hashUnencodedChars(CharSequence input)

Implements com.google.common.hash.HashFunction.hashUnencodedChars.

Doc from com.google.common.hash.HashFunction.hashUnencodedChars.

Shortcut for newHasher().putUnencodedChars(input).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse. Note that no character encoding is performed; the low byte and high byte of each char are hashed directly (in that order).

Warning

This method will produce different output than most other languages do when running the same hash function on the equivalent input. For cross-language compatibility, use hashString, usually with a charset of UTF-8. For other use cases, use hashUnencodedChars.

Annotations
@Override
newHasherback to summary
public Hasher newHasher(int expectedInputSize)

Implements com.google.common.hash.HashFunction.newHasher.

Doc from com.google.common.hash.HashFunction.newHasher.

Begins a new hash code computation as newHasher(), but provides a hint of the expected size of the input (in bytes). This is only important for non-streaming hash functions (hash functions that need to buffer their whole input before processing any of it).

Annotations
@Override