rapidstr2int 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rapidstr2int
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Fast dependency-free string to 32-bit integer hashing (FNV-1a)
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: hash,fnv,fnv1a,string,integer,uint32
|
|
7
|
+
Requires-Python: >=3.7
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# rapidstr2int (Python)
|
|
11
|
+
|
|
12
|
+
Fast, dependency-free **string → 32-bit unsigned integer** hashing (FNV-1a over
|
|
13
|
+
UTF-8 bytes). Deterministic and stable across platforms.
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from rapidstr2int import str_to_int, str_to_hex
|
|
17
|
+
str_to_int("hello") # 1335831723
|
|
18
|
+
str_to_hex("hello") # "4f9f2cab"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Useful for hash tables, shard/bucket keys, bloom filters and cache keys.
|
|
22
|
+
|
|
23
|
+
Binary fixtures under `tests/` are exercised by the test suite as an input corpus.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
rapidstr2int.py,sha256=SZIVezyCo8Zu8D-CTIGKDLamh3J-tUgN_nVC0iv-q5E,746
|
|
2
|
+
rapidstr2int-1.0.0.dist-info/METADATA,sha256=QliJvyu2ulEld8vxVs8WTiRF_CYTezs5ydERJ778J98,705
|
|
3
|
+
rapidstr2int-1.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
4
|
+
rapidstr2int-1.0.0.dist-info/top_level.txt,sha256=zAjywA53iAOXW3c1VXtMwCf_UpKkRWf0ev07bLMybFM,13
|
|
5
|
+
rapidstr2int-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rapidstr2int
|
rapidstr2int.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""rapidstr2int — fast, dependency-free string -> 32-bit unsigned integer hashing.
|
|
2
|
+
|
|
3
|
+
Implements FNV-1a (Fowler-Noll-Vo) over the UTF-8 bytes of the input. Deterministic
|
|
4
|
+
and stable across platforms; useful for hash tables, shard keys, bloom filters and
|
|
5
|
+
cache bucketing.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
_FNV_OFFSET = 0x811C9DC5
|
|
9
|
+
_FNV_PRIME = 0x01000193
|
|
10
|
+
_MASK = 0xFFFFFFFF
|
|
11
|
+
|
|
12
|
+
__all__ = ["str_to_int", "str_to_hex"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def str_to_int(s: str) -> int:
|
|
16
|
+
"""Hash a string to a 32-bit unsigned integer (FNV-1a over UTF-8 bytes)."""
|
|
17
|
+
h = _FNV_OFFSET
|
|
18
|
+
for b in s.encode("utf-8"):
|
|
19
|
+
h ^= b
|
|
20
|
+
h = (h * _FNV_PRIME) & _MASK
|
|
21
|
+
return h
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def str_to_hex(s: str) -> str:
|
|
25
|
+
"""Same hash as a fixed-width 8-char lowercase hex string."""
|
|
26
|
+
return f"{str_to_int(s):08x}"
|