in pyignite/utils.py [0:0]
def __hashcode_fallback(data: Union[str, bytes, bytearray, memoryview]) -> int:
if data is None:
return 0
if isinstance(data, str):
"""
For strings we iterate over code point which are of the int type
and can take up to 4 bytes and can only be positive.
"""
result = 0
for char in data:
try:
char_val = ord(char)
result = int_overflow(31 * result + char_val)
except TypeError:
pass
else:
"""
For byte array we iterate over bytes which only take 1 byte. But
according to protocol, bytes during hashing should be treated as signed
integer numbers 8 bits long. On other hand elements in Python's `bytes`
are unsigned. For this reason we use ctypes.c_byte() to make them
signed.
"""
result = 1
for byte in data:
byte = ctypes.c_byte(byte).value
result = int_overflow(31 * result + byte)
return result