Java Hash Code Calculate hashCode(char[] array, int start, int end)

Here you can find the source of hashCode(char[] array, int start, int end)

Description

Returns hash of chars in range start (inclusive) to end (inclusive)

License

Open Source License

Declaration

public static int hashCode(char[] array, int start, int end) 

Method Source Code

//package com.java2s;
/**/*from   w ww .j a va2s  . c  o  m*/
 * @(#)ArrayUtil.java, 2013-2-24.
 * 
 * Copyright 2013 Netease, Inc. All rights reserved.
 * NETEASE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {
    /**
     * Returns hash of chars in range start (inclusive) to end (inclusive)
     */
    public static int hashCode(char[] array, int start, int end) {
        int code = 0;
        for (int i = end - 1; i >= start; i--) {
            code = code * 31 + array[i];
        }
        return code;
    }

    /**
     * Returns hash of chars in range start (inclusive) to end (inclusive)
     */
    public static int hashCode(byte[] array, int start, int end) {
        int code = 0;
        for (int i = end - 1; i >= start; i--) {
            code = code * 31 + array[i];
        }
        return code;
    }
}

Related

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