picop.cyhash#
Fast buffer and pointer hashing helpers (CPython 3.8+).
- picop.cyhash.hash_buffer(data, start=0, end=-1)#
Return the CPython hash of
data’s bytes, or of thedata[start:end]range.Notes
Mixed Tier A parity: 0.36x (array.array(‘B’) n=6), 0.82x (bytearray n=2048), 0.48x (bytearray n=64), 0.52x (bytes n=2048 range 64:128), 1.19x (bytes n=8 (cached)), 2.25x (memoryview n=256 (cached)), 0.45x (memoryview n=256 range 64:128); re-hashes the buffer every call, while
bytes/memoryviewcache theirs.Accepts any simple buffer object (
bytes,bytearray,memoryviewand exporters such as arrays);stris not a buffer and raisesTypeError.bytearrayandarray.arrayhave no__hash__, and hashing a writablememoryviewraisesValueError, so this replaceshash(bytes(data))without the copy. Once abytesor read-onlymemoryviewhas been hashed the builtin is cheaper: the value is cached on the object.startdefaults to 0 and any negativeendmeans the end of the buffer;start/endout of range orend < startraiseValueError. The value matcheshash(bytes(data[start:end]))exactly (SipHash over the same bytes).