Skip to content
Snippets Groups Projects
Commit 877bc5c5 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Use (hopefully) faster hash functions in KeyBuilder for int, float

parent 48c92041
No related branches found
No related tags found
No related merge requests found
......@@ -263,14 +263,21 @@ class KeyBuilder:
@staticmethod
def update_for_int(key_hash, key):
key_hash.update(str(key).encode("utf8"))
sz = 8
while True:
try:
key_hash.update(key.to_bytes(sz, byteorder="little", signed=True))
return
except OverflowError:
sz *= 2
update_for_long = update_for_int
update_for_bool = update_for_int
@staticmethod
def update_for_bool(key_hash, key):
key_hash.update(str(key).encode("utf8"))
@staticmethod
def update_for_float(key_hash, key):
key_hash.update(repr(key).encode("utf8"))
key_hash.update(key.hex().encode("utf8"))
@staticmethod
def update_for_str(key_hash, key):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment