Top Description Inners Fields Constructors Methods
com.google.common.hash

pack-priv final Class Murmur3_32HashFunction

extends AbstractHashFunction
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@Immutable
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkPositionIndexes, .Preconditions.checkState, com.google.common.primitives.UnsignedBytes.toInt

See MurmurHash3_x86_32 in the C++ implementation.
Authors
Austin Appleby, Dimitris Andreou, Kurt Alfred Kluever

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
pack-priv static final HashFunction
pack-priv static final HashFunction
pack-priv static final HashFunction
private final int
private static final long
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
Murmur3_32HashFunction(int seed, boolean supplementaryPlaneFix)

Method Summary

Modifier and TypeMethod and Description
public int
bits()

Implements com.google.common.hash.HashFunction.bits.

Returns the number of bits (a multiple of 32) that each hash code produced by this hash function has.
private static long
private static long
private static long
codePointToFourUtf8Bytes(int codePoint)

public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private static HashCode
fmix(int h1, int length)

private static int
getIntLittleEndian(byte[] input, int offset)

public HashCode
hashBytes(byte[] input, int off, int len)

Overrides com.google.common.hash.AbstractHashFunction.hashBytes.

Implements com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input, off, len).hash().
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public HashCode
hashInt(int input)

Overrides com.google.common.hash.AbstractHashFunction.hashInt.

Implements com.google.common.hash.HashFunction.hashInt.

Shortcut for newHasher().putInt(input).hash(); returns the hash code for the given int value, interpreted in little-endian byte order.
public HashCode
hashLong(long input)

Overrides com.google.common.hash.AbstractHashFunction.hashLong.

Implements com.google.common.hash.HashFunction.hashLong.

Shortcut for newHasher().putLong(input).hash(); returns the hash code for the given long value, interpreted in little-endian byte order.
public HashCode
hashString(CharSequence input, Charset charset)

Overrides com.google.common.hash.AbstractHashFunction.hashString.

Implements com.google.common.hash.HashFunction.hashString.

Shortcut for newHasher().putString(input, charset).hash().
public HashCode
private static int
mixH1(int h1, int k1)

private static int
mixK1(int k1)

public Hasher
newHasher()

Implements com.google.common.hash.HashFunction.newHasher.

Begins a new hash code computation by returning an initialized, stateful Hasher instance that is ready to receive data.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.hash.AbstractHashFunction:
hashByteshashByteshashObjectnewHasher

Field Detail

C1back to summary
private static final int C1
C2back to summary
private static final int C2
CHUNK_SIZEback to summary
private static final int CHUNK_SIZE
GOOD_FAST_HASH_32back to summary
pack-priv static final HashFunction GOOD_FAST_HASH_32
MURMUR3_32back to summary
pack-priv static final HashFunction MURMUR3_32
MURMUR3_32_FIXEDback to summary
pack-priv static final HashFunction MURMUR3_32_FIXED
seedback to summary
private final int seed
serialVersionUIDback to summary
private static final long serialVersionUID
supplementaryPlaneFixback to summary
private final boolean supplementaryPlaneFix

Constructor Detail

Murmur3_32HashFunctionback to summary
pack-priv Murmur3_32HashFunction(int seed, boolean supplementaryPlaneFix)

Method Detail

bitsback to summary
public int bits()

Implements com.google.common.hash.HashFunction.bits.

Doc from com.google.common.hash.HashFunction.bits.

Returns the number of bits (a multiple of 32) that each hash code produced by this hash function has.

Annotations
@Override
charToThreeUtf8Bytesback to summary
private static long charToThreeUtf8Bytes(char c)
charToTwoUtf8Bytesback to summary
private static long charToTwoUtf8Bytes(char c)
codePointToFourUtf8Bytesback to summary
private static long codePointToFourUtf8Bytes(int codePoint)
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
object:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
fmixback to summary
private static HashCode fmix(int h1, int length)
getIntLittleEndianback to summary
private static int getIntLittleEndian(byte[] input, int offset)
hashBytesback to summary
public HashCode hashBytes(byte[] input, int off, int len)

Overrides com.google.common.hash.AbstractHashFunction.hashBytes.

