Java Murmur Hash murmur(String str, int seed)

Here you can find the source of murmur(String str, int seed)

Description

murmur

License

Open Source License

Declaration

public static int murmur(String str, int seed) 

Method Source Code

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

public class Main {
    public static int murmur(String str, int seed) {
        if (str == null)
            throw new IllegalArgumentException("str cannot be null");
        final int m = 0xc6a4a793;
        final int r = 16;
        int hash = seed ^ (str.length() * m);
        byte b[] = str.getBytes();
        int len = b.length;
        int i = 0;
        while (len >= 4) {
            int l = b[i] + b[i + 1] << 8 + b[i + 2] << 16 + b[i + 3] << 24;
            hash += l;//from  w  w  w.  jav  a  2s.  c o m
            hash *= m;
            hash ^= hash >>> r;
            len -= 4;
            i += 4;
        }
        switch (len) {
        case 3:
            hash += b[i + 2] << 16;
        case 2:
            hash += b[i + 1] << 8;
        case 1:
            hash += b[i];
            hash *= m;
            hash ^= hash >>> r;
        }
        hash *= m;
        hash ^= hash >>> 10;
        hash *= m;
        hash ^= hash >>> 17;
        return hash;
    }
}

Related

  1. murmur2(final byte[] data)
  2. murmur2(int value, int salt)
  3. murmur3fmix(int value)
  4. murmurHash(byte[] data, int offset, int length)