Java FNV Hash FNVHash1(byte[] data)

Here you can find the source of FNVHash1(byte[] data)

Description

FNV Hash

License

Apache License

Declaration

public static int FNVHash1(byte[] data) 

Method Source Code

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

public class Main {

    public static int FNVHash1(byte[] data) {
        final int p = 16777619;
        int hash = (int) 2166136261L;
        for (byte b : data)
            hash = (hash ^ b) * p;/*from  www. j  av a  2 s .  c o  m*/
        hash += hash << 13;
        hash ^= hash >> 7;
        hash += hash << 3;
        hash ^= hash >> 17;
        hash += hash << 5;
        return hash;
    }

    public static int FNVHash1(String data) {
        final int p = 16777619;
        int hash = (int) 2166136261L;
        for (int i = 0; i < data.length(); i++)
            hash = (hash ^ data.charAt(i)) * p;
        hash += hash << 13;
        hash ^= hash >> 7;
        hash += hash << 3;
        hash ^= hash >> 17;
        hash += hash << 5;
        return hash;
    }
}

Related

  1. FNVHash(byte[] data)
  2. FNVHash(byte[] data)
  3. fnvHash(int[] p)
  4. FNVHash(String str)
  5. FNVhash64(long val)