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

inthash(Object obj)
Same hash function as HashMap#newHash method.
int h = obj.hashCode();
h ^= (h >>> 20) ^ (h >>> 12);
return h ^ (h >>> 7) ^ (h >>> 4);
Integerhash(Object obj)
hash
Integer rtn = null;
if (obj != null) {
    rtn = obj.hashCode();
return rtn;
inthash(Object object)
Returns a hash code for non-null Object x.
int h = object.hashCode();
h ^= (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_1) ^ (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_2);
return h ^ (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_3) ^ (h >>> DOUG_LEA_BLACK_MAGIC_OPERAND_4);
inthash(Object v)
hash
return v == null ? 0 : v.hashCode();
Stringhash(Object value)
hash
if (value == null) {
    return "null";
int hashcode = value.hashCode();
char[] hexChars = new char[8];
hexChars[0] = HEX_CHARS[(hashcode >> 28) & 0xF];
hexChars[1] = HEX_CHARS[(hashcode >> 24) & 0xF];
hexChars[2] = HEX_CHARS[(hashcode >> 20) & 0xF];
...
inthash(Object value, int seed)
Alters the given seed with the hash code value computed from the given value.
seed *= PRIME_NUMBER;
if (value != null) {
    assert !value.getClass().isArray() : value;
    seed += value.hashCode();
return seed;
inthash(Object... as)
Create a hash code for a list of objects.
if (as == null)
    return 0;
int hash = 0;
for (Object a : as) {
    if (hash != 0)
        hash = 41 * hash + hash1(a);
    else
        hash = 41 + hash1(a);
...
longhash(Object... value)
hash
String key = toString(value);
long hash;
int i;
for (hash = key.length(), i = 0; i < key.length(); ++i)
    hash = (hash << 4) ^ (hash >> 28) ^ key.charAt(i);
return hash;
inthash(Object... values)
hash
int code = 17;
for (Object value : values) {
    code += hashOrNull(value);
    code *= 37;
return code;
inthash(Object[] array)
calculate the array hash (only the first level)
int length = array.length;
int seed = SEED;
for (Object anArray : array) {
    seed = hash(seed, anArray == null ? 0 : anArray.hashCode());
return seed;