public final class HashUtil extends Object
These hashes are based on C code placed in the public domain by Bob Jenkins. They are advertised as strong enough to allow the
use of hash & mask
instead of hash % prime
for computing a hash bucket.
Modifier and Type | Field and Description |
---|---|
static int |
NULL_HASH_CODE
An arbitrary nonzero constant for the hash code of null valued tokens.
|
Constructor and Description |
---|
HashUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
binaryHashCode(byte[] bytes)
Hash a binary value using Bob Jenkins' "One-at-a-Time
Hash".
|
static int |
binaryHashCode(byte[] bytes,
int offset,
int len)
Hash a binary value using Bob Jenkins' "One-at-a-Time
Hash".
|
static int |
booleanHashCode(boolean b)
Hashes a boolean value using the same algorithm as
intHashCode(int) . |
static int |
charHashCode(char c)
Hashes a character value using the same algorithm as
intHashCode(int) . |
static int |
doubleHashCode(double d)
Hashes a double value using the same algorithm as
longHashCode(long) . |
static int |
finalMix(int a,
int b,
int c)
Replicates the computation of Bob Jenkins' "final" macro.
|
static int |
floatHashCode(float f)
Hashes a float value using the same algorithm as
intHashCode(int) . |
static int |
intHashCode(int a)
Hash a binary value using Bob Jenkins' "4-byte
Integer Hashing".
|
static int |
longHashCode(long l)
Hashes a long value.
|
static int |
objectHashCode(Object o)
Hashes an object using
Object.hashCode() . |
static int |
timestampHashCode(long epochSecs,
int nanos)
Hashes a timestamp decomposed in seconds and nanos parts.
|
public static final int NULL_HASH_CODE
public static final int binaryHashCode(byte[] bytes)
bytes
- the value to hashpublic static final int binaryHashCode(byte[] bytes, int offset, int len)
bytes
- the value to hashoffset
- start offsetlen
- number of bytes to codepublic static final int intHashCode(int a)
a
- the value to hashpublic static final int charHashCode(char c)
intHashCode(int)
.c
- the value to hashpublic static final int booleanHashCode(boolean b)
intHashCode(int)
.b
- the value to hashpublic static final int doubleHashCode(double d)
longHashCode(long)
.d
- the value to hashpublic static final int floatHashCode(float f)
intHashCode(int)
.f
- the value to hashpublic static final int longHashCode(long l)
l
- the value to hashpublic static final int objectHashCode(Object o)
Object.hashCode()
. Null values are given their own hash code.o
- the value to hashpublic static final int timestampHashCode(long epochSecs, int nanos)
epochSecs
- the seconds-since-epoch portion of the timestampnanos
- the nanoseconds portion of the timestamppublic static final int finalMix(int a, int b, int c)
a
- the first input to the macrob
- the second input to the macroc
- the third input to the macroCopyright © 2019 Actian Corporation. All rights reserved.