java.lang.Object
com.pervasive.datarush.commons.util.HashUtil
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 & mask
instead of hash % prime for computing a hash bucket.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAn arbitrary nonzero constant for the hash code of null valued tokens. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final intbinaryHashCode(byte[] bytes) Hash a binary value using Bob Jenkins' "One-at-a-Time Hash".static final intbinaryHashCode(byte[] bytes, int offset, int len) Hash a binary value using Bob Jenkins' "One-at-a-Time Hash".static final intbooleanHashCode(boolean b) Hashes a boolean value using the same algorithm asintHashCode(int).static final intcharHashCode(char c) Hashes a character value using the same algorithm asintHashCode(int).static final intdoubleHashCode(double d) Hashes a double value using the same algorithm aslongHashCode(long).static final intfinalMix(int a, int b, int c) Replicates the computation of Bob Jenkins' "final" macro.static final intfloatHashCode(float f) Hashes a float value using the same algorithm asintHashCode(int).static final intintHashCode(int a) Hash a binary value using Bob Jenkins' "4-byte Integer Hashing".static final intlongHashCode(long l) Hashes a long value.static final intHashes an object usingObject.hashCode().static final inttimestampHashCode(long epochSecs, int nanos) Hashes a timestamp decomposed in seconds and nanos parts.
-
Field Details
-
NULL_HASH_CODE
public static final int NULL_HASH_CODEAn arbitrary nonzero constant for the hash code of null valued tokens.- See Also:
-
-
Constructor Details
-
HashUtil
public HashUtil()
-
-
Method Details
-
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
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
-