Java Hash Code Calculate combineHashCodes(final int pHashCode_1, final int pHashCode_2)

Here you can find the source of combineHashCodes(final int pHashCode_1, final int pHashCode_2)

Description

Combine two hash codes to obtain a third one representing both.

License

LGPL

Parameter

Parameter Description
pHashCode_1 The first hash code.
pHashCode_2 The second hash code.

Return

A hash code representing both hash codes and their sequence.

Declaration

public static final int combineHashCodes(final int pHashCode_1, final int pHashCode_2) 

Method Source Code

//package com.java2s;
/*/* ww  w  .j  av a  2  s . co m*/
 * Copyright (c) 2006 Thomas Weise
 * Software Foundation Classes
 * http://sourceforge.net/projects/java-sfc
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-11-22
 * Creator          : Thomas Weise
 * Original Filename: org.sfc.utils.HashUtils.java
 * Last modification: 2006-11-22
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to theFree Software
 *                    Foundation, Inc. 51 Franklin Street, Fifth Floor,
 *                    Boston, MA 02110-1301, USA or download the license
 *                    under http://www.gnu.org/licenses/lgpl.html or
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */

public class Main {
    /**
     * Combine two hash codes to obtain a third one representing both.
     * 
     * @param pHashCode_1
     *          The first hash code.
     * @param pHashCode_2
     *          The second hash code.
     * @return A hash code representing both hash codes <strong>and</strong>
     *         their sequence.
     */
    public static final int combineHashCodes(final int pHashCode_1, final int pHashCode_2) {
        return intHashCode(intHashCode(pHashCode_1) - pHashCode_2);
    }

    /**
     * Create a hash code of an integer value.
     * 
     * @param value
     *          The integer value to create a hash code off.
     * @return The hash code of the integer value.
     */
    public static final int intHashCode(final int value) {
        int v;

        v = (value + 0xad4497fc);
        v += ~(v << 9);
        v ^= (v >>> 14);
        v += (v << 4);
        v ^= (v >>> 10);

        return v;
    }
}

Related

  1. combinedHashCode(Object... objects)
  2. combineHashCodes(int hashCode1, int hashCode2)
  3. combineHashCodes(int hashCode1, int hashCode2)
  4. combineHashCodes(int numA, int numB, int numC)
  5. combineHashCodesHelper(int hashCode1, int hashCode2)