Java Hash Code Calculate combineHashCodes(int numA, int numB, int numC)

Here you can find the source of combineHashCodes(int numA, int numB, int numC)

Description

Combines 3 hash codes to make a new one.

License

Open Source License

Declaration

public static int combineHashCodes(int numA, int numB, int numC) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014, 2014 Bruno Medeiros and other Contributors.
 * 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:/*from   ww w.ja  va  2 s.c  o m*/
 *     Bruno Medeiros - initial API and implementation
 *******************************************************************************/

public class Main {
    /** Combines two hash codes to make a new one. */
    public static int combineHashCodes(int hashCode1, int hashCode2) {
        return hashCode1 * 31 + hashCode2;
    }

    /** Combines 3 hash codes to make a new one. */
    public static int combineHashCodes(int numA, int numB, int numC) {
        final int prime = 31;
        int result = 1;
        result = prime * result + numA;
        result = prime * result + numB;
        result = prime * result + numC;
        return result;
    }

    /** Combines multiple hash codes to make a new one. */
    public static int combineHashCodes(int... nums) {
        final int prime = 31;
        int result = 1;
        for (int num : nums) {
            result = prime * result + num;
        }
        return result;
    }

    /** Combines multiple hash codes to make a new one. */
    public static int combineHashCodes(Object... objects) {
        final int prime = 31;
        int result = 1;
        for (Object obj : objects) {
            result = prime * result + getHashCode(obj);
        }
        return result;
    }

    /** Helper to get the hashcode for a member object. */
    public static int getHashCode(Object member) {
        return member == null ? 0 : member.hashCode();
    }
}

Related

  1. combinedHashCode(Object... objects)
  2. combineHashCodes(final int pHashCode_1, final int pHashCode_2)
  3. combineHashCodes(int hashCode1, int hashCode2)
  4. combineHashCodes(int hashCode1, int hashCode2)
  5. combineHashCodesHelper(int hashCode1, int hashCode2)
  6. combineHashes(int hash1, int hash2)
  7. combineHashesBad(int hash1, int hash2)
  8. combineHashesMurmur(int hash2, int hash1)