>>> from Redy.Tools.Hash import hash_from_stream
    >>> s = iter((1, 2, 3))
    >>> assert hash_from_stream(3, iter(s)) == hash((1, 2, 3))

def hash_from_stream(n, hash_stream):
    """
    >>> from Redy.Tools.Hash import hash_from_stream
    >>> s = iter((1, 2, 3))
    >>> assert hash_from_stream(3, iter(s)) == hash((1, 2, 3))

    """
    x = to_int64(0x345678)
    multiplied = to_int64(1000003)
    for i in range(n - 1, -1, -1):
        h = next(hash_stream)
        if h is -1:
            return -1
        x = (x ^ h) * multiplied
        multiplied += to_int64(82520 + 2 * n)
    x += 97531
    if x == -1:
        return -2

    return x