Package org.apache.datasketches.memory
Class MurmurHash3v2
- java.lang.Object
-
- org.apache.datasketches.memory.MurmurHash3v2
-
public final class MurmurHash3v2 extends Object
The MurmurHash3 is a fast, non-cryptographic, 128-bit hash function that has excellent avalanche and 2-way bit independence properties.
Austin Appleby's C++ MurmurHash3_x64_128(...), final revision 150, which is in the Public Domain, was the inspiration for this implementation in Java.
This implementation of the MurmurHash3 allows hashing of a block of on-heap Memory defined by an offset and length. The calling API also allows the user to supply the small output array of two longs, so that the entire hash function is static and free of object allocations.
This implementation produces exactly the same hash result as the MurmurHash3 function in datasketches-java given compatible inputs.
- Author:
- Lee Rhodes
-
-
Constructor Summary
Constructors Constructor Description MurmurHash3v2()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long[]
hash(byte[] in, long seed)
Returns a 128-bit hash of the input.static long[]
hash(char[] in, long seed)
Returns a 128-bit hash of the input.static long[]
hash(double in, long seed, long[] hashOut)
Returns a 128-bit hash of the input.static long[]
hash(int[] in, long seed)
Returns a 128-bit hash of the input.static long[]
hash(long[] in, long seed)
Returns a 128-bit hash of the input.static long[]
hash(long in, long seed, long[] hashOut)
Returns a 128-bit hash of the input.static long[]
hash(String in, long seed, long[] hashOut)
Returns a 128-bit hash of the input.static long[]
hash(Memory mem, long offsetBytes, long lengthBytes, long seed, long[] hashOut)
Returns a 128-bit hash of the input as a long array of size 2.
-
-
-
Method Detail
-
hash
public static long[] hash(long[] in, long seed)
Returns a 128-bit hash of the input. Provided for compatibility with older version of MurmurHash3, but empty or null input now throws IllegalArgumentException.- Parameters:
in
- long arrayseed
- A long valued seed.- Returns:
- the hash
-
hash
public static long[] hash(int[] in, long seed)
Returns a 128-bit hash of the input. Provided for compatibility with older version of MurmurHash3, but empty or null input now throws IllegalArgumentException.- Parameters:
in
- int arrayseed
- A long valued seed.- Returns:
- the hash
-
hash
public static long[] hash(char[] in, long seed)
Returns a 128-bit hash of the input. Provided for compatibility with older version of MurmurHash3, but empty or null input now throws IllegalArgumentException.- Parameters:
in
- char arrayseed
- A long valued seed.- Returns:
- the hash
-
hash
public static long[] hash(byte[] in, long seed)
Returns a 128-bit hash of the input. Provided for compatibility with older version of MurmurHash3, but empty or null input now throws IllegalArgumentException.- Parameters:
in
- byte arrayseed
- A long valued seed.- Returns:
- the hash
-
hash
public static long[] hash(long in, long seed, long[] hashOut)
Returns a 128-bit hash of the input. Note the entropy of the resulting hash cannot be more than 64 bits.- Parameters:
in
- a longseed
- A long valued seed.hashOut
- A long array of size 2- Returns:
- the hash
-
hash
public static long[] hash(double in, long seed, long[] hashOut)
Returns a 128-bit hash of the input. Note the entropy of the resulting hash cannot be more than 64 bits.- Parameters:
in
- a doubleseed
- A long valued seed.hashOut
- A long array of size 2- Returns:
- the hash
-
hash
public static long[] hash(String in, long seed, long[] hashOut)
Returns a 128-bit hash of the input. An empty or null input throws IllegalArgumentException.- Parameters:
in
- a Stringseed
- A long valued seed.hashOut
- A long array of size 2- Returns:
- the hash
-
hash
public static long[] hash(Memory mem, long offsetBytes, long lengthBytes, long seed, long[] hashOut)
Returns a 128-bit hash of the input as a long array of size 2.- Parameters:
mem
- The input on-heap Memory. Must be non-null and non-empty, otherwise throws IllegalArgumentException.offsetBytes
- the starting point within Memory.lengthBytes
- the total number of bytes to be hashed.seed
- A long valued seed.hashOut
- the size 2 long array for the resulting 128-bit hash- Returns:
- the hash.
-
-