abstract class AbstractStreamingHashFunction extends java.lang.Object implements HashFunction
HashFunction
. Provides default implementations which
invokes the appropriate method on HashFunction.newHasher()
, then return the result of
Hasher.hash()
.
Invocations of newHasher(int)
also delegate to HashFunction.newHasher(), ignoring
the expected input size parameter.
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractStreamingHashFunction.AbstractStreamingHasher
A convenience base class for implementors of
Hasher ; handles accumulating data
until an entire "chunk" (of implementation-dependent length) is ready to be hashed. |
Constructor and Description |
---|
AbstractStreamingHashFunction() |
Modifier and Type | Method and Description |
---|---|
HashCode |
hashBytes(byte[] input)
Shortcut for
newHasher().putBytes(input).hash() . |
HashCode |
hashBytes(byte[] input,
int off,
int len)
Shortcut for
newHasher().putBytes(input, off, len).hash() . |
HashCode |
hashInt(int input)
Shortcut for
newHasher().putInt(input).hash() ; returns the hash code for the given
int value, interpreted in little-endian byte order. |
HashCode |
hashLong(long input)
Shortcut for
newHasher().putLong(input).hash() ; returns the hash code for the
given long value, interpreted in little-endian byte order. |
<T> HashCode |
hashObject(T instance,
Funnel<? super T> funnel)
Shortcut for
newHasher().putObject(instance, funnel).hash() . |
HashCode |
hashString(java.lang.CharSequence input,
java.nio.charset.Charset charset)
Shortcut for
newHasher().putString(input, charset).hash() . |
HashCode |
hashUnencodedChars(java.lang.CharSequence input)
Shortcut for
newHasher().putUnencodedChars(input).hash() . |
Hasher |
newHasher(int expectedInputSize)
Begins a new hash code computation as
HashFunction.newHasher() , but provides a hint of the
expected size of the input (in bytes). |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
bits, newHasher
public <T> HashCode hashObject(T instance, Funnel<? super T> funnel)
HashFunction
newHasher().putObject(instance, funnel).hash()
. The implementation
might perform better than its longhand equivalent, but should not perform worse.hashObject
in interface HashFunction
public HashCode hashUnencodedChars(java.lang.CharSequence input)
HashFunction
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).hashUnencodedChars
in interface HashFunction
public HashCode hashString(java.lang.CharSequence input, java.nio.charset.Charset charset)
HashFunction
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.hashString
in interface HashFunction
public HashCode hashInt(int input)
HashFunction
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.hashInt
in interface HashFunction
public HashCode hashLong(long input)
HashFunction
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.hashLong
in interface HashFunction
public HashCode hashBytes(byte[] input)
HashFunction
newHasher().putBytes(input).hash()
. The implementation
might perform better than its longhand equivalent, but should not perform
worse.hashBytes
in interface HashFunction
public HashCode hashBytes(byte[] input, int off, int len)
HashFunction
newHasher().putBytes(input, off, len).hash()
. The implementation
might perform better than its longhand equivalent, but should not perform
worse.hashBytes
in interface HashFunction
public Hasher newHasher(int expectedInputSize)
HashFunction
HashFunction.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).newHasher
in interface HashFunction