Java Murmur Hash murmurHash3(int x)

Here you can find the source of murmurHash3(int x)

Description

Avalanches the bits of an integer by applying the finalisation step of MurmurHash3.

License

Apache License

Parameter

Parameter Description
x an integer.

Return

a hash value with good avalanching properties.

Declaration

public final static int murmurHash3(int x) 

Method Source Code

//package com.java2s;
/*       /*from ww  w  .  j a  v  a  2  s .  c  o m*/
 * Copyright (C) 2002-2015 Sebastiano Vigna
 *
 * 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 {
    /** Avalanches the bits of an integer by applying the finalisation step of MurmurHash3.
     * 
     * <p>This method implements the finalisation step of Austin Appleby's <a href="http://code.google.com/p/smhasher/">MurmurHash3</a>.
     * Its purpose is to avalanche the bits of the argument to within 0.25% bias.
     * 
     * @param x an integer.
     * @return a hash value with good avalanching properties.
     */
    public final static int murmurHash3(int x) {
        x ^= x >>> 16;
        x *= 0x85ebca6b;
        x ^= x >>> 13;
        x *= 0xc2b2ae35;
        x ^= x >>> 16;
        return x;
    }

    /** Avalanches the bits of a long integer by applying the finalisation step of MurmurHash3.
     * 
     * <p>This method implements the finalisation step of Austin Appleby's <a href="http://code.google.com/p/smhasher/">MurmurHash3</a>.
     * Its purpose is to avalanche the bits of the argument to within 0.25% bias.
     * 
     * @param x a long integer.
     * @return a hash value with good avalanching properties.
     */
    public final static long murmurHash3(long x) {
        x ^= x >>> 33;
        x *= 0xff51afd7ed558ccdL;
        x ^= x >>> 33;
        x *= 0xc4ceb9fe1a85ec53L;
        x ^= x >>> 33;
        return x;
    }
}

Related

  1. murmur3fmix(int value)
  2. murmurHash(byte[] data, int offset, int length)
  3. murmurHash(int code)
  4. murmurhash2_64(final byte[] data, int length, int seed)
  5. murmurHash3(int k)
  6. murmurHash3(int x)
  7. MurmurHash3_fmix(int k)
  8. murmurhash3x8632(byte[] data, int offset, int len, int seed)
  9. murmurMix(long h)