rapidstr2int 1.0.0__tar.gz

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,2 @@
1
+ # Ensure the binary test corpus ships in the source distribution (sdist).
2
+ recursive-include tests *
@@ -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,14 @@
1
+ # rapidstr2int (Python)
2
+
3
+ Fast, dependency-free **string → 32-bit unsigned integer** hashing (FNV-1a over
4
+ UTF-8 bytes). Deterministic and stable across platforms.
5
+
6
+ ```python
7
+ from rapidstr2int import str_to_int, str_to_hex
8
+ str_to_int("hello") # 1335831723
9
+ str_to_hex("hello") # "4f9f2cab"
10
+ ```
11
+
12
+ Useful for hash tables, shard/bucket keys, bloom filters and cache keys.
13
+
14
+ Binary fixtures under `tests/` are exercised by the test suite as an input corpus.
@@ -0,0 +1,15 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "rapidstr2int"
7
+ version = "1.0.0"
8
+ description = "Fast dependency-free string to 32-bit integer hashing (FNV-1a)"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.7"
12
+ keywords = ["hash", "fnv", "fnv1a", "string", "integer", "uint32"]
13
+
14
+ [tool.setuptools]
15
+ py-modules = ["rapidstr2int"]
@@ -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,9 @@
1
+ MANIFEST.in
2
+ README.md
3
+ pyproject.toml
4
+ rapidstr2int.py
5
+ rapidstr2int.egg-info/PKG-INFO
6
+ rapidstr2int.egg-info/SOURCES.txt
7
+ rapidstr2int.egg-info/dependency_links.txt
8
+ rapidstr2int.egg-info/top_level.txt
9
+ tests/test_rapidstr2int.py
@@ -0,0 +1 @@
1
+ rapidstr2int
@@ -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}"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ import glob
2
+ import os
3
+
4
+ from rapidstr2int import str_to_int, str_to_hex
5
+
6
+
7
+ def test_known_vectors():
8
+ assert str_to_int("") == 0x811C9DC5
9
+ assert str_to_hex("hello") == "4f9f2cab"
10
+ assert str_to_hex("a") == "e40c292c"
11
+
12
+
13
+ def test_corpus():
14
+ here = os.path.dirname(__file__)
15
+ for f in glob.glob(os.path.join(here, "*.bin")):
16
+ with open(f, "rb") as fh:
17
+ data = fh.read()
18
+ h = str_to_int(data.decode("latin1"))
19
+ assert 0 <= h <= 0xFFFFFFFF