Java Utililty Methods Hash Code Calculate

List of utility methods to do Hash Code Calculate

Description

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

Method

inthashCode(boolean bool)
Return the same value as Boolean#hashCode() .
return bool ? 1231 : 1237;
inthashCode(boolean bool)
hash Code
return (bool ? 1231 : 1237);
inthashCode(boolean value)
Returns hash code for a boolean value.
return (value ? 1231 : 1237);
inthashCode(byte a[])
Returns a hash code based on the contents of the specified array.
if (a == null) {
    return 0;
int result = 1;
for (int i = 0; i < a.length; i++) {
    result = 31 * result + a[i];
return result;
...
inthashCode(byte a[], int offset, int length)
hash Code
if (a == null)
    return 0;
int result = 1;
for (int i = offset; i < offset + length; i++) {
    result = 31 * result + a[i];
return result;
inthashCode(byte[] array)
bob jenkin's hash function
int hash = 0;
for (int i = 0; i < array.length; i++) {
    hash += array[i];
    hash += (hash << 10);
    hash ^= (hash >> 6);
hash += (hash << 3);
hash ^= (hash >> 11);
...
inthashCode(byte[] array, int size)
Returns a hash code for the elements of the given array.
int hashCode = 0;
for (int index = 0; index < size; index++) {
    hashCode ^= array[index];
return hashCode;
inthashCode(byte[] bytes, int offset, int length)
hash Code
int hash = 1;
for (int i = offset; i < offset + length; i++)
    hash = (31 * hash) + (int) bytes[i];
return hash;
inthashCode(byte[] bytes, int size)
A function that calculates hash code of a byte array based on its contents but using the given size parameter as deliminator for the content.
int contentLimit = size;
if (size > bytes.length)
    contentLimit = bytes.length;
int hashCode = 1;
for (int i = 0; i < contentLimit; i++)
    hashCode = 31 * hashCode + bytes[i];
return hashCode;
inthashCode(byte[] data, int offset, int len, int seed)
hash Code
final int c1 = 0xcc9e2d51;
final int c2 = 0x1b873593;
int h1 = seed;
int roundedEnd = offset + (len & 0xfffffffc); 
for (int i = offset; i < roundedEnd; i += 4) {
    int k1 = (data[i] & 0xff) | ((data[i + 1] & 0xff) << 8) | ((data[i + 2] & 0xff) << 16)
            | (data[i + 3] << 24);
    k1 *= c1;
...