Implements com.google.common.hash.HashFunction.hashBytes.

Doc from com.google.common.hash.HashFunction.hashBytes.

Shortcut for newHasher().putBytes(input, off, len).hash(). The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
hashIntback to summary
public HashCode hashInt(int input)

Overrides com.google.common.hash.AbstractHashFunction.hashInt.

Implements com.google.common.hash.HashFunction.hashInt.

Doc from com.google.common.hash.HashFunction.hashInt.

Shortcut for newHasher().putInt(input).hash(); returns the hash code for the given int value, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashLongback to summary
public HashCode hashLong(long input)

Overrides com.google.common.hash.AbstractHashFunction.hashLong.

Implements com.google.common.hash.HashFunction.hashLong.

Doc from com.google.common.hash.HashFunction.hashLong.

Shortcut for newHasher().putLong(input).hash(); returns the hash code for the given long value, interpreted in little-endian byte order. The implementation might perform better than its longhand equivalent, but should not perform worse.

Annotations
@Override
hashStringback to summary
public HashCode hashString(CharSequence input, Charset charset)

Overrides com.google.common.hash.AbstractHashFunction.hashString.

Implements com.google.common.hash.HashFunction.hashString.

Doc from com.google.common.hash.HashFunction.hashString.

Shortcut for newHasher().putString(input, charset).hash(). Characters are encoded using the given Charset. 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 hashUnencodedChars, which is faster, produces the same output across Java releases, and hashes every char in the input, even if some are invalid.

Annotations
@SuppressWarnings:deprecation
@Override
hashUnencodedCharsback to summary
public HashCode hashUnencodedChars(CharSequence input)

Overrides com.google.common.hash.AbstractHashFunction.hashUnencodedChars.

Implements com.google.common.hash.HashFunction.hashUnencodedChars.

Doc from com.google.common.hash.HashFunction.hashUnencodedChars.

Shortcut for newHasher().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 each char 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 hashString, usually with a charset of UTF-8. For other use cases, use hashUnencodedChars.

Annotations
@Override
mixH1back to summary
private static int mixH1(int h1, int k1)
mixK1back to summary
private static int mixK1(int k1)
newHasherback to summary
public Hasher newHasher()

Implements com.google.common.hash.HashFunction.newHasher.

Doc from com.google.common.hash.HashFunction.newHasher.

Begins a new hash code computation by returning an initialized, stateful Hasher instance that is ready to receive data. Example:

HashFunction hf = Hashing.md5();
HashCode hc = hf.newHasher()
    .putLong(id)
    .putBoolean(isActive)
    .hash();
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.google.common.hash back to summary

private final Class Murmur3_32HashFunction.Murmur3_32Hasher

extends AbstractHasher
Class Inheritance

Field Summary

Modifier and TypeField and Description
private long
private int
private boolean
private int
private int

Constructor Summary

AccessConstructor and Description
pack-priv
Murmur3_32Hasher(int seed)

Method Summary

Modifier and TypeMethod and Description
public HashCode
hash()

Implements com.google.common.hash.Hasher.hash.

Computes a hash code based on the data that have been provided to this hasher.
public Hasher
putByte(byte
a byte
b
)

Implements com.google.common.hash.Hasher.putByte.

Puts a byte into this sink.
public Hasher
putBytes(byte[]
a byte array
bytes
,
int
the start offset in the array
off
,
int
the number of bytes to write
len
)

Overrides com.google.common.hash.AbstractHasher.putBytes.

Implements com.google.common.hash.Hasher.putBytes.

Puts a chunk of an array of bytes into this sink.
public Hasher
putBytes(ByteBuffer
a byte buffer
buffer
)

Overrides com.google.common.hash.AbstractHasher.putBytes.

Implements com.google.common.hash.Hasher.putBytes.

Puts the remaining bytes of a byte buffer into this sink.
public Hasher
putChar(char c)

Overrides com.google.common.hash.AbstractHasher.putChar.

Implements com.google.common.hash.Hasher.putChar.

Puts a character into this sink.
public Hasher
putInt(int i)

