public class Hashes extends Object
Warning: the Jenkins hash algorithm has three state variables. The last variable is the standard Jenkins hash,
but in our implementation (up to Sux4J 2.0.1) we are mistakenly returning the first variable. Unfortunately, the
first-variable high bits might be constant on keys with the same high bits. The comment applies also to the
versions returning all three variables. This behaviour was fixed in Sux4J 2.1, but the fix changed the values returned by the methods of this
class based on Jenkins hashing and broke serialisation compatibility for several classes
(such as MWHCFunction and MinimalPerfectHashFunction).
| Modifier and Type | Method and Description |
|---|---|
static long |
jenkins(BitVector bv)
Jenkins 64-bit hashing.
|
static long |
jenkins(BitVector bv,
long seed)
Jenkins 64-bit hashing.
|
static void |
jenkins(BitVector bv,
long seed,
long[] h)
Jenkins 64-bit hashing (all three values produced).
|
static long |
jenkins(BitVector bv,
long prefixLength,
long[] aa,
long[] bb,
long[] cc)
Constant-time Jenkins 64-bit hashing for any prefix.
|
static void |
jenkins(BitVector bv,
long prefixLength,
long[] aa,
long[] bb,
long[] cc,
long[] h)
Constant-time Jenkins 64-bit hashing for any prefix (all three values produced).
|
static void |
jenkins(long[] triple,
long seed,
long[] h)
Jenkins 64-bit hashing (all three values produced) for a triple of longs.
|
static void |
main(String[] arg)
A simple test to check the relative speed of various hashes on your architecture.
|
static long |
murmur(BitVector bv,
long seed)
MurmurHash 64-bit
|
static long |
murmur(BitVector bv,
long prefixLength,
long[] state)
Constant-time MurmurHash 64-bit hashing for any prefix.
|
static long |
murmur(BitVector bv,
long prefixLength,
long[] state,
long lcp)
Constant-time MurmurHash 64-bit hashing reusing precomputed state partially.
|
static long |
murmur3(BitVector bv,
long seed)
MurmurHash3 64-bit
|
static void |
murmur3(BitVector bv,
long seed,
long[] h)
MurmurHash3 128-bit
|
static long |
murmur3(BitVector bv,
long prefixLength,
long[] hh1,
long[] hh2,
long[] cc1,
long[] cc2)
Constant-time MurmurHash3 64-bit hashing for any prefix.
|
static long |
murmur3(BitVector bv,
long prefixLength,
long[] hh1,
long[] hh2,
long[] cc1,
long[] cc2,
long lcp)
Constant-time MurmurHash3 64-bit hashing reusing precomputed state partially.
|
static void |
murmur3(BitVector bv,
long prefixLength,
long[] hh1,
long[] hh2,
long[] cc1,
long[] cc2,
long[] h)
Constant-time MurmurHash3 128-bit hashing for any prefix.
|
static void |
murmur3(BitVector bv,
long prefixLength,
long[] hh1,
long[] hh2,
long[] cc1,
long[] cc2,
long lcp,
long[] h)
Constant-time MurmurHash3 128-bit hashing reusing precomputed state partially.
|
static long[][] |
preprocessJenkins(BitVector bv,
long seed)
Preprocesses a bit vector so that Jenkins 64-bit hashing can be computed in constant time on all prefixes.
|
static long[] |
preprocessMurmur(BitVector bv,
long seed)
Preprocesses a bit vector so that MurmurHash 64-bit can be computed in constant time on all prefixes.
|
static long[][] |
preprocessMurmur3(BitVector bv,
long seed)
Preprocesses a bit vector so that MurmurHash3 can be computed in constant time on all prefixes.
|
public static void jenkins(BitVector bv, long seed, long[] h)
This code is based on the lookup8.c, and in particular on the version consuming 64 bits at a time, but it has been slightly modified to work correctly with any bit vector length (not just multiples of 64). Moreover, we return all three values generated by the algorithm.
Warning: see the class documentation comments about the hash values returned.
bv - a bit vector.seed - a seed for the hash.h - a triple of long values in which the three generated hashes will be saved.public static long jenkins(BitVector bv, long seed)
Warning: see the class documentation comments about the hash value returned.
bv - a bit vector.seed - a seed for the hash.jenkins(BitVector, long, long[]).public static long jenkins(BitVector bv)
Warning: see the class documentation comments about the hash value returned.
bv - a bit vector.jenkins(BitVector, long, long[]) with seed 0.public static long[][] preprocessJenkins(BitVector bv, long seed)
bv - a bit vector.seed - a seed for the hash.a, b and c
during the hash computation; these vector must be passed to jenkins(BitVector, long, long[], long[], long[]) (and analogous functions) in this order.jenkins(BitVector, long)public static void jenkins(BitVector bv, long prefixLength, long[] aa, long[] bb, long[] cc, long[] h)
Warning: see the class documentation comments about the hash values returned.
bv - a bit vector.prefixLength - the length of the prefix of bv over which the hash must be computed.aa - the first state array returned by preprocessJenkins(BitVector, long).bb - the second state array returned by preprocessJenkins(BitVector, long).cc - the third state array returned by preprocessJenkins(BitVector, long).h - a triple of long values in which the three generated hashes will be saved.public static long jenkins(BitVector bv, long prefixLength, long[] aa, long[] bb, long[] cc)
Warning: see the class documentation comments about the hash value returned.
bv - a bit vector.prefixLength - the length of the prefix of bv over which the hash must be computed.aa - the first state array returned by preprocessJenkins(BitVector, long).bb - the second state array returned by preprocessJenkins(BitVector, long).cc - the third state array returned by preprocessJenkins(BitVector, long).jenkins(BitVector, long, long[], long[], long[], long[]).public static void jenkins(long[] triple,
long seed,
long[] h)
Warning: see the class documentation comments about the hash values returned.
triple - three longs.seed - a seed for the hash.h - a triple of long values in which the three generated hashes will be saved.public static long murmur(BitVector bv, long seed)
This code is based on a mix of the sources that can be found at MurmurHash's web site, and in particular on the version consuming 64 bits at a time, which has been merged with the 2A version to obtain an incremental implementation.
bv - a bit vector.seed - a seed for the hash.public static long murmur(BitVector bv, long prefixLength, long[] state)
bv - a bit vector.prefixLength - the length of the prefix of bv over which the hash must be computed.state - the state array returned by preprocessMurmur(BitVector, long).bv or prefixLength bits.public static long murmur(BitVector bv, long prefixLength, long[] state, long lcp)
bv - a bit vector.prefixLength - the length of the prefix of bv over which the hash must be computed.state - the state array returned by preprocessMurmur(BitVector, long).lcp - the length of the longest common prefix between bv and the vector over which state was computed.bv or prefixLength bits.public static long[] preprocessMurmur(BitVector bv, long seed)
bv - a bit vector.seed - a seed for the hash.h
during the hash computation; these vector must be passed to murmur(BitVector, long, long[])
(and analogous functions) in this order.murmur(BitVector, long)public static void murmur3(BitVector bv, long seed, long[] h)
This code is based on a mix of the sources that can be found at MurmurHash's web site.
Warning: this code is still experimental.
bv - a bit vector.seed - a seed for the hash.h - a pair of long values in which the two generated hashes will be saved.public static long murmur3(BitVector bv, long seed)
This code is based on a mix of the sources that can be found at MurmurHash's web site.
Warning: this code is still experimental.
bv - a bit vector.seed - a seed for the hash.public static void murmur3(BitVector bv, long prefixLength, long[] hh1, long[] hh2, long[] cc1, long[] cc2, long[] h)
Warning: this code is still experimental.
bv - a bit vector.prefixLength - the length of the prefix of bv over which the hash must be computed.hh1 - the first component of the state array returned by preprocessMurmur3(BitVector, long).hh2 - the second component of the state array returned by preprocessMurmur3(BitVector, long).cc1 - the third component of the state array returned by preprocessMurmur3(BitVector, long).cc2 - the fourth component of the state array returned by preprocessMurmur3(BitVector, long).h - a pair of long values in which the two generated hashes will be saved.public static long murmur3(BitVector bv, long prefixLength, long[] hh1, long[] hh2, long[] cc1, long[] cc2)
Warning: this code is still experimental.
bv - a bit vector.prefixLength - the length of the prefix of bv over which the hash must be computed.hh1 - the first component of the state array returned by preprocessMurmur3(BitVector, long).hh2 - the second component of the state array returned by preprocessMurmur3(BitVector, long).cc1 - the third component of the state array returned by preprocessMurmur3(BitVector, long).cc2 - the fourth component of the state array returned by preprocessMurmur3(BitVector, long).public static void murmur3(BitVector bv, long prefixLength, long[] hh1, long[] hh2, long[] cc1, long[] cc2, long lcp, long[] h)
Warning: this code is still experimental.
bv - a bit vector.prefixLength - the length of the prefix of bv over which the hash must be computed.hh1 - the first component of the state array returned by preprocessMurmur3(BitVector, long).hh2 - the second component of the state array returned by preprocessMurmur3(BitVector, long).cc1 - the third component of the state array returned by preprocessMurmur3(BitVector, long).cc2 - the fourth component of the state array returned by preprocessMurmur3(BitVector, long).lcp - the length of the longest common prefix between bv and the vector over which state was computed.h - a pair of long values in which the two generated hashes will be saved.public static long murmur3(BitVector bv, long prefixLength, long[] hh1, long[] hh2, long[] cc1, long[] cc2, long lcp)
Warning: this code is still experimental.
bv - a bit vector.prefixLength - the length of the prefix of bv over which the hash must be computed.hh1 - the first component of the state array returned by preprocessMurmur3(BitVector, long).hh2 - the second component of the state array returned by preprocessMurmur3(BitVector, long).cc1 - the third component of the state array returned by preprocessMurmur3(BitVector, long).cc2 - the fourth component of the state array returned by preprocessMurmur3(BitVector, long).lcp - the length of the longest common prefix between bv and the vector over which state was computed.public static long[][] preprocessMurmur3(BitVector bv, long seed)
Warning: this code is still experimental.
bv - a bit vector.seed - a seed for the hash.h1, h2, c1 and c2
during the hash computation; these vector must be passed to murmur3(BitVector, long, long[], long[], long[], long[])
(and analogous functions) in this order.murmur3(BitVector, long)public static void main(String[] arg)
arg - the length of the bit vector to hash, and then the number of evaluations.