Java Hash Code Calculate hashCode(long longVal)

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

Description

Get standard Java hashCode for a long without the extra object creation.

License

Open Source License

Parameter

Parameter Description
longVal value for which to compute hashCode

Return

hashCode

Declaration

public static int hashCode(long longVal) 

Method Source Code

//package com.java2s;

public class Main {
    /**// w w w.  j a va 2s . com
     * Get standard Java hashCode for a long without the extra object creation.
     *
     * <p>Equivalent to (new Long(longVal)).hashCode() in jdk1.6.</p>
     *
     * @param   longVal  value for which to compute hashCode
     * @return  hashCode
     */
    public static int hashCode(long longVal) {
        // combine upper 32 and lower 32 bits via exclusive or
        return (int) (longVal ^ (longVal >>> 32));
    }

    /**
     * Get standard Java hashCode for a float without the extra object creation.
     *
     * <p>Equivalent to (new Float(floatVal)).hashCode() in jdk1.6.</p>
     *
     * @param   floatVal  value for which to compute hashCode
     * @return  hashCode
     */
    public static int hashCode(float floatVal) {
        return Float.floatToIntBits(floatVal);
    }

    /**
     * Get standard Java hashCode for a float without the extra object creation.
     *
     * <p>Equivalent to (new Double(doubleVal)).hashCode() in jdk1.6.</p>
     *
     * @param   doubleVal  value for which to compute hashCode
     * @return  hashCode
     */
    public static int hashCode(double doubleVal) {
        return hashCode(Double.doubleToLongBits(doubleVal));
    }

    /**
     * Get standard Java hashCode for a boolean without the extra object creation.
     *
     * <p>Equivalent to (new Boolean(booleanVal)).hashCode() in jdk1.6.</p>
     *
     * @param   booleanVal  value for which to compute hashCode
     * @return  hashCode
     */
    public static int hashCode(boolean booleanVal) {
        return (booleanVal ? 1231 : 1237);
    }
}

Related

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