|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.hadoop.util.hash.Hash org.apache.hadoop.util.hash.JenkinsHash
public class JenkinsHash
Produces 32-bit hash for hash table lookup.
lookup3.c, by Bob Jenkins, May 2006, Public Domain. You can use this free for any purpose. It's in the public domain. It has no warranty.
Field Summary |
---|
Fields inherited from class org.apache.hadoop.util.hash.Hash |
---|
INVALID_HASH, JENKINS_HASH, MURMUR_HASH |
Constructor Summary | |
---|---|
JenkinsHash()
|
Method Summary | |
---|---|
static Hash |
getInstance()
|
int |
hash(byte[] key,
int nbytes,
int initval)
taken from hashlittle() -- hash a variable-length key into a 32-bit value |
static void |
main(String[] args)
Compute the hash of the specified file |
Methods inherited from class org.apache.hadoop.util.hash.Hash |
---|
getHashType, getInstance, getInstance, hash, hash, parseHashType |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JenkinsHash()
Method Detail |
---|
public static Hash getInstance()
public int hash(byte[] key, int nbytes, int initval)
hash
in class Hash
key
- the key (the unaligned variable-length array of bytes)nbytes
- number of bytes to include in hashinitval
- can be any integer value
The best hash table sizes are powers of 2. There is no need to do mod
a prime (mod is sooo slow!). If you need less than 32 bits, use a bitmask.
For example, if you need only 10 bits, do
h = (h & hashmask(10));
In which case, the hash table should have hashsize(10) elements.
If you are hashing n strings byte[][] k, do it like this: for (int i = 0, h = 0; i < n; ++i) h = hash( k[i], h);
By Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. You may use this code any way you wish, private, educational, or commercial. It's free.
Use for hash table lookup, or anything where one collision in 2^^32 is acceptable. Do NOT use for cryptographic purposes.
public static void main(String[] args) throws IOException
args
- name of file to compute hash of.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |