Java Abs absHash(Object obj)

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

Description

abs Hash

License

Apache License

Declaration

public static int absHash(Object obj) 

Method Source Code

//package com.java2s;
/*/*  ww  w  . j  a  va 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 {
    public static int absHash(Object obj) {
        return Math.abs(hash(obj));
    }

    /**
     * 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. absClamp(double value, double bounds)
  2. absDegrees(double degrees)
  3. absDelta(double a, double b)
  4. absDelta(float f1, float f2)
  5. absDiff(long x, long y)
  6. absNeg(final int a)
  7. absNeg(long a)
  8. absNegativeZeros(float f)
  9. Absolute(int a)