Java Hash String hash(String data)

Here you can find the source of hash(String data)

Description

ts var hash = 0, i, chr, len; if (data.length === 0) return hash; for (i = 0, len = data.length; i < len; i++) chr = data.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } return hash; }

License

Open Source License

Declaration

public static int hash(String data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w ww. j  a  v a 2s  .c o  m*/
     * {@native ts
     * var hash = 0, i, chr, len;
     * if (data.length === 0) return hash;
     * for (i = 0, len = data.length; i < len; i++) {
     * chr   = data.charCodeAt(i);
     * hash  = ((hash << 5) - hash) + chr;
     * hash |= 0; // Convert to 32bit integer
     * }
     * return hash;
     * }
     */
    public static int hash(String data) {
        /*
        long h = HSTART;
        final long hmult = HMULT;
        final long[] ht = byteTable;
        int dataLength = data.length();
        for (int i = 0; i < dataLength; i++) {
        h = (h * hmult) ^ ht[data.codePointAt(i) & 0xff];
        }
        return h % Constants.END_OF_TIME;
        */
        return data.hashCode();
    }
}

Related

  1. hash(final String s1, final String s2, final String[] a)
  2. hash(String arg)
  3. hash(String data)
  4. hash(String name)
  5. hash(String password)
  6. hash(String s)