Java Hash Calculate hashFNV64(byte[] bytes)

Here you can find the source of hashFNV64(byte[] bytes)

Description

FNV hashes are designed to be fast while maintaining a low collision rate.

License

Open Source License

Parameter

Parameter Description
str Value to be hashed

Return

hex string representing the hash code

Declaration

public static long hashFNV64(byte[] bytes) 

Method Source Code

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

public class Main {
    /**//from www .j  av a 2 s  .c  om
     *  FNV hashes are designed to be fast while maintaining a low collision rate. The FNV speed allows one to quickly hash lots of data while maintaining a reasonable collision rate. The high dispersion of the FNV hashes makes them well suited for hashing nearly identical strings such as URLs, hostnames, filenames, text, IP addresses, etc.<br><br>
     *  The IETF has an informational draft on The FNV Non-Cryptographic Hash Algorithm: <code>http://tools.ietf.org/html/draft-eastlake-fnv-03</code> 
     * @param str Value to be hashed
     * @return hex string representing the hash code
     */
    public static long hashFNV64(String str) {
        return hashFNV64(str.getBytes());
    }

    /**
     *  FNV hashes are designed to be fast while maintaining a low collision rate. The FNV speed allows one to quickly hash lots of data while maintaining a reasonable collision rate. The high dispersion of the FNV hashes makes them well suited for hashing nearly identical strings such as URLs, hostnames, filenames, text, IP addresses, etc.<br><br>
     *  The IETF has an informational draft on The FNV Non-Cryptographic Hash Algorithm: <code>http://tools.ietf.org/html/draft-eastlake-fnv-03</code> 
     * @param str Value to be hashed
     * @return hex string representing the hash code
     */
    public static long hashFNV64(byte[] bytes) {
        long nHashVal = 0xcbf29ce484222325L;
        long nMagicPrime = 0x00000100000001b3L;

        for (int i = 0; i < bytes.length; i++) {
            nHashVal ^= bytes[i];
            nHashVal *= nMagicPrime;
        }

        return nHashVal;
    }
}

Related

  1. hashDouble(double val)
  2. hashEqules(Object source, Object obj)
  3. hashFloat(float value)
  4. hashFloatBits(long hash, float f)
  5. hashFNV32(int val)
  6. hashForEqual(Class clazz)
  7. hashHC(int i)
  8. hashHsieh(int init, Object... vals)
  9. hashInt(final int v)