Java Hash Calculate hashJava32(byte[] byteList)

Here you can find the source of hashJava32(byte[] byteList)

Description

This is a copy of the hash function in JDK 1.6 to ensure it does not change.

License

Open Source License

Parameter

Parameter Description
byteList The bytes to hash

Return

A 32 bits hash

Declaration

public static int hashJava32(byte[] byteList) 

Method Source Code

//package com.java2s;
/**/*from   ww  w .  j  av a2 s  . co  m*/
 * Copyright 2014 Expedia, Inc. All rights reserved.
 * EXPEDIA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {
    private static final int BITMASK_POSITIVE_32 = ~0x80000000;

    /**
     * This is a copy of the hash function in JDK 1.6 to ensure it does not change.
     * MultiCache will lose data if the function changes.
     *
     * @param byteList      The bytes to hash
     * @return            A 32 bits hash
     */
    public static int hashJava32(byte[] byteList) {
        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;
    }
}

Related

  1. hashHC(int i)
  2. hashHsieh(int init, Object... vals)
  3. hashInt(final int v)
  4. hashIntArray(int seed, int[] data, int offset, int len)
  5. hashIt(Object o)
  6. hashJava64(byte[] byteList)
  7. hashJenkins(int init, Object... vals)
  8. hashLong(long id)
  9. hashLong(long l)