Overrides com.google.common.hash.AbstractHasher.putInt.

Implements com.google.common.hash.Hasher.putInt.

Puts an int into this sink.
public Hasher
putLong(long l)

Overrides com.google.common.hash.AbstractHasher.putLong.

Implements com.google.common.hash.Hasher.putLong.

Puts a long into this sink.
public Hasher
putString(CharSequence input, Charset charset)

Overrides com.google.common.hash.AbstractHasher.putString.

Implements com.google.common.hash.Hasher.putString.

Equivalent to putBytes(charSequence.toString().getBytes(charset)).
private void
update(int nBytes, long update)

Inherited from com.google.common.hash.AbstractHasher:
putBooleanputBytesputDoubleputFloatputObjectputShortputUnencodedChars

Field Detail

bufferback to summary
private long buffer
h1back to summary
private int h1
isDoneback to summary
private boolean isDone
lengthback to summary
private int length
shiftback to summary
private int shift

Constructor Detail

Murmur3_32Hasherback to summary
pack-priv Murmur3_32Hasher(int seed)

Method Detail

hashback to summary
public HashCode hash()

Implements com.google.common.hash.Hasher.hash.

Doc from com.google.common.hash.Hasher.hash.

Computes a hash code based on the data that have been provided to this hasher. The result is unspecified if this method is called more than once on the same instance.

Annotations
@Override
putByteback to summary
public Hasher putByte(byte b)

Implements com.google.common.hash.Hasher.putByte.

Doc from com.google.common.hash.PrimitiveSink.putByte.

Puts a byte into this sink.

Parameters
b:byte

a byte

Returns:Hasher

this instance

Annotations
@CanIgnoreReturnValue
@Override
putBytesback to summary
public Hasher putBytes(byte[] bytes, int off, int len)

Overrides com.google.common.hash.AbstractHasher.putBytes.

Implements com.google.common.hash.Hasher.putBytes.

Doc from com.google.common.hash.PrimitiveSink.putBytes.

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.

Parameters
bytes:byte[]

a byte array

off:int

the start offset in the array

len:int

the number of bytes to write

Returns:Hasher

this instance

Annotations
@CanIgnoreReturnValue
@Override
putBytesback to summary
public Hasher putBytes(ByteBuffer buffer)

Overrides com.google.common.hash.AbstractHasher.putBytes.

Implements com.google.common.hash.Hasher.putBytes.

Doc from com.google.common.hash.PrimitiveSink.putBytes.

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.

Parameters
buffer:ByteBuffer

a byte buffer

Returns:Hasher

this instance

Annotations
@CanIgnoreReturnValue
@Override
putCharback to summary
public Hasher putChar(char c)

Overrides com.google.common.hash.AbstractHasher.putChar.

Implements com.google.common.hash.Hasher.putChar.

Doc from com.google.common.hash.PrimitiveSink.putChar.

Puts a character into this sink.

Annotations
@CanIgnoreReturnValue
@Override
putIntback to summary
public Hasher putInt(int i)

Overrides com.google.common.hash.AbstractHasher.putInt.

Implements com.google.common.hash.Hasher.putInt.

Doc from com.google.common.hash.PrimitiveSink.putInt.

Puts an int into this sink.

Annotations
@CanIgnoreReturnValue
@Override
putLongback to summary
public Hasher putLong(long l)

Overrides com.google.common.hash.AbstractHasher.putLong.

Implements com.google.common.hash.Hasher.putLong.

Doc from com.google.common.hash.PrimitiveSink.putLong.

Puts a long into this sink.

Annotations
@CanIgnoreReturnValue
@Override
putStringback to summary
public Hasher putString(CharSequence input, Charset charset)

Overrides com.google.common.hash.AbstractHasher.putString.

Implements com.google.common.hash.Hasher.putString.

Doc from com.google.common.hash.Hasher.putString.

Equivalent to putBytes(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 putUnencodedChars, which is faster, produces the same output across Java releases, and hashes every char in the input, even if some are invalid.

Annotations
@CanIgnoreReturnValue
@SuppressWarnings:deprecation
@Override
updateback to summary
private void update(int nBytes, long update)