Java Hash Code Calculate hashCode(long x)

Here you can find the source of hashCode(long x)

Description

Compute a hash code for the given bitset.

License

Open Source License

Parameter

Parameter Description
x Bitset bitset

Return

Hash code

Declaration

public static int hashCode(long x) 

Method Source Code

//package com.java2s;
/*/*from   w w  w . j  a  va  2s. co  m*/
 This file is part of ELKI:
 Environment for Developing KDD-Applications Supported by Index-Structures
    
 Copyright (C) 2015
 Ludwig-Maximilians-Universit?t M?nchen
 Lehr- und Forschungseinheit f?r Datenbanksysteme
 ELKI Development Team
    
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.
    
 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Compute a hash code for the given bitset.
     * 
     * @param x Bitset bitset
     * @return Hash code
     */
    public static int hashCode(long x) {
        // We use almost the same hash code function as Java BitSet.
        // Optimized for speed only, not protected against collision attacks
        // If you need that, consider using murmur hashing with custom seeds.
        long hash = 0x76543210L ^ x;
        return (int) ((hash >> 32) ^ hash);
    }

    /**
     * Compute a hash code for the given bitset.
     * 
     * @param x Bitset bitset
     * @return Hash code
     */
    public static int hashCode(long[] x) {
        // We use almost the same hash code function as Java BitSet.
        // Optimized for speed only, not protected against collision attacks
        // If you need that, consider using murmur hashing with custom seeds.
        long hash = 0x76543210L;
        for (int i = 0; i < x.length;) {
            hash ^= x[i] * ++i;
        }
        return (int) ((hash >> 32) ^ hash);
    }
}

Related

  1. hashCode(int[][] arrays)
  2. hashCode(Iterable iterable)
  3. hashCode(long a[])
  4. hashCode(long longVal)
  5. hashCode(long value)
  6. hashCode(long[] a, int fromIndex, int toIndex)
  7. hashCode(Object a)
  8. hashCode(Object array)
  9. hashCode(Object o)