public final class JenkinsLookup3HashLittle
extends java.lang.Object
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.
Modifier and Type | Method and Description |
---|---|
static int |
hash(byte[] key)
Equivalent to
hash(byte[] bytes, int initialValue) with initialValue = 0 |
static int |
hash(byte[] bytes,
int initialValue)
The best hash table sizes are powers of 2.
|
static int |
hash(java.nio.ByteBuffer byteBuffer)
Equivalent to
hash(ByteBuffer byteBuffer, int initialValue) with initialValue = 0 |
static int |
hash(java.nio.ByteBuffer byteBuffer,
int initialValue)
The best hash table sizes are powers of 2.
|
public static int hash(byte[] key)
hash(byte[] bytes, int initialValue)
with initialValue = 0key
- bytes to hashpublic static int hash(java.nio.ByteBuffer byteBuffer)
hash(ByteBuffer byteBuffer, int initialValue)
with initialValue = 0byteBuffer
- bytes to hashpublic static int hash(byte[] bytes, int initialValue)
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.
bytes
- bytes to hashinitialValue
- can be any integer valuepublic static int hash(java.nio.ByteBuffer byteBuffer, int initialValue)
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.
byteBuffer
- to hashinitialValue
- can be any integer value