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 HasherputBoolean(boolean b)Equivalent toputByte(b ? (byte) 1 : (byte) 0).HasherputBytes(byte[] bytes)Puts an array of bytes into this sink.HasherputBytes(byte[] bytes, int off, int len)Puts a chunk of an array of bytes into this sink.HasherputBytes(java.nio.ByteBuffer b)Puts the remaining bytes of a byte buffer into this sink.HasherputChar(char c)Puts a character into this sink.HasherputDouble(double d)Equivalent toputLong(Double.doubleToRawLongBits(d)).HasherputFloat(float f)Equivalent toputInt(Float.floatToRawIntBits(f)).HasherputInt(int i)Puts an int into this sink.HasherputLong(long l)Puts a long into this sink.<T> HasherputObject(T instance, Funnel<? super T> funnel)A simple convenience forfunnel.funnel(object, this).HasherputShort(short s)Puts a short into this sink.HasherputString(java.lang.CharSequence charSequence, java.nio.charset.Charset charset)Equivalent toputBytes(charSequence.toString().getBytes(charset)).HasherputUnencodedChars(java.lang.CharSequence charSequence)Equivalent to processing eachcharvalue in theCharSequence, in order.
-
-
-
Method Detail
-
putBoolean
public final Hasher putBoolean(boolean b)
Description copied from interface:HasherEquivalent toputByte(b ? (byte) 1 : (byte) 0).- Specified by:
putBooleanin interfaceHasher- Specified by:
putBooleanin interfacePrimitiveSink
-
putDouble
public final Hasher putDouble(double d)
Description copied from interface:HasherEquivalent toputLong(Double.doubleToRawLongBits(d)).- Specified by:
putDoublein interfaceHasher- Specified by:
putDoublein interfacePrimitiveSink
-
putFloat
public final Hasher putFloat(float f)
Description copied from interface:HasherEquivalent toputInt(Float.floatToRawIntBits(f)).- Specified by:
putFloatin interfaceHasher- Specified by:
putFloatin interfacePrimitiveSink
-
putUnencodedChars
public Hasher putUnencodedChars(java.lang.CharSequence charSequence)
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
public Hasher putString(java.lang.CharSequence charSequence, java.nio.charset.Charset charset)
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
public Hasher putBytes(byte[] bytes)
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
public Hasher putBytes(byte[] bytes, int off, int len)
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
public Hasher putBytes(java.nio.ByteBuffer b)
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
public Hasher putShort(short s)
Description copied from interface:PrimitiveSinkPuts a short into this sink.- Specified by:
putShortin interfaceHasher- Specified by:
putShortin interfacePrimitiveSink
-
putInt
public Hasher putInt(int i)
Description copied from interface:PrimitiveSinkPuts an int into this sink.- Specified by:
putIntin interfaceHasher- Specified by:
putIntin interfacePrimitiveSink
-
putLong
public Hasher putLong(long l)
Description copied from interface:PrimitiveSinkPuts a long into this sink.- Specified by:
putLongin interfaceHasher- Specified by:
putLongin interfacePrimitiveSink
-
putChar
public Hasher putChar(char c)
Description copied from interface:PrimitiveSinkPuts a character into this sink.- Specified by:
putCharin interfaceHasher- Specified by:
putCharin interfacePrimitiveSink
-
-