move to xxh3 hashing algorithm

+ port: search
This commit is contained in:
cwilvx
2024-07-03 11:12:06 +03:00
parent ff7343a7be
commit a5634f267f
16 changed files with 322 additions and 182 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
import locale
from typing import TypeVar
from typing import Iterable, TypeVar
T = TypeVar("T")
@@ -16,5 +16,5 @@ def format_number(number: float) -> str:
def flatten(list_: list[list[T]]) -> list[T]:
def flatten(list_: Iterable[list[T]]) -> list[T]:
return [item for sublist in list_ for item in sublist]
+8 -6
View File
@@ -1,4 +1,5 @@
import hashlib
import xxhash
from unidecode import unidecode
@@ -32,11 +33,12 @@ def create_hash(*args: str, decode=False, limit=10) -> str:
str_ = unidecode(str_)
str_ = str_.encode("utf-8")
str_ = hashlib.sha1(str_).hexdigest()
return xxhash.xxh3_64(str_).hexdigest()
# str_ = hashlib.sha1(str_).hexdigest()
# INFO: Return first 5 + last 5 characters
return (
str_[: limit // 2] + str_[-limit // 2 :]
if limit % 2 == 0
else str_[: limit // 2] + str_[-limit // 2 - 1 :]
)
# return (
# str_[: limit // 2] + str_[-limit // 2 :]
# if limit % 2 == 0
# else str_[: limit // 2] + str_[-limit // 2 - 1 :]
# )