Class MurmurHash3
java.lang.Object
com.loomcache.common.util.MurmurHash3
MurmurHash3 (32-bit) — fast, non-cryptographic hash for key distribution.
Why MurmurHash3? - Excellent distribution (passes all SMHasher tests) - Fast: ~3 GB/s on modern CPUs - No collision bias: critical for even partition distribution - Used by: Guava, Cassandra, Kafka, Redis Cluster
We use the 32-bit variant because our partition count fits in an int and 32-bit hashing is faster on most JVMs.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
MurmurHash3
public MurmurHash3()
-
-
Method Details
-
hash
Hash a string key to a positive integer.- Parameters:
key- the string key to hash (must not be null)- Returns:
- a positive hash value
-
hash
public static int hash(byte[] data) Hash a byte array using MurmurHash3 (32-bit, x86).- Parameters:
data- the byte array to hash (must not be null)- Returns:
- the hash value
-
hash
public static int hash(byte[] data, int offset, int length, int seed) Core MurmurHash3 implementation.Reference: https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
- Parameters:
data- the byte array to hash (must not be null)offset- the offset to start hashing fromlength- the number of bytes to hashseed- the seed value- Returns:
- the hash value
-