Java Hash Calculate hashIntArray(int seed, int[] data, int offset, int len)

Here you can find the source of hashIntArray(int seed, int[] data, int offset, int len)

Description

hash Int Array

License

Open Source License

Declaration

public static int hashIntArray(int seed, int[] data, int offset, int len) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 BowenCai.//from   ww w .j av a  2  s . c o m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     BowenCai - initial API and implementation
 ******************************************************************************/

public class Main {
    public static int hashIntArray(int seed, int[] data, int offset, int len) {
        int h1 = seed;

        int off = offset;
        int end = offset + len;

        // body
        while (off < end) {
            int k1 = data[off++];

            k1 *= 0xcc9e2d51;
            k1 = Integer.rotateLeft(k1, 15);
            k1 *= 0x1b873593;

            h1 ^= k1;
            h1 = Integer.rotateLeft(h1, 13);
            h1 = h1 * 5 + 0xe6546b64;
        }

        // tail (always empty, as body is always 32-bit chunks)

        // finalization

        h1 ^= len * (Integer.SIZE / Byte.SIZE);

        // finalization mix force all bits of a hash block to avalanche
        h1 ^= h1 >>> 16;
        h1 *= 0x85ebca6b;
        h1 ^= h1 >>> 13;
        h1 *= 0xc2b2ae35;
        h1 ^= h1 >>> 16;

        return h1;
    }
}

Related

  1. hashFNV64(byte[] bytes)
  2. hashForEqual(Class clazz)
  3. hashHC(int i)
  4. hashHsieh(int init, Object... vals)
  5. hashInt(final int v)
  6. hashIt(Object o)
  7. hashJava32(byte[] byteList)
  8. hashJava64(byte[] byteList)
  9. hashJenkins(int init, Object... vals)