Package com.google.common.hash
Class AbstractNonStreamingHashFunction
- java.lang.Object
-
- com.google.common.hash.AbstractHashFunction
-
- com.google.common.hash.AbstractNonStreamingHashFunction
-
- All Implemented Interfaces:
HashFunction
- Direct Known Subclasses:
FarmHashFingerprint64
abstract class AbstractNonStreamingHashFunction extends AbstractHashFunction
Skeleton implementation ofHashFunction, appropriate for non-streaming algorithms. All the hash computation done using newHasher() are delegated to the hashBytes(byte[], int, int) method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classAbstractNonStreamingHashFunction.BufferingHasherIn-memory stream-based implementation of Hasher.private static classAbstractNonStreamingHashFunction.ExposedByteArrayOutputStream
-
Constructor Summary
Constructors Constructor Description AbstractNonStreamingHashFunction()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract HashCodehashBytes(byte[] input, int off, int len)Shortcut fornewHasher().putBytes(input, off, len).hash().HashCodehashBytes(java.nio.ByteBuffer input)Shortcut fornewHasher().putBytes(input).hash().HashCodehashInt(int input)Shortcut fornewHasher().putInt(input).hash(); returns the hash code for the givenintvalue, interpreted in little-endian byte order.HashCodehashLong(long input)Shortcut fornewHasher().putLong(input).hash(); returns the hash code for the givenlongvalue, interpreted in little-endian byte order.HashCodehashString(java.lang.CharSequence input, java.nio.charset.Charset charset)Shortcut fornewHasher().putString(input, charset).hash().HashCodehashUnencodedChars(java.lang.CharSequence input)Shortcut fornewHasher().putUnencodedChars(input).hash().HashernewHasher()Begins a new hash code computation by returning an initialized, statefulHasherinstance that is ready to receive data.HashernewHasher(int expectedInputSize)Begins a new hash code computation asHashFunction.newHasher(), but provides a hint of the expected size of the input (in bytes).-
Methods inherited from class com.google.common.hash.AbstractHashFunction
hashBytes, hashObject
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.common.hash.HashFunction
bits
-
-
-
-
Method Detail
-
newHasher
public Hasher newHasher()
Description copied from interface:HashFunctionBegins a new hash code computation by returning an initialized, statefulHasherinstance that is ready to receive data. Example:HashFunction hf = Hashing.md5(); HashCode hc = hf.newHasher() .putLong(id) .putBoolean(isActive) .hash();
-
newHasher
public Hasher newHasher(int expectedInputSize)
Description copied from interface:HashFunctionBegins a new hash code computation asHashFunction.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).- Specified by:
newHasherin interfaceHashFunction- Overrides:
newHasherin classAbstractHashFunction
-
hashInt
public HashCode hashInt(int input)
Description copied from interface:HashFunctionShortcut fornewHasher().putInt(input).hash(); returns the hash code for the givenintvalue, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashIntin interfaceHashFunction- Overrides:
hashIntin classAbstractHashFunction
-
hashLong
public HashCode hashLong(long input)
Description copied from interface:HashFunctionShortcut fornewHasher().putLong(input).hash(); returns the hash code for the givenlongvalue, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashLongin interfaceHashFunction- Overrides:
hashLongin classAbstractHashFunction
-
hashUnencodedChars
public HashCode hashUnencodedChars(java.lang.CharSequence input)
Description copied from interface:HashFunctionShortcut fornewHasher().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 eachcharare hashed directly (in that order).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
HashFunction.hashString(java.lang.CharSequence, java.nio.charset.Charset), usually with a charset of UTF-8. For other use cases, usehashUnencodedChars.- Specified by:
hashUnencodedCharsin interfaceHashFunction- Overrides:
hashUnencodedCharsin classAbstractHashFunction
-
hashString
public HashCode hashString(java.lang.CharSequence input, java.nio.charset.Charset charset)
Description copied from interface:HashFunctionShortcut fornewHasher().putString(input, charset).hash(). Characters are encoded using the givenCharset. The implementation might perform better than its longhand equivalent, but should not perform worse.Warning: This method, which reencodes the input before hashing it, is useful only for cross-language compatibility. For other use cases, prefer
HashFunction.hashUnencodedChars(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:
hashStringin interfaceHashFunction- Overrides:
hashStringin classAbstractHashFunction
-
hashBytes
public abstract HashCode hashBytes(byte[] input, int off, int len)
Description copied from interface:HashFunctionShortcut fornewHasher().putBytes(input, off, len).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashBytesin interfaceHashFunction- Overrides:
hashBytesin classAbstractHashFunction
-
hashBytes
public HashCode hashBytes(java.nio.ByteBuffer input)
Description copied from interface:HashFunctionShortcut fornewHasher().putBytes(input).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashBytesin interfaceHashFunction- Overrides:
hashBytesin classAbstractHashFunction
-
-