Class Hash


  • public class Hash
    extends Object
    A hash function utility class.
    • 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