Class Hashing


  • public class Hashing
    extends Object
    Utility class for computing bounded hash values.
    Author:
    Rohan Padhye
    • Method Detail

      • knuth

        protected static int knuth​(long x,
                                   int bound)
        Compute knuth's multiplicative hash.

        Source: Donald Knuth's The Art of Computer Programming, Volume 3 (2nd edition), section 6.4, page 516.

        Parameters:
        x - the input value to hash
        bound - the upper bound
        Returns:
        the hash value
      • hash

        public static int hash​(long x,
                               int bound)
        Returns a bounded hashed value with one input.
        Parameters:
        x - the input to hash
        bound - the upper bound
        Returns:
        a pseudo-uniformly distributed value in [0, bound)
      • hash1

        public static int hash1​(long x,
                                long y,
                                int bound)
        Returns a bounded hashed value with two inputs.
        Parameters:
        x - the first input to hash
        y - the second input to hash
        bound - the upper bound
        Returns:
        a pseudo-uniformly distributed value in [0, bound)