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 Hasher
putBoolean
(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 Hasher
putDouble
(double d) Equivalent toputLong(Double.doubleToRawLongBits(d))
.final Hasher
putFloat
(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> Hasher
A 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 eachchar
value in theCharSequence
, in order.
-
Constructor Details
-
AbstractHasher
AbstractHasher()
-
-
Method Details
-
putBoolean
Description copied from interface:Hasher
Equivalent toputByte(b ? (byte) 1 : (byte) 0)
.- Specified by:
putBoolean
in interfaceHasher
- Specified by:
putBoolean
in interfacePrimitiveSink
-
putDouble
Description copied from interface:Hasher
Equivalent toputLong(Double.doubleToRawLongBits(d))
.- Specified by:
putDouble
in interfaceHasher
- Specified by:
putDouble
in interfacePrimitiveSink
-
putFloat
Description copied from interface:Hasher
Equivalent toputInt(Float.floatToRawIntBits(f))
.- Specified by:
putFloat
in interfaceHasher
- Specified by:
putFloat
in interfacePrimitiveSink
-
putUnencodedChars
Description copied from interface:Hasher
Equivalent to processing eachchar
value in theCharSequence
, in order. In other words, no character encoding is performed; the low byte and high byte of eachchar
are 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:
putUnencodedChars
in interfaceHasher
- Specified by:
putUnencodedChars
in interfacePrimitiveSink
-
putString
Description copied from interface:Hasher
Equivalent 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 everychar
in the input, even if some are invalid.- Specified by:
putString
in interfaceHasher
- Specified by:
putString
in interfacePrimitiveSink
-
putBytes
Description copied from interface:PrimitiveSink
Puts an array of bytes into this sink.- Specified by:
putBytes
in interfaceHasher
- Specified by:
putBytes
in interfacePrimitiveSink
- Parameters:
bytes
- a byte array- Returns:
- this instance
-
putBytes
Description copied from interface:PrimitiveSink
Puts 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:
putBytes
in interfaceHasher
- Specified by:
putBytes
in 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:PrimitiveSink
Puts the remaining bytes of a byte buffer into this sink.bytes.position()
is the first byte written,bytes.limit() - 1
is the last. The position of the buffer will be equal to the limit when this method returns.- Specified by:
putBytes
in interfaceHasher
- Specified by:
putBytes
in interfacePrimitiveSink
- Parameters:
b
- a byte buffer- Returns:
- this instance
-
putShort
Description copied from interface:PrimitiveSink
Puts a short into this sink.- Specified by:
putShort
in interfaceHasher
- Specified by:
putShort
in interfacePrimitiveSink
-
putInt
Description copied from interface:PrimitiveSink
Puts an int into this sink.- Specified by:
putInt
in interfaceHasher
- Specified by:
putInt
in interfacePrimitiveSink
-
putLong
Description copied from interface:PrimitiveSink
Puts a long into this sink.- Specified by:
putLong
in interfaceHasher
- Specified by:
putLong
in interfacePrimitiveSink
-
putChar
Description copied from interface:PrimitiveSink
Puts a character into this sink.- Specified by:
putChar
in interfaceHasher
- Specified by:
putChar
in interfacePrimitiveSink
-
putObject
Description copied from interface:Hasher
A simple convenience forfunnel.funnel(object, this)
.
-