Java Hash Calculate hashCharArray(int seed, char... charArray)

Here you can find the source of hashCharArray(int seed, char... charArray)

Description

Calculates hash code for char array.

License

Open Source License

Declaration

public static int hashCharArray(int seed, char... charArray) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final int PRIME = 37;

    /**/*  w w w  . j  a v  a2s  .  c o m*/
     * Calculates hash code for char array.
     */
    public static int hashCharArray(int seed, char... charArray) {
        return hash(seed, charArray);
    }

    /**
     * Calculates hash code for booleans.
     */
    public static int hash(int seed, boolean aBoolean) {
        return PRIME * seed + (aBoolean ? 1231 : 1237);
    }

    /**
     * Calculates hash code for boolean array.
     */
    public static int hash(int seed, boolean[] booleanArray) {
        if (booleanArray == null)
            return 0;
        for (boolean aBoolean : booleanArray)
            seed = hash(seed, aBoolean);
        return seed;
    }

    /**
     * Calculates hash code for byte array.
     */
    public static int hash(int seed, byte[] byteArray) {
        if (byteArray == null)
            return 0;
        for (byte aByte : byteArray)
            seed = hash(seed, aByte);
        return seed;
    }

    /**
     * Calculates hash code for chars.
     */
    public static int hash(int seed, char aChar) {
        return PRIME * seed + aChar;
    }

    /**
     * Calculates hash code for char array.
     */
    public static int hash(int seed, char[] charArray) {
        if (charArray == null)
            return 0;
        for (char aChar : charArray)
            seed = hash(seed, aChar);
        return seed;
    }

    /**
     * Calculates hash code for doubles.
     */
    public static int hash(int seed, double aDouble) {
        return hash(seed, Double.doubleToLongBits(aDouble));
    }

    /**
     * Calculates hash code for double array.
     */
    public static int hash(int seed, double[] doubleArray) {
        if (doubleArray == null)
            return 0;
        for (double aDouble : doubleArray)
            seed = hash(seed, aDouble);
        return seed;
    }

    /**
     * Calculates hash code for floats.
     */
    public static int hash(int seed, float aFloat) {
        return hash(seed, Float.floatToIntBits(aFloat));
    }

    /**
     * Calculates hash code for float array.
     */
    public static int hash(int seed, float[] floatArray) {
        if (floatArray == null)
            return 0;
        for (float aFloat : floatArray)
            seed = hash(seed, aFloat);
        return seed;
    }

    /**
     * Calculates hash code for ints.
     */
    public static int hash(int seed, int anInt) {
        return PRIME * seed + anInt;
    }

    /**
     * Calculates hash code for int array.
     */
    public static int hash(int seed, int[] intArray) {
        if (intArray == null)
            return 0;
        for (int anInt : intArray)
            seed = hash(seed, anInt);
        return seed;
    }

    /**
     * Calculates hash code for longs.
     */
    public static int hash(int seed, long aLong) {
        return PRIME * seed + (int) (aLong ^ aLong >>> 32);
    }

    /**
     * Calculates hash code for long array.
     */
    public static int hash(int seed, long[] longArray) {
        if (longArray == null)
            return 0;
        for (long aLong : longArray)
            seed = hash(seed, aLong);
        return seed;
    }

    /**
     * Calculates hash code for Objects. Object is a possibly-null object field, and possibly an array.
     * <p>
     * If <code>aObject</code> is an array, then each element may be a primitive
     * or a possibly-null object.
     */
    public static int hash(int seed, Object aObject) {
        int result = seed;
        if (aObject == null)
            result = hash(result, 0);
        else if (aObject.getClass().isArray() == false)
            result = hash(result, aObject.hashCode());
        else {
            Object[] objects = (Object[]) aObject;
            int length = objects.length;
            for (int idx = 0; idx < length; ++idx)
                result = hash(result, objects[idx]);
        }
        return result;
    }

    /**
     * Calculates hash code for short array.
     */
    public static int hash(int seed, short[] shortArray) {
        if (shortArray == null)
            return 0;
        for (short aShort : shortArray)
            seed = hash(seed, aShort);
        return seed;
    }
}

Related

  1. hashArray(Object[] objs)
  2. hashBerkeleyDB64(byte[] str)
  3. hashByteArray(byte[] array, int startInclusive, int endExclusive)
  4. hashBytes(int seed, byte[] data, int offset, int len)
  5. hashCapacityForSize(final int size)
  6. hashClassName(Class clazz)
  7. hashCombine(int seed, int hash)
  8. hashCombine(int seed, int hash)
  9. hashDisp(long hash)