Java Hash Calculate hash(int h, Object o)

Here you can find the source of hash(int h, Object o)

Description

Computes a hash code from an existing hash code and an object (which may be null).

License

Apache License

Declaration

public static int hash(int h, Object o) 

Method Source Code

//package com.java2s;
/*/*from   w  ww  .  j a v  a  2  s  .  co m*/
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you 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 {
    /**
     * Combines two integers into a hash code.
     */
    public static int hash(int i, int j) {
        return (i << 4) ^ j;
    }

    /**
     * Computes a hash code from an existing hash code and an object (which may
     * be null).
     */
    public static int hash(int h, Object o) {
        int k = (o == null) ? 0 : o.hashCode();
        return ((h << 4) | h) ^ k;
    }

    /** Computes the hash code of a {@code double} value. Equivalent to
     * {@link Double}{@code .hashCode(double)}, but that method was only
     * introduced in JDK 1.8.
     *
     * @param v Value
     * @return Hash code
     */
    public static int hashCode(double v) {
        long bits = Double.doubleToLongBits(v);
        return (int) (bits ^ (bits >>> 32));
    }
}

Related

  1. hash(int aSeed, Object[] aArray)
  2. hash(int base, boolean field)
  3. hash(int h)
  4. hash(int h)
  5. hash(int h, boolean v)
  6. hash(int hash, boolean item)
  7. hash(int i, int j)
  8. hash(int k)
  9. hash(int k)