Package org.apache.commons.codec.digest
Class MurmurHash3
- java.lang.Object
-
- org.apache.commons.codec.digest.MurmurHash3
-
public final class MurmurHash3 extends java.lang.Object
MurmurHash3 yields a 32-bit or 128-bit value. MurmurHash is a non-cryptographic hash function suitable for general hash-based lookup. The name comes from two basic operations, multiply (MU) and rotate (R), used in its inner loop. Unlike cryptographic hash functions, it is not specifically designed to be difficult to reverse by an adversary, making it unsuitable for cryptographic purposes. 32-bit Java port of https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp#94 128-bit Java port of https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp#255 This is a public domain code with no copyrights. From homepage of MurmurHash (https://code.google.com/p/smhasher/), "All MurmurHash versions are public domain software, and the author disclaims all copyright to their code." Copied from Apache Hive: https://github.com/apache/hive/blob/master/storage-api/src/java/org/apache/hive/common/util/Murmur3.java- Since:
- 1.13
- See Also:
- MurmurHash
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MurmurHash3.IncrementalHash32
-
Field Summary
Fields Modifier and Type Field Description private static long
C1
private static int
C1_32
private static long
C2
private static int
C2_32
static int
DEFAULT_SEED
(package private) static int
INTEGER_BYTES
TODO Replace on Java 8 with Integer.BYTES.(package private) static int
LONG_BYTES
TODO Replace on Java 8 with Long.BYTES.private static int
M
private static int
M_32
private static int
N_32
private static int
N1
private static int
N2
static long
NULL_HASHCODE
private static int
R1
private static int
R1_32
private static int
R2
private static int
R2_32
private static int
R3
(package private) static int
SHORT_BYTES
TODO Replace on Java 8 with Short.BYTES.
-
Constructor Summary
Constructors Modifier Constructor Description private
MurmurHash3()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static int
fmix32(int length, int hash)
private static long
fmix64(long h)
static long[]
hash128(byte[] data)
Murmur3 128-bit variant.static long[]
hash128(byte[] data, int offset, int length, int seed)
Murmur3 128-bit variant.static long[]
hash128(java.lang.String data)
Murmur3 128-bit variant.static int
hash32(byte[] data)
Generates 32 bit hash from byte array with the default seed.static int
hash32(byte[] data, int length)
Generates 32 bit hash from byte array with the default seed.static int
hash32(byte[] data, int length, int seed)
Generates 32 bit hash from byte array with the given length and seed.static int
hash32(byte[] data, int offset, int length, int seed)
Generates 32 bit hash from byte array with the given length, offset and seed.static int
hash32(long l0)
Generates 32 bit hash from a long with default seed value.static int
hash32(long l0, int seed)
Generates 32 bit hash from a long with the given seed.static int
hash32(long l0, long l1)
Generates 32 bit hash from two longs with default seed value.static int
hash32(long l0, long l1, int seed)
Generates 32 bit hash from two longs with the given seed.static int
hash32(java.lang.String data)
Generates 32 bit hash from a string with the default seed.static long
hash64(byte[] data)
Murmur3 64-bit variant.static long
hash64(byte[] data, int offset, int length)
Generates 64 bit hash from byte array with the given length, offset and default seed.static long
hash64(byte[] data, int offset, int length, int seed)
Generates 64 bit hash from byte array with the given length, offset and seed.static long
hash64(int data)
Murmur3 64-bit variant.static long
hash64(long data)
Murmur3 64-bit variant.static long
hash64(short data)
Murmur3 64-bit variant.private static int
mix32(int k, int hash)
private static int
orBytes(byte b1, byte b2, byte b3, byte b4)
-
-
-
Field Detail
-
LONG_BYTES
static final int LONG_BYTES
TODO Replace on Java 8 with Long.BYTES.- See Also:
- Constant Field Values
-
INTEGER_BYTES
static final int INTEGER_BYTES
TODO Replace on Java 8 with Integer.BYTES.- See Also:
- Constant Field Values
-
SHORT_BYTES
static final int SHORT_BYTES
TODO Replace on Java 8 with Short.BYTES.- See Also:
- Constant Field Values
-
NULL_HASHCODE
public static final long NULL_HASHCODE
- See Also:
- Constant Field Values
-
C1_32
private static final int C1_32
- See Also:
- Constant Field Values
-
C2_32
private static final int C2_32
- See Also:
- Constant Field Values
-
R1_32
private static final int R1_32
- See Also:
- Constant Field Values
-
R2_32
private static final int R2_32
- See Also:
- Constant Field Values
-
M_32
private static final int M_32
- See Also:
- Constant Field Values
-
N_32
private static final int N_32
- See Also:
- Constant Field Values
-
C1
private static final long C1
- See Also:
- Constant Field Values
-
C2
private static final long C2
- See Also:
- Constant Field Values
-
R1
private static final int R1
- See Also:
- Constant Field Values
-
R2
private static final int R2
- See Also:
- Constant Field Values
-
R3
private static final int R3
- See Also:
- Constant Field Values
-
M
private static final int M
- See Also:
- Constant Field Values
-
N1
private static final int N1
- See Also:
- Constant Field Values
-
N2
private static final int N2
- See Also:
- Constant Field Values
-
DEFAULT_SEED
public static final int DEFAULT_SEED
- See Also:
- Constant Field Values
-
-
Method Detail
-
hash32
public static int hash32(long l0, long l1)
Generates 32 bit hash from two longs with default seed value.- Parameters:
l0
- long to hashl1
- long to hash- Returns:
- 32 bit hash
-
hash32
public static int hash32(long l0)
Generates 32 bit hash from a long with default seed value.- Parameters:
l0
- long to hash- Returns:
- 32 bit hash
-
hash32
public static int hash32(long l0, int seed)
Generates 32 bit hash from a long with the given seed.- Parameters:
l0
- long to hashseed
- initial seed value- Returns:
- 32 bit hash
-
hash32
public static int hash32(long l0, long l1, int seed)
Generates 32 bit hash from two longs with the given seed.- Parameters:
l0
- long to hashl1
- long to hashseed
- initial seed value- Returns:
- 32 bit hash
-
hash32
public static int hash32(byte[] data)
Generates 32 bit hash from byte array with the default seed.- Parameters:
data
- - input byte array- Returns:
- 32 bit hash
-
hash32
public static int hash32(java.lang.String data)
Generates 32 bit hash from a string with the default seed.- Parameters:
data
- - input string- Returns:
- 32 bit hash
-
hash32
public static int hash32(byte[] data, int length)
Generates 32 bit hash from byte array with the default seed.- Parameters:
data
- - input byte arraylength
- - length of array- Returns:
- 32 bit hash
-
hash32
public static int hash32(byte[] data, int length, int seed)
Generates 32 bit hash from byte array with the given length and seed.- Parameters:
data
- - input byte arraylength
- - length of arrayseed
- - seed. (default 0)- Returns:
- 32 bit hash
-
hash32
public static int hash32(byte[] data, int offset, int length, int seed)
Generates 32 bit hash from byte array with the given length, offset and seed.- Parameters:
data
- - input byte arrayoffset
- - offset of datalength
- - length of arrayseed
- - seed. (default 0)- Returns:
- 32 bit hash
-
hash64
public static long hash64(byte[] data)
Murmur3 64-bit variant. This is essentially MSB 8 bytes of Murmur3 128-bit variant.- Parameters:
data
- - input byte array- Returns:
- 64 bit hash
-
hash64
public static long hash64(long data)
Murmur3 64-bit variant. This is essentially MSB 8 bytes of Murmur3 128-bit variant.- Parameters:
data
- - input long- Returns:
- 64 bit hash
-
hash64
public static long hash64(int data)
Murmur3 64-bit variant. This is essentially MSB 8 bytes of Murmur3 128-bit variant.- Parameters:
data
- - input int- Returns:
- 64 bit hash
-
hash64
public static long hash64(short data)
Murmur3 64-bit variant. This is essentially MSB 8 bytes of Murmur3 128-bit variant.- Parameters:
data
- - input short- Returns:
- 64 bit hash
-
hash64
public static long hash64(byte[] data, int offset, int length)
Generates 64 bit hash from byte array with the given length, offset and default seed.- Parameters:
data
- - input byte arrayoffset
- - offset of datalength
- - length of array- Returns:
- 64 bit hash
-
hash64
public static long hash64(byte[] data, int offset, int length, int seed)
Generates 64 bit hash from byte array with the given length, offset and seed.- Parameters:
data
- - input byte arrayoffset
- - offset of datalength
- - length of arrayseed
- - seed. (default 0)- Returns:
- 64 bit hash
-
hash128
public static long[] hash128(byte[] data)
Murmur3 128-bit variant.- Parameters:
data
- - input byte array- Returns:
- - 128 bit hash (2 longs)
-
hash128
public static long[] hash128(java.lang.String data)
Murmur3 128-bit variant.- Parameters:
data
- - input String- Returns:
- - 128 bit hash (2 longs)
-
hash128
public static long[] hash128(byte[] data, int offset, int length, int seed)
Murmur3 128-bit variant.- Parameters:
data
- - input byte arrayoffset
- - the first element of arraylength
- - length of arrayseed
- - seed. (default is 0)- Returns:
- - 128 bit hash (2 longs)
-
mix32
private static int mix32(int k, int hash)
-
fmix32
private static int fmix32(int length, int hash)
-
fmix64
private static long fmix64(long h)
-
orBytes
private static int orBytes(byte b1, byte b2, byte b3, byte b4)
-
-