List of utility methods to do Hash Calculate
int | hashJenkins(int init, Object... vals) hash Jenkins if (vals == null || vals.length == 0) { return init; int a, b, c; a = b = c = BASE + (vals.length << 2) + init; int pos = 0; while (vals.length - pos > 3) { a += vals[pos].hashCode(); ... |
int | hashLong(long id) hash Long return (int) (id ^ id >>> 32); |
int | hashLong(long l) Returns a hash code for a long. return (int) (l ^ (l >>> 32)); |
int | hashMapCapacity(final int nElements) return a good initialCapacity for a HashMap that will hold a given number of elements return (int) ((nElements * 4L) / 3) + 1; |
int | hashMore(final int hash, final int more) hash More int result = hash << 1; if (result < 0) result |= 1; return result ^ more; |
long | hashName(CharSequence name) hash Name long hash = 0L; int size = name.length(); for (int index = 0; index < size; index++) { hash *= 37L; char c = name.charAt(index); if (c >= 'A' && c <= 'Z') { hash += (long) ('\001' + c - 'A'); } else if (c >= 'a' && c <= 'z') { ... |
int | hashObject(Object obj) A convenience function for hashing an object without getting NullPointerException s return obj == null ? 0 : obj.hashCode();
|
int | hashOrNull(Object value) hash Or Null return value == null ? 1 : value.hashCode();
|
int | hashOrZero(Object o) Note -- if you are using Arrays.equals( ... return (o == null ? 0 : o.hashCode());
|
long | hashPair(int a, int b) Generates a unique number based from two arguments. if (a >= 0 || b >= 0) { return a >= b ? a * a + a + b : a + b * b; } else { throw new IllegalArgumentException("a and b must be positive."); |