Java Utililty Methods Hash Calculate

List of utility methods to do Hash Calculate

Description

The list of methods to do Hash Calculate are organized into topic(s).

Method

inthashFNV32(int val)
32 bit FNV hash.
int hashVal = FNV_OFFSET_BASIS_32;
for (int i = 0; i < 4; i++) {
    int octet = val & 0x00ff;
    val = val >> 8;
    hashVal = hashVal ^ octet;
    hashVal = hashVal * FNV_PRIME_32;
return Math.abs(hashVal);
...
longhashFNV64(byte[] bytes)
FNV hashes are designed to be fast while maintaining a low collision rate.
long nHashVal = 0xcbf29ce484222325L;
long nMagicPrime = 0x00000100000001b3L;
for (int i = 0; i < bytes.length; i++) {
    nHashVal ^= bytes[i];
    nHashVal *= nMagicPrime;
return nHashVal;
inthashForEqual(Class clazz)
hash For Equal
return hashForEqual(clazz.getName());
inthashHC(int i)
hash HC
return (i * -1640531535) >>> ((MIN_MATCH * 8) - HASH_LOG_HC);
inthashHsieh(int init, Object... vals)
hash Hsieh
if (vals == null || vals.length == 0) {
    return init;
int hash = init;
for (final Object o : vals) {
    final int thingHash = o.hashCode();
    hash += (thingHash >>> 16);
    final int tmp = ((thingHash & 0xffff) << 11) ^ hash;
...
inthashInt(final int v)
Quickly mixes the bits of an integer.
final int h = v * INT_PHI;
return h ^ (h >>> 16);
inthashIntArray(int seed, int[] data, int offset, int len)
hash Int Array
int h1 = seed;
int off = offset;
int end = offset + len;
while (off < end) {
    int k1 = data[off++];
    k1 *= 0xcc9e2d51;
    k1 = Integer.rotateLeft(k1, 15);
    k1 *= 0x1b873593;
...
inthashIt(Object o)

Return an object's hash code or 0 if the object is null.

if (o == null)
    return 0;
else
    return o.hashCode();
inthashJava32(byte[] byteList)
This is a copy of the hash function in JDK 1.6 to ensure it does not change.
if (byteList == null) {
    return 0;
long hash = 1;
for (int i = 0; i < byteList.length; i++) {
    byte element = byteList[i];
    hash = 31 * hash + element;
return (int) hash & BITMASK_POSITIVE_32;
longhashJava64(byte[] byteList)
hash Java
if (byteList == null) {
    return 0;
long hash = 1;
for (byte element : byteList) {
    hash = 31 * hash + element;
return hash & BITMASK_POSITIVE_64;
...