Java Hash Calculate hashArray(int h, Object[] a)

Here you can find the source of hashArray(int h, Object[] a)

Description

Computes a hash code from an existing hash code and an array of objects (which may be null).

License

Open Source License

Declaration

public static int hashArray(int h, Object[] a) 

Method Source Code

//package com.java2s;
/*/*from   w w  w .j ava  2  s . c o m*/
 // This software is subject to the terms of the Eclipse Public License v1.0
 // Agreement, available at the following URL:
 // http://www.eclipse.org/legal/epl-v10.html.
 // You must accept the terms of that agreement to use this software.
 //
 // Copyright (C) 2001-2005 Julian Hyde
 // Copyright (C) 2005-2012 Pentaho and others
 // All Rights Reserved.
 */

public class Main {
    /**
     * Computes a hash code from an existing hash code and an array of objects
     * (which may be null).
     */
    public static int hashArray(int h, Object[] a) {
        // The hashcode for a null array and an empty array should be different
        // than h, so use magic numbers.
        if (a == null) {
            return hash(h, 19690429);
        }
        if (a.length == 0) {
            return hash(h, 19690721);
        }
        for (Object anA : a) {
            h = hash(h, anA);
        }
        return h;
    }

    /**
     * Combines two integers into a hash code.
     */
    public static int hash(int i, int j) {
        return (i << 4) ^ j;
    }

    /**
     * Computes a hash code from an existing hash code and an object (which
     * may be null).
     */
    public static int hash(int h, Object o) {
        int k = (o == null) ? 0 : o.hashCode();
        return ((h << 4) | h) ^ k;
    }
}

Related

  1. hash64To32(long lg)
  2. hash64to32(long v)
  3. hashAdd(final int left, final int right)
  4. hashAll(Object[] array)
  5. hasHangulJongSung(char ch)
  6. hashArray(Object[] array)
  7. hashArray(Object[] objs)
  8. hashBerkeleyDB64(byte[] str)
  9. hashByteArray(byte[] array, int startInclusive, int endExclusive)