rwskit.hash =========== .. py:module:: rwskit.hash .. autoapi-nested-parse:: Hash utilities. Attributes ---------- .. autoapisummary:: rwskit.hash.log rwskit.hash.HashSize Classes ------- .. autoapisummary:: rwskit.hash.ObjectHasher Module Contents --------------- .. py:data:: log .. py:data:: HashSize .. py:class:: ObjectHasher(hash_size: HashSize = 128, signed: bool = False) Hash objects using xxHash. The only requirement is that the object be ``msgpack`` serializable. .. py:property:: hash_size :type: HashSize Get integer size of the returned hash values this hasher produces. .. py:method:: hash(obj: Any, signed: Optional[bool] = None) -> int Hash the object using the hash size specified in the constructor. ``xxHash`` returns an unsigned value, but it can be converted to a signed value if the hash size is less than 128 bits. ..note:: Only values supported by `msgpack `__ can be hashed. ..note:: This can only hash integers up to 64-bits. :param obj: The object to hash :type obj: Any :param signed: Whether to convert the value to a signed integer using :meth:`~rwskit.numeric.to_signed`. :type signed: bool, default = False :returns: An integer representing the hash of the object. :rtype: int :raises OverflowError: If the data contains an integer that is outside the range -2^63 to 2^64-1. .. py:method:: hash_sorted(obj: Any, signed: Optional[bool] = None) -> int Sort a collection using :func:`~rwskit.collections_.recursive_sort` and hash the result. This should provide a more robust hash that should return the same value for collections containing the same data, but in a different order.