def hash_int(x, p):
    """
    Compute the hash of an integer. The hashing method is Knuth multiplicative hash.

    Parameters
    ----------
    x : int
        element
    p : int
        Prime number used for shifting. Recommended p is 53 or 31.

    Returns
    -------
    hash : hash value of x
    """
    if x < 0:
        x *= -1
    if 0 <= p <= 32:
        return (x * 2654435769) >> (32 - p)
    else:
        raise ValueError("The prime number p should be between 0 and 32.")