Package com.google.common.hash
Class AbstractHasher
java.lang.Object
com.google.common.hash.AbstractHasher
- All Implemented Interfaces:
Hasher,PrimitiveSink
- Direct Known Subclasses:
AbstractByteHasher,AbstractNonStreamingHashFunction.BufferingHasher,AbstractStreamingHasher,Murmur3_32HashFunction.Murmur3_32Hasher
An abstract implementation of
Hasher, which only requires subtypes to implement Hasher.putByte(byte). Subtypes may provide more efficient implementations, however.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal HasherputBoolean(boolean b) Equivalent toputByte(b ? (byte) 1 : (byte) 0).putBytes(byte[] bytes) Puts an array of bytes into this sink.putBytes(byte[] bytes, int off, int len) Puts a chunk of an array of bytes into this sink.Puts the remaining bytes of a byte buffer into this sink.putChar(char c) Puts a character into this sink.final HasherputDouble(double d) Equivalent toputLong(Double.doubleToRawLongBits(d)).final HasherputFloat(float f) Equivalent toputInt(Float.floatToRawIntBits(f)).putInt(int i) Puts an int into this sink.putLong(long l) Puts a long into this sink.<T> HasherA simple convenience forfunnel.funnel(object, this).putShort(short s) Puts a short into this sink.putString(CharSequence charSequence, Charset charset) Equivalent toputBytes(charSequence.toString().getBytes(charset)).putUnencodedChars(CharSequence charSequence) Equivalent to processing eachcharvalue in theCharSequence, in order.
-
Constructor Details
-
AbstractHasher
AbstractHasher()
-
-
Method Details
-
putBoolean
Description copied from interface:HasherEquivalent toputByte(b ? (byte) 1 : (byte) 0).- Specified by:
putBooleanin interfaceHasher- Specified by:
putBooleanin interfacePrimitiveSink
-
putDouble
Description copied from interface:HasherEquivalent toputLong(Double.doubleToRawLongBits(d)).- Specified by:
putDoublein interfaceHasher- Specified by:
putDoublein interfacePrimitiveSink
-
putFloat
Description copied from interface:HasherEquivalent toputInt(Float.floatToRawIntBits(f)).- Specified by:
putFloatin interfaceHasher- Specified by:
putFloatin interfacePrimitiveSink
-
putUnencodedChars
Description copied from interface:HasherEquivalent to processing eachcharvalue in theCharSequence, in order. In other words, no character encoding is performed; the low byte and high byte of eachcharare hashed directly (in that order). The input must not be updated while this method is in progress.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
Hasher.putString(java.lang.CharSequence, java.nio.charset.Charset), usually with a charset of UTF-8. For other use cases, useputUnencodedChars.- Specified by:
putUnencodedCharsin interfaceHasher- Specified by:
putUnencodedCharsin interfacePrimitiveSink
-
putString
Description copied from interface:HasherEquivalent toputBytes(charSequence.toString().getBytes(charset)).Warning: This method, which reencodes the input before hashing it, is useful only for cross-language compatibility. For other use cases, prefer
Hasher.putUnencodedChars(java.lang.CharSequence), which is faster, produces the same output across Java releases, and hashes everycharin the input, even if some are invalid.- Specified by:
putStringin interfaceHasher- Specified by:
putStringin interfacePrimitiveSink
-
putBytes
Description copied from interface:PrimitiveSinkPuts an array of bytes into this sink.- Specified by:
putBytesin interfaceHasher- Specified by:
putBytesin interfacePrimitiveSink- Parameters:
bytes- a byte array- Returns:
- this instance
-
putBytes
Description copied from interface:PrimitiveSinkPuts a chunk of an array of bytes into this sink.bytes[off]is the first byte written,bytes[off + len - 1]is the last.- Specified by:
putBytesin interfaceHasher- Specified by:
putBytesin interfacePrimitiveSink- Parameters:
bytes- a byte arrayoff- the start offset in the arraylen- the number of bytes to write- Returns:
- this instance
-
putBytes
Description copied from interface:PrimitiveSinkPuts the remaining bytes of a byte buffer into this sink.bytes.position()is the first byte written,bytes.limit() - 1is the last. The position of the buffer will be equal to the limit when this method returns.- Specified by:
putBytesin interfaceHasher- Specified by:
putBytesin interfacePrimitiveSink- Parameters:
b- a byte buffer- Returns:
- this instance
-
putShort
Description copied from interface:PrimitiveSinkPuts a short into this sink.- Specified by:
putShortin interfaceHasher- Specified by:
putShortin interfacePrimitiveSink
-
putInt
Description copied from interface:PrimitiveSinkPuts an int into this sink.- Specified by:
putIntin interfaceHasher- Specified by:
putIntin interfacePrimitiveSink
-
putLong
Description copied from interface:PrimitiveSinkPuts a long into this sink.- Specified by:
putLongin interfaceHasher- Specified by:
putLongin interfacePrimitiveSink
-
putChar
Description copied from interface:PrimitiveSinkPuts a character into this sink.- Specified by:
putCharin interfaceHasher- Specified by:
putCharin interfacePrimitiveSink
-
putObject
Description copied from interface:HasherA simple convenience forfunnel.funnel(object, this).
-