diff --git a/.pylintrc-local.yml b/.pylintrc-local.yml index 8cb3aa72..e045e85c 100644 --- a/.pylintrc-local.yml +++ b/.pylintrc-local.yml @@ -4,3 +4,4 @@ - arg: ignored-modules val: - matplotlib + - siphash24 diff --git a/pyproject.toml b/pyproject.toml index adf94b1d..2768d5a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ classifiers = [ dependencies = [ "platformdirs>=2.2", "typing-extensions>=4; python_version<'3.11'", + "siphash24", ] [project.optional-dependencies] diff --git a/pytools/persistent_dict.py b/pytools/persistent_dict.py index c35476c7..a4756d65 100644 --- a/pytools/persistent_dict.py +++ b/pytools/persistent_dict.py @@ -30,7 +30,6 @@ """ -import hashlib import logging import os import pickle @@ -52,6 +51,8 @@ cast, ) +from siphash24 import siphash13 + if TYPE_CHECKING: from _typeshed import ReadableBuffer @@ -160,7 +161,7 @@ class KeyBuilder: # this exists so that we can (conceivably) switch algorithms at some point # down the road - new_hash: Callable[..., Hash] = hashlib.sha256 + new_hash: Callable[..., Hash] = siphash13 def rec(self, key_hash: Hash, key: Any) -> Hash: """ @@ -301,7 +302,8 @@ def update_for_frozenset(self, key_hash: Hash, key: FrozenSet[Any]) -> None: unordered_hash( key_hash, - (self.rec(self.new_hash(), key_i).digest() for key_i in key)) + (self.rec(self.new_hash(), key_i).digest() for key_i in key), + hash_constructor=self.new_hash) update_for_FrozenOrderedSet = update_for_frozenset # noqa: N815 @@ -351,7 +353,8 @@ def update_for_frozendict(self, key_hash: Hash, key: Mapping[Any, Any]) -> None: unordered_hash( key_hash, - (self.rec(self.new_hash(), (k, v)).digest() for k, v in key.items())) + (self.rec(self.new_hash(), (k, v)).digest() for k, v in key.items()), + hash_constructor=self.new_hash) update_for_immutabledict = update_for_frozendict update_for_constantdict = update_for_frozendict