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
abstract class AbstractHasher extends java.lang.Object implements Hasher
An abstract implementation ofHasher
, which only requires subtypes to implementHasher.putByte(byte)
. Subtypes may provide more efficient implementations, however.
-
-
Constructor Summary
Constructors Constructor Description AbstractHasher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Hasher
putBoolean(boolean b)
Equivalent toputByte(b ? (byte) 1 : (byte) 0)
.Hasher
putBytes(byte[] bytes)
Puts an array of bytes into this sink.Hasher
putBytes(byte[] bytes, int off, int len)
Puts a chunk of an array of bytes into this sink.Hasher
putBytes(java.nio.ByteBuffer b)
Puts the remaining bytes of a byte buffer into this sink.Hasher
putChar(char c)
Puts a character into this sink.Hasher
putDouble(double d)
Equivalent toputLong(Double.doubleToRawLongBits(d))
.Hasher
putFloat(float f)
Equivalent toputInt(Float.floatToRawIntBits(f))
.Hasher
putInt(int i)
Puts an int into this sink.Hasher
putLong(long l)
Puts a long into this sink.<T> Hasher
putObject(T instance, Funnel<? super T> funnel)
A simple convenience forfunnel.funnel(object, this)
.Hasher
putShort(short s)
Puts a short into this sink.Hasher
putString(java.lang.CharSequence charSequence, java.nio.charset.Charset charset)
Equivalent toputBytes(charSequence.toString().getBytes(charset))
.Hasher
putUnencodedChars(java.lang.CharSequence charSequence)
Equivalent to processing eachchar
value in theCharSequence
, in order.
-
-
-
Method Detail
-
putBoolean
public final Hasher putBoolean(boolean b)
Description copied from interface:Hasher
Equivalent toputByte(b ? (byte) 1 : (byte) 0)
.- Specified by:
putBoolean
in interfaceHasher
- Specified by:
putBoolean
in interfacePrimitiveSink
-
putDouble
public final Hasher putDouble(double d)
Description copied from interface:Hasher
Equivalent toputLong(Double.doubleToRawLongBits(d))
.- Specified by:
putDouble
in interfaceHasher
- Specified by:
putDouble
in interfacePrimitiveSink
-
putFloat
public final Hasher putFloat(float f)
Description copied from interface:Hasher
Equivalent toputInt(Float.floatToRawIntBits(f))
.- Specified by:
putFloat
in interfaceHasher
- Specified by:
putFloat
in interfacePrimitiveSink
-
putUnencodedChars
public Hasher putUnencodedChars(java.lang.CharSequence charSequence)
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
public Hasher putString(java.lang.CharSequence charSequence, java.nio.charset.Charset charset)
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
public Hasher putBytes(byte[] bytes)
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
public Hasher putBytes(byte[] bytes, int off, int len)
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
public Hasher putBytes(java.nio.ByteBuffer b)
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
public Hasher putShort(short s)
Description copied from interface:PrimitiveSink
Puts a short into this sink.- Specified by:
putShort
in interfaceHasher
- Specified by:
putShort
in interfacePrimitiveSink
-
putInt
public Hasher putInt(int i)
Description copied from interface:PrimitiveSink
Puts an int into this sink.- Specified by:
putInt
in interfaceHasher
- Specified by:
putInt
in interfacePrimitiveSink
-
putLong
public Hasher putLong(long l)
Description copied from interface:PrimitiveSink
Puts a long into this sink.- Specified by:
putLong
in interfaceHasher
- Specified by:
putLong
in interfacePrimitiveSink
-
putChar
public Hasher putChar(char c)
Description copied from interface:PrimitiveSink
Puts a character into this sink.- Specified by:
putChar
in interfaceHasher
- Specified by:
putChar
in interfacePrimitiveSink
-
-