Package com.google.common.hash
Class AbstractHashFunction
java.lang.Object
com.google.common.hash.AbstractHashFunction
- All Implemented Interfaces:
HashFunction
- Direct Known Subclasses:
AbstractCompositeHashFunction,AbstractNonStreamingHashFunction,ChecksumHashFunction,Crc32cHashFunction,MacHashFunction,MessageDigestHashFunction,Murmur3_128HashFunction,Murmur3_32HashFunction,SipHashFunction
Skeleton implementation of
HashFunction in terms of HashFunction.newHasher().
TODO(lowasser): make public
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionhashBytes(byte[] input) Shortcut fornewHasher().putBytes(input).hash().hashBytes(byte[] input, int off, int len) Shortcut fornewHasher().putBytes(input, off, len).hash().hashBytes(ByteBuffer input) Shortcut fornewHasher().putBytes(input).hash().hashInt(int input) Shortcut fornewHasher().putInt(input).hash(); returns the hash code for the givenintvalue, interpreted in little-endian byte order.hashLong(long input) Shortcut fornewHasher().putLong(input).hash(); returns the hash code for the givenlongvalue, interpreted in little-endian byte order.<T> HashCodehashObject(T instance, Funnel<? super T> funnel) Shortcut fornewHasher().putObject(instance, funnel).hash().hashString(CharSequence input, Charset charset) Shortcut fornewHasher().putString(input, charset).hash().hashUnencodedChars(CharSequence input) Shortcut fornewHasher().putUnencodedChars(input).hash().newHasher(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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.google.common.hash.HashFunction
bits, newHasher
-
Constructor Details
-
AbstractHashFunction
AbstractHashFunction()
-
-
Method Details
-
hashObject
Description copied from interface:HashFunctionShortcut fornewHasher().putObject(instance, funnel).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashObjectin interfaceHashFunction
-
hashUnencodedChars
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
-
hashString
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
-
hashInt
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
-
hashLong
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
-
hashBytes
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
-
hashBytes
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
-
hashBytes
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
-
newHasher
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
-