Package com.google.common.hash
Class Murmur3_32HashFunction
- java.lang.Object
-
- com.google.common.hash.AbstractHashFunction
-
- com.google.common.hash.Murmur3_32HashFunction
-
- All Implemented Interfaces:
HashFunction
,java.io.Serializable
final class Murmur3_32HashFunction extends AbstractHashFunction implements java.io.Serializable
See MurmurHash3_x86_32 in the C++ implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Murmur3_32HashFunction.Murmur3_32Hasher
-
Field Summary
Fields Modifier and Type Field Description private static int
C1
private static int
C2
private static int
CHUNK_SIZE
(package private) static HashFunction
GOOD_FAST_HASH_32
(package private) static HashFunction
MURMUR3_32
(package private) static HashFunction
MURMUR3_32_FIXED
private int
seed
private static long
serialVersionUID
private boolean
supplementaryPlaneFix
-
Constructor Summary
Constructors Constructor Description Murmur3_32HashFunction(int seed, boolean supplementaryPlaneFix)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
bits()
Returns the number of bits (a multiple of 32) that each hash code produced by this hash function has.private static long
charToThreeUtf8Bytes(char c)
private static long
charToTwoUtf8Bytes(char c)
private static long
codePointToFourUtf8Bytes(int codePoint)
boolean
equals(java.lang.Object object)
private static HashCode
fmix(int h1, int length)
private static int
getIntLittleEndian(byte[] input, int offset)
HashCode
hashBytes(byte[] input, int off, int len)
Shortcut fornewHasher().putBytes(input, off, len).hash()
.int
hashCode()
HashCode
hashInt(int input)
Shortcut fornewHasher().putInt(input).hash()
; returns the hash code for the givenint
value, interpreted in little-endian byte order.HashCode
hashLong(long input)
Shortcut fornewHasher().putLong(input).hash()
; returns the hash code for the givenlong
value, interpreted in little-endian byte order.HashCode
hashString(java.lang.CharSequence input, java.nio.charset.Charset charset)
Shortcut fornewHasher().putString(input, charset).hash()
.HashCode
hashUnencodedChars(java.lang.CharSequence input)
Shortcut fornewHasher().putUnencodedChars(input).hash()
.private static int
mixH1(int h1, int k1)
private static int
mixK1(int k1)
Hasher
newHasher()
Begins a new hash code computation by returning an initialized, statefulHasher
instance that is ready to receive data.java.lang.String
toString()
-
Methods inherited from class com.google.common.hash.AbstractHashFunction
hashBytes, hashBytes, hashObject, newHasher
-
-
-
-
Field Detail
-
MURMUR3_32
static final HashFunction MURMUR3_32
-
MURMUR3_32_FIXED
static final HashFunction MURMUR3_32_FIXED
-
GOOD_FAST_HASH_32
static final HashFunction GOOD_FAST_HASH_32
-
CHUNK_SIZE
private static final int CHUNK_SIZE
- See Also:
- Constant Field Values
-
C1
private static final int C1
- See Also:
- Constant Field Values
-
C2
private static final int C2
- See Also:
- Constant Field Values
-
seed
private final int seed
-
supplementaryPlaneFix
private final boolean supplementaryPlaneFix
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
bits
public int bits()
Description copied from interface:HashFunction
Returns the number of bits (a multiple of 32) that each hash code produced by this hash function has.- Specified by:
bits
in interfaceHashFunction
-
newHasher
public Hasher newHasher()
Description copied from interface:HashFunction
Begins a new hash code computation by returning an initialized, statefulHasher
instance that is ready to receive data. Example:HashFunction hf = Hashing.md5(); HashCode hc = hf.newHasher() .putLong(id) .putBoolean(isActive) .hash();
- Specified by:
newHasher
in interfaceHashFunction
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(@CheckForNull java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
hashInt
public HashCode hashInt(int input)
Description copied from interface:HashFunction
Shortcut fornewHasher().putInt(input).hash()
; returns the hash code for the givenint
value, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashInt
in interfaceHashFunction
- Overrides:
hashInt
in classAbstractHashFunction
-
hashLong
public HashCode hashLong(long input)
Description copied from interface:HashFunction
Shortcut fornewHasher().putLong(input).hash()
; returns the hash code for the givenlong
value, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashLong
in interfaceHashFunction
- Overrides:
hashLong
in classAbstractHashFunction
-
hashUnencodedChars
public HashCode hashUnencodedChars(java.lang.CharSequence input)
Description copied from interface:HashFunction
Shortcut 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 eachchar
are 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:
hashUnencodedChars
in interfaceHashFunction
- Overrides:
hashUnencodedChars
in classAbstractHashFunction
-
hashString
public HashCode hashString(java.lang.CharSequence input, java.nio.charset.Charset charset)
Description copied from interface:HashFunction
Shortcut 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 everychar
in the input, even if some are invalid.- Specified by:
hashString
in interfaceHashFunction
- Overrides:
hashString
in classAbstractHashFunction
-
hashBytes
public HashCode hashBytes(byte[] input, int off, int len)
Description copied from interface:HashFunction
Shortcut fornewHasher().putBytes(input, off, len).hash()
. The implementation might perform better than its longhand equivalent, but should not perform worse.- Specified by:
hashBytes
in interfaceHashFunction
- Overrides:
hashBytes
in classAbstractHashFunction
-
getIntLittleEndian
private static int getIntLittleEndian(byte[] input, int offset)
-
mixK1
private static int mixK1(int k1)
-
mixH1
private static int mixH1(int h1, int k1)
-
fmix
private static HashCode fmix(int h1, int length)
-
codePointToFourUtf8Bytes
private static long codePointToFourUtf8Bytes(int codePoint)
-
charToThreeUtf8Bytes
private static long charToThreeUtf8Bytes(char c)
-
charToTwoUtf8Bytes
private static long charToTwoUtf8Bytes(char c)
-
-