public final class MurmurHash3 extends Object implements Serializable
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 java implementation pays close attention to the C++ algorithms in order to maintain bit-wise compatibility, but the design is quite different. This implementation has also been extended to include processing of arrays of longs, char or ints, which was not part of the original C++ implementation. This implementation produces the same exact output hash bits as the above C++ method given the same input.
In addition, with this implementation, the hash of byte[], char[], int[], or long[] will produce the same hash result if, and only if, all the arrays have the same exact length in bytes, and if the contents of the values in the arrays have the same byte endianness and overall order. There is a unit test for this class that demonstrates this.
The structure of this implementation also reflects a separation of code that is dependent on the input structure (in this case byte[], int[] or long[]) from code that is independent of the input structure. This also makes the code more readable and suitable for future extensions.
Modifier and Type | Method and Description |
---|---|
static long[] |
hash(byte[] key,
long seed)
Returns a long array of size 2, which is a 128-bit hash of the input.
|
static long[] |
hash(char[] key,
long seed)
Returns a long array of size 2, which is a 128-bit hash of the input.
|
static long[] |
hash(int[] key,
long seed)
Returns a long array of size 2, which is a 128-bit hash of the input.
|
static long[] |
hash(long[] key,
long seed)
Returns a long array of size 2, which is a 128-bit hash of the input.
|
public static long[] hash(long[] key, long seed)
key
- The input long[] array. Must be non-null and non-empty.seed
- A long valued seed.public static long[] hash(int[] key, long seed)
key
- The input int[] array. Must be non-null and non-empty.seed
- A long valued seed.public static long[] hash(char[] key, long seed)
key
- The input char[] array. Must be non-null and non-empty.seed
- A long valued seed.public static long[] hash(byte[] key, long seed)
key
- The input byte[] array. Must be non-null and non-empty.seed
- A long valued seed.Copyright © 2015–2021 The Apache Software Foundation. All rights reserved.