Java Array Deep Hash Code deepHashCode(byte[] array)

Here you can find the source of deepHashCode(byte[] array)

Description

Computes a hashcode based on the contents of a one-dimensional byte array rather than its identity.

License

Open Source License

Parameter

Parameter Description
array the array to compute the hashcode of

Return

the hashcode

Declaration

public static int deepHashCode(byte[] array) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  www . j  a  v a  2 s.  c om*/
     * Computes a hashcode based on the contents of a one-dimensional byte array
     * rather than its identity.
     *
     * @param array the array to compute the hashcode of
     * @return the hashcode
     */
    public static int deepHashCode(byte[] array) {
        int result = 1;
        for (int i = 0; i < array.length; i++) {
            result = 31 * result + array[i];
        }
        return result;
    }

    /**
     * Computes a hashcode based on the contents of a two-dimensional byte array
     * rather than its identity.
     *
     * @param array the array to compute the hashcode of
     * @return the hashcode
     */
    public static int deepHashCode(byte[][] array) {
        int result = 1;
        for (int i = 0; i < array.length; i++) {
            result = 31 * result + deepHashCode(array[i]);
        }
        return result;
    }

    /**
     * Computes a hashcode based on the contents of a three-dimensional byte
     * array rather than its identity.
     *
     * @param array the array to compute the hashcode of
     * @return the hashcode
     */
    public static int deepHashCode(byte[][][] array) {
        int result = 1;
        for (int i = 0; i < array.length; i++) {
            result = 31 * result + deepHashCode(array[i]);
        }
        return result;
    }
}

Related

  1. deepHashCode(final Iterable stream)
  2. deepHashCode(Object a[])
  3. deepHashCode(Object a[])