Java Hash Calculate hashHsieh(int init, Object... vals)

Here you can find the source of hashHsieh(int init, Object... vals)

Description

hash Hsieh

License

Open Source License

Declaration

public static int hashHsieh(int init, Object... vals) 

Method Source Code

//package com.java2s;
/*// w w  w.j  ava  2 s.  c  o  m
 * Copyright (C) 2012-2013 University of Freiburg
 *
 * This file is part of SMTInterpol.
 *
 * SMTInterpol is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SMTInterpol is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with SMTInterpol.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static int hashHsieh(int init, Object... vals) {
        if (vals == null || vals.length == 0) {
            return init;
        }
        int hash = init;
        /* Main loop */
        for (final Object o : vals) {
            final int thingHash = o.hashCode();
            hash += (thingHash >>> 16);
            final int tmp = ((thingHash & 0xffff) << 11) ^ hash;
            hash = (hash << 16) ^ tmp;
            hash += (hash >>> 11);
        }

        /* Force "avalanching" of final 127 bits */
        hash ^= hash << 3;
        hash += hash >>> 5;
        hash ^= hash << 4;
        hash += hash >>> 17;
        hash ^= hash << 25;
        hash += hash >>> 6;
        return hash;
    }

    public static int hashHsieh(int init, Object val) {
        int hash = init;
        final int thingHash = val.hashCode();
        hash += (thingHash >>> 16);
        final int tmp = ((thingHash & 0xffff) << 11) ^ hash;
        hash = (hash << 16) ^ tmp;
        hash += (hash >>> 11);
        /* Force "avalanching" of final 127 bits */
        hash ^= hash << 3;
        hash += hash >>> 5;
        hash ^= hash << 4;
        hash += hash >>> 17;
        hash ^= hash << 25;
        hash += hash >>> 6;
        return hash;
    }
}

Related

  1. hashFloatBits(long hash, float f)
  2. hashFNV32(int val)
  3. hashFNV64(byte[] bytes)
  4. hashForEqual(Class clazz)
  5. hashHC(int i)
  6. hashInt(final int v)
  7. hashIntArray(int seed, int[] data, int offset, int len)
  8. hashIt(Object o)
  9. hashJava32(byte[] byteList)