Java Hash Calculate hash(char[] str, int start, int length)

Here you can find the source of hash(char[] str, int start, int length)

Description

hash

License

Open Source License

Declaration

public static final int hash(char[] str, int start, int length) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w  w  w. j  a va 2 s  . c  o  m*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    public static final int hash(char[] str, int start, int length) {
        int h = 0;
        int end = start + length;

        for (int curr = start; curr < end; ++curr)
            h += (h << 3) + str[curr];

        return h;
    }

    public static final int hash(char[] str) {
        return hash(str, 0, str.length);
    }
}

Related

  1. hash(byte x)
  2. hash(byte[] bytes)
  3. hash(byte[] bytes)
  4. hash(byte[] data)
  5. hash(byte[] digest, int number)
  6. hash(double value)
  7. hash(final boolean value)
  8. hash(final int value)
  9. hash(final Object key, final Object value)