rwskit.hash

Hash utilities.

Attributes

log

HashSize

Classes

ObjectHasher

Hash objects using xxHash.

Module Contents

rwskit.hash.log[source]
rwskit.hash.HashSize[source]
class rwskit.hash.ObjectHasher(hash_size: HashSize = 128, signed: bool = False)[source]

Hash objects using xxHash.

The only requirement is that the object be msgpack serializable.

property hash_size: HashSize[source]

Get integer size of the returned hash values this hasher produces.

hash(obj: Any, signed: bool | None = None) int[source]

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.

Parameters:
  • obj (Any) – The object to hash

  • signed (bool, default = False) – Whether to convert the value to a signed integer using to_signed().

Returns:

An integer representing the hash of the object.

Return type:

int

Raises:

OverflowError – If the data contains an integer that is outside the range -2^63 to 2^64-1.

hash_sorted(obj: Any, signed: bool | None = None) int[source]

Sort a collection using 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.