Java Hash Calculate hash(Object obj)

Here you can find the source of hash(Object obj)

Description

Same hash function as HashMap#newHash method.

License

Apache License

Declaration

public static int hash(Object obj) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w . jav a  2  s.co m*/
 * Copyright 2004-2009 the original author or authors.
 *
 * 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.
 */

public class Main {
    /**
     * Same hash function as <code>HashMap#newHash</code> method.
     */
    public static int hash(Object obj) {
        int h = obj.hashCode();
        // This function ensures that hashCodes that differ only by
        // constant multiples at each bit position have a bounded
        // number of collisions (approximately 8 at default load factor).
        h ^= (h >>> 20) ^ (h >>> 12);
        return h ^ (h >>> 7) ^ (h >>> 4);
    }
}

Related

  1. hash(long mover, long enemy)
  2. hash(Object a, Object b)
  3. hash(Object key, int limit)
  4. hash(Object o)
  5. hash(Object obj)
  6. hash(Object obj)
  7. hash(Object object)
  8. hash(Object v)
  9. hash(Object value)