Java Hash Code Calculate hashCode(Object o)

Here you can find the source of hashCode(Object o)

Description

hash Code

License

Open Source License

Declaration

public static int hashCode(Object o) 

Method Source Code

//package com.java2s;
/*/*from ww  w .  j  a  v a  2 s .  c  o  m*/
 * Copyright (c) 2007, 2011-2013, 2015, 2016 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 *    Christian W. Damus (CEA LIST) - bug 418454
 */

public class Main {
    public static int hashCode(Object o) {
        if (o == null) {
            return 0;
        }

        return o.hashCode();
    }

    /**
     * A collision-free hash code for small sets (<=4) of small, positive integers (<=128)
     *
     * @since 3.2
     */
    public static int hashCode(int... values) {
        int hash = 0;
        for (int i = 0; i < values.length; i++) {
            hash += values[i];
            hash = (hash << 7) - hash;
        }

        return hash;
    }

    public static int hashCode(long num) {
        return (int) (num >> 32) ^ (int) (num & 0xffffffff);
    }
}

Related

  1. hashCode(long[] a, int fromIndex, int toIndex)
  2. hashCode(Object a)
  3. hashCode(Object array)
  4. hashCode(Object o)
  5. hashCode(Object o)
  6. hashCode(Object o1, Object o2)
  7. hashCode(Object obj)
  8. hashCode(Object obj)
  9. hashcode(Object obj)