Class Hash


  • public class Hash
    extends java.lang.Object
    A hash function utility class.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long hash64​(long x)
      Calculate a 64-bit hash value from a value.
      static long hash64​(long x, long seed)
      Calculate a 64-bit hash value from a value, using a seed.
      static int reduce​(int hash, int n)
      Shrink the hash to a value 0..n.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • hash64

        public static long hash64​(long x,
                                  long seed)
        Calculate a 64-bit hash value from a value, using a seed. The current algorithm used the finalizer of the MurmurHash3 hash function, but callers shouldn't rely on that.
        Parameters:
        x - the value
        seed - the seed
        Returns:
        the hash value
      • hash64

        public static long hash64​(long x)
        Calculate a 64-bit hash value from a value. The input is a 64-bit value and the output is a 64-bit values. Two different inputs are never mapped to the same output. The operation is reversible.
        Parameters:
        x - the value
        Returns:
        the hash value
      • reduce

        public static int reduce​(int hash,
                                 int n)
        Shrink the hash to a value 0..n. Kind of like modulo, but using multiplication and shift, which are faster to compute.
        Parameters:
        hash - the hash
        n - the maximum of the result
        Returns:
        the reduced value