Java Hash Code Calculate hashCode(byte[] bytes, int size)

Here you can find the source of hashCode(byte[] bytes, int size)

Description

A function that calculates hash code of a byte array based on its contents but using the given size parameter as deliminator for the content.

License

Apache License

Declaration

public static int hashCode(byte[] bytes, int size) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  w  w  .  j  a v a2s  .  c  om*/
     * A function that calculates hash code of a byte array based on its
     * contents but using the given size parameter as deliminator for the
     * content.
     */
    public static int hashCode(byte[] bytes, int size) {
        int contentLimit = size;
        if (size > bytes.length)
            contentLimit = bytes.length;

        int hashCode = 1;
        for (int i = 0; i < contentLimit; i++)
            hashCode = 31 * hashCode + bytes[i];

        return hashCode;
    }
}

Related

  1. hashCode(byte a[])
  2. hashCode(byte a[], int offset, int length)
  3. hashCode(byte[] array)
  4. hashCode(byte[] array, int size)
  5. hashCode(byte[] bytes, int offset, int length)
  6. hashCode(byte[] data, int offset, int len, int seed)
  7. hashCode(char[] array)
  8. hashCode(char[] array, int start, int end)
  9. hashCode(char[] array, int start, int end)