Java Hash Calculate hashByteArray(byte[] array, int startInclusive, int endExclusive)

Here you can find the source of hashByteArray(byte[] array, int startInclusive, int endExclusive)

Description

A utility to allow hashing of a portion of an array without having to copy it.

License

Open Source License

Parameter

Parameter Description
array a parameter
startInclusive a parameter
endExclusive a parameter

Return

hash byte

Declaration

public static byte hashByteArray(byte[] array, int startInclusive, int endExclusive) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w w w.j a  v a 2s . c  om
     * A utility to allow hashing of a portion of an array without having to copy it.
     * @param array
     * @param startInclusive
     * @param endExclusive
     * @return hash byte
     */
    public static byte hashByteArray(byte[] array, int startInclusive, int endExclusive) {
        if (array == null) {
            return 0;
        }

        int range = endExclusive - startInclusive;
        if (range < 0) {
            throw new IllegalArgumentException(startInclusive + " > " + endExclusive);
        }

        int result = 1;
        for (int i = startInclusive; i < endExclusive; i++) {
            result = 31 * result + array[i];
        }

        return (byte) result;
    }
}

Related

  1. hasHangulJongSung(char ch)
  2. hashArray(int h, Object[] a)
  3. hashArray(Object[] array)
  4. hashArray(Object[] objs)
  5. hashBerkeleyDB64(byte[] str)
  6. hashBytes(int seed, byte[] data, int offset, int len)
  7. hashCapacityForSize(final int size)
  8. hashCharArray(int seed, char... charArray)
  9. hashClassName(Class clazz)