public final class HashFunctions extends Object
| Modifier and Type | Field and Description |
|---|---|
static long |
FNV_BASIS
Fowler/Noll/Vo hash algorithms FNV_BASIS constant
|
static long |
FNV_PRIME_32
Fowler/Noll/Vo hash algorithms FNV_PRIME constant for 32 bit hash
|
static long |
FNV_PRIME_64
Fowler/Noll/Vo hash algorithms FNV_PRIME constant for 64 bit hash
|
| Modifier and Type | Method and Description |
|---|---|
static int |
FVN32hash(byte[] bytes)
Fowler-Noll-Vo 32 bit hash (FNV-1a) for bytes array.
|
static int |
FVN32hash(int c)
Fowler-Noll-Vo 32 bit hash (FNV-1a) for integer key.
|
static long |
FVN64hash(byte[] bytes)
Fowler-Noll-Vo 64 bit hash (FNV-1a) for bytes array.
|
static long |
FVN64hash(long c)
Fowler-Noll-Vo 64 bit hash (FNV-1a) for long key.
|
static int |
FVN64to32hash(long c)
Fowler-Noll-Vo 32 bit hash (FNV-1a) for long key.
|
static int |
JenkinWang32shift(int key)
Based on an original suggestion on Robert Jenkin's part in 1997 and Thomas Wang 2007 updates.
|
static long |
JenkinWang64shift(long key)
Based on an original suggestion on Robert Jenkin's part in 1997 and Thomas Wang 2007 updates.
|
static int |
mix(int a,
int b,
int c)
Robert Jenkins' 96 bit Mix Function.
|
static int |
MurmurHash2(byte[] data)
MurmurHash hash function for bytes array with default seed value equals 0x2f1a32b3.
|
static int |
MurmurHash2(byte[] data,
int seed)
MurmurHash hash function for bytes array.
|
static int |
MurmurHash2(int c)
MurmurHash hash function integer with default seed value equals to 0x2f1a32b3.
|
static int |
MurmurHash2(int c,
int seed)
MurmurHash hash function integer.
|
static int |
Wang32shiftmult(int key)
This method uses a combination of bit shifts and integer multiplication to hash the input key.
|
static int |
Wang64to32shift(long key)
Hashing long to int.
|
public static final long FNV_BASIS
public static final long FNV_PRIME_32
public static final long FNV_PRIME_64
public static int mix(int a,
int b,
int c)
Subtraction is similar to multiplication in that changes in upper bits of the key do not influence lower bits of the addition. The 9 bit shift operations in Robert Jenkins' mixing algorithm shifts the key to the right 61 bits in total, and shifts the key to the left 34 bits in total. As the calculation is chained, each exclusive-or doubles the number of states. There are at least 2^9 different combined versions of the original key, shifted by various amounts. That is why a single bit change in the key can influence widely apart bits in the hash result.
The uniform distribution of the hash function can be determined from the nature of the subtraction operation. Look at a single bit subtraction operation between a key, and a random bit. If the random bit is 0, then the key remains unchanged. If the random bit is 1, then the key will be flipped. A carry will occur in the case where both the key bit and the random bit are 1. Subtracting the random bits will cause about half of the key bits to be flipped. So even if the key is not uniform, subtracting the random bits will result in uniform distribution.
a - initialized random bitsb - initialized random bitsc - key to be hashedpublic static int JenkinWang32shift(int key)
key - key to be hashedpublic static int Wang32shiftmult(int key)
key - key to be hashedpublic static long JenkinWang64shift(long key)
key - key to be hashedpublic static int Wang64to32shift(long key)
key - key to be hashedpublic static int FVN32hash(byte[] bytes)
hash = offset_basis
for each octet_of_data to be hashed
hash = hash xor octet_of_data
hash = hash * FNV_prime
return hash
bytes - bytes array to hashpublic static int FVN32hash(int c)
hash = offset_basis
for each octet_of_data to be hashed
hash = hash xor octet_of_data
hash = hash * FNV_prime
return hash
c - integer key to be hashedpublic static long FVN64hash(byte[] bytes)
hash = offset_basis
for each octet_of_data to be hashed
hash = hash xor octet_of_data
hash = hash * FNV_prime
return hash
bytes - bytes array to hashpublic static long FVN64hash(long c)
hash = offset_basis
for each octet_of_data to be hashed
hash = hash xor octet_of_data
hash = hash * FNV_prime
return hash
c - long key to be hashedpublic static int FVN64to32hash(long c)
hash = offset_basis
for each octet_of_data to be hashed
hash = hash xor octet_of_data
hash = hash * FNV_prime
return hash
c - long key to be hashedpublic static int MurmurHash2(byte[] data,
int seed)
data - bytes to be hashedseed - seed parameterpublic static int MurmurHash2(int c,
int seed)
c - int to be hashedseed - seed parameterpublic static int MurmurHash2(byte[] data)
data - bytes to be hashedpublic static int MurmurHash2(int c)
c - int to be hashed\Copyright © 2018. All rights reserved.