Java FNV Hash FNVhash64(long val)

Here you can find the source of FNVhash64(long val)

Description

FN Vhash

License

Open Source License

Declaration

public static long FNVhash64(long val) 

Method Source Code

//package com.java2s;
/*/*from w  w w.ja v  a2  s  . c o  m*/
 * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License. See accompanying LICENSE file.
 */

public class Main {
    public static final long FNV_offset_basis_64 = 0xCBF29CE484222325L;
    public static final long FNV_prime_64 = 1099511628211L;

    public static long FNVhash64(long val) {
        long hashval = FNV_offset_basis_64;

        for (int i = 0; i < 8; i++) {
            long octet = val & 0x00ff;
            val = val >> 8;

            hashval = hashval ^ octet;
            hashval = hashval * FNV_prime_64;
        }
        return Math.abs(hashval);
    }
}

Related

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