- java.lang.Object
-
- com.pervasive.datarush.commons.util.HashUtil
-
public final class HashUtil extends Object
Utility methods for hashing different data types.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 & maskinstead ofhash % primefor computing a hash bucket.
-
-
Field Summary
Fields Modifier and Type Field Description static intNULL_HASH_CODEAn arbitrary nonzero constant for the hash code of null valued tokens.
-
Constructor Summary
Constructors Constructor Description HashUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intbinaryHashCode(byte[] bytes)Hash a binary value using Bob Jenkins' "One-at-a-Time Hash".static intbinaryHashCode(byte[] bytes, int offset, int len)Hash a binary value using Bob Jenkins' "One-at-a-Time Hash".static intbooleanHashCode(boolean b)Hashes a boolean value using the same algorithm asintHashCode(int).static intcharHashCode(char c)Hashes a character value using the same algorithm asintHashCode(int).static intdoubleHashCode(double d)Hashes a double value using the same algorithm aslongHashCode(long).static intfinalMix(int a, int b, int c)Replicates the computation of Bob Jenkins' "final" macro.static intfloatHashCode(float f)Hashes a float value using the same algorithm asintHashCode(int).static intintHashCode(int a)Hash a binary value using Bob Jenkins' "4-byte Integer Hashing".static intlongHashCode(long l)Hashes a long value.static intobjectHashCode(Object o)Hashes an object usingObject.hashCode().static inttimestampHashCode(long epochSecs, int nanos)Hashes a timestamp decomposed in seconds and nanos parts.
-
-
-
Field Detail
-
NULL_HASH_CODE
public static final int NULL_HASH_CODE
An arbitrary nonzero constant for the hash code of null valued tokens.- See Also:
- Constant Field Values
-
-
Method Detail
-
binaryHashCode
public static final int binaryHashCode(byte[] bytes)
Hash a binary value using Bob Jenkins' "One-at-a-Time Hash".- Parameters:
bytes- the value to hash- Returns:
- the hash code
-
binaryHashCode
public static final int binaryHashCode(byte[] bytes, int offset, int len)Hash a binary value using Bob Jenkins' "One-at-a-Time Hash".- Parameters:
bytes- the value to hashoffset- start offsetlen- number of bytes to code- Returns:
- the hash code
-
intHashCode
public static final int intHashCode(int a)
Hash a binary value using Bob Jenkins' "4-byte Integer Hashing".- Parameters:
a- the value to hash- Returns:
- the hash code
-
charHashCode
public static final int charHashCode(char c)
Hashes a character value using the same algorithm asintHashCode(int).- Parameters:
c- the value to hash- Returns:
- the hash code
-
booleanHashCode
public static final int booleanHashCode(boolean b)
Hashes a boolean value using the same algorithm asintHashCode(int).- Parameters:
b- the value to hash- Returns:
- the hash code
-
doubleHashCode
public static final int doubleHashCode(double d)
Hashes a double value using the same algorithm aslongHashCode(long).- Parameters:
d- the value to hash- Returns:
- the hash code
-
floatHashCode
public static final int floatHashCode(float f)
Hashes a float value using the same algorithm asintHashCode(int).- Parameters:
f- the value to hash- Returns:
- the hash code
-
longHashCode
public static final int longHashCode(long l)
Hashes a long value.- Parameters:
l- the value to hash- Returns:
- the hash code
-
objectHashCode
public static final int objectHashCode(Object o)
Hashes an object usingObject.hashCode(). Null values are given their own hash code.- Parameters:
o- the value to hash- Returns:
- the hash code
-
timestampHashCode
public static final int timestampHashCode(long epochSecs, int nanos)Hashes a timestamp decomposed in seconds and nanos parts. Note that time zone offset is deliberately not included. Equal timestamp values in different time zones must have the same hashCode.- Parameters:
epochSecs- the seconds-since-epoch portion of the timestampnanos- the nanoseconds portion of the timestamp- Returns:
- the hash code
-
finalMix
public static final int finalMix(int a, int b, int c)Replicates the computation of Bob Jenkins' "final" macro.- Parameters:
a- the first input to the macrob- the second input to the macroc- the third input to the macro- Returns:
- the resulting mix
-
-