Java Hash Calculate hash(int seed, int toHash)

Here you can find the source of hash(int seed, int toHash)

Description

Returns a new hash code depending on the seed and toHash.

License

Open Source License

Parameter

Parameter Description
seed The seed to be used.
toHash The integer value to be hashed.

Declaration

public static int hash(int seed, int toHash) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * This file is part of Tmetrics./*from  w  w w  . j a v a  2 s.c  o m*/
 *
 * Tmetrics is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tmetrics is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tmetrics. If not, see <http://www.gnu.org/licenses/>.
 *******************************************************************************/

public class Main {
    private static final int PRIME_NUMBER = (2 << 16) - 1;

    /**
     * Returns a new hash code depending on the seed and toHash.
     * @param seed The seed to be used.
     * @param toHash The integer value to be hashed.
     * @return
     */
    public static int hash(int seed, int toHash) {
        return first(seed) + toHash;
    }

    /**
     * Generates a start hash code.
     * @param seed The seed used for the start.
     * @return A start hash code.
     */
    private static int first(int seed) {
        return seed * PRIME_NUMBER;
    }
}

Related

  1. hash(int key)
  2. hash(int n)
  3. hash(int p_188208_0_)
  4. hash(int seed, boolean value)
  5. hash(int seed, int i)
  6. hash(int seed, int val)
  7. hash(int state1, int state2, int numStates1)
  8. hash(int val)
  9. hash(int value)