hyzip 0.1.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.
- hyzip-0.1.0/PKG-INFO +25 -0
- hyzip-0.1.0/README.md +15 -0
- hyzip-0.1.0/hyzip/__init__.py +62 -0
- hyzip-0.1.0/hyzip/_tikmax.pyi +11 -0
- hyzip-0.1.0/hyzip/py.typed +1 -0
- hyzip-0.1.0/hyzip.egg-info/PKG-INFO +25 -0
- hyzip-0.1.0/hyzip.egg-info/SOURCES.txt +12 -0
- hyzip-0.1.0/hyzip.egg-info/dependency_links.txt +1 -0
- hyzip-0.1.0/hyzip.egg-info/requires.txt +2 -0
- hyzip-0.1.0/hyzip.egg-info/top_level.txt +1 -0
- hyzip-0.1.0/pyproject.toml +15 -0
- hyzip-0.1.0/setup.cfg +4 -0
- hyzip-0.1.0/setup.py +26 -0
- hyzip-0.1.0/src/tikmax.cpp +58 -0
hyzip-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hyzip
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Auto-Routing Hybrid Text Compressor (MoeZip + TikMax)
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: moezip
|
|
9
|
+
Requires-Dist: tiktoken>=0.5.0
|
|
10
|
+
|
|
11
|
+
# hyzip
|
|
12
|
+
|
|
13
|
+
Auto-Routing Hybrid Text Compression Engine combining **MoeZip** (2nd-Order Markov + LZ777) and **TikMax** (BPE + C++ LEB128 Varint).
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import hyzip
|
|
19
|
+
|
|
20
|
+
# Compress text (Auto-selects best engine)
|
|
21
|
+
compressed = hyzip.compress("Hello world!")
|
|
22
|
+
|
|
23
|
+
# Decompress text
|
|
24
|
+
text = hyzip.decompress(compressed)
|
|
25
|
+
```
|
hyzip-0.1.0/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# hyzip
|
|
2
|
+
|
|
3
|
+
Auto-Routing Hybrid Text Compression Engine combining **MoeZip** (2nd-Order Markov + LZ777) and **TikMax** (BPE + C++ LEB128 Varint).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
import hyzip
|
|
9
|
+
|
|
10
|
+
# Compress text (Auto-selects best engine)
|
|
11
|
+
compressed = hyzip.compress("Hello world!")
|
|
12
|
+
|
|
13
|
+
# Decompress text
|
|
14
|
+
text = hyzip.decompress(compressed)
|
|
15
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""
|
|
2
|
+
hyzip: Auto-Routing Hybrid Text Compression Engine
|
|
3
|
+
Combines installed moezip + tikmax BPE into a unified 1-byte header protocol.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import tiktoken
|
|
7
|
+
import moezip # Uses already installed moezip engine!
|
|
8
|
+
from hyzip import _tikmax
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.0"
|
|
11
|
+
|
|
12
|
+
_enc = tiktoken.get_encoding("cl100k_base")
|
|
13
|
+
|
|
14
|
+
FLAG_MOEZIP = b'M' # Header for MoeZip payload (0x4D)
|
|
15
|
+
FLAG_TIKMAX = b'T' # Header for TikMax payload (0x54)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _tikmax_compress(text: str) -> bytes:
|
|
19
|
+
tokens = _enc.encode(text)
|
|
20
|
+
return _tikmax.pack_tokens(tokens)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _tikmax_decompress(data: bytes) -> str:
|
|
24
|
+
tokens = _tikmax.unpack_tokens(data)
|
|
25
|
+
return _enc.decode(tokens)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def compress(text: str) -> bytes:
|
|
29
|
+
"""
|
|
30
|
+
Compresses text using BOTH MoeZip and TikMax engines.
|
|
31
|
+
Returns the smallest binary payload prepended with a 1-byte header flag.
|
|
32
|
+
"""
|
|
33
|
+
if not text:
|
|
34
|
+
return b""
|
|
35
|
+
|
|
36
|
+
# Compress with MoeZip
|
|
37
|
+
mz_payload = FLAG_MOEZIP + moezip.compress(text)
|
|
38
|
+
|
|
39
|
+
# Compress with TikMax
|
|
40
|
+
tm_payload = FLAG_TIKMAX + _tikmax_compress(text)
|
|
41
|
+
|
|
42
|
+
# Pick the smaller winner
|
|
43
|
+
return mz_payload if len(mz_payload) <= len(tm_payload) else tm_payload
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def decompress(payload: bytes) -> str:
|
|
47
|
+
"""
|
|
48
|
+
Decompresses payload by reading the 1-byte header flag
|
|
49
|
+
and routing to the correct engine.
|
|
50
|
+
"""
|
|
51
|
+
if not payload:
|
|
52
|
+
return ""
|
|
53
|
+
|
|
54
|
+
header = payload[:1]
|
|
55
|
+
body = payload[1:]
|
|
56
|
+
|
|
57
|
+
if header == FLAG_MOEZIP:
|
|
58
|
+
return moezip.decompress(body)
|
|
59
|
+
elif header == FLAG_TIKMAX:
|
|
60
|
+
return _tikmax_decompress(body)
|
|
61
|
+
else:
|
|
62
|
+
raise ValueError(f"Corrupted payload or unknown header flag: {header}")
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# _tikmax.pyi - IDE Auto-Completion Type Stubs
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
def pack_tokens(tokens: List[int]) -> bytes:
|
|
6
|
+
"""Packs Tiktoken BPE token IDs into an LEB128 + ZigZag Varint byte stream."""
|
|
7
|
+
...
|
|
8
|
+
|
|
9
|
+
def unpack_tokens(data: bytes) -> List[int]:
|
|
10
|
+
"""Unpacks an LEB128 + ZigZag Varint byte stream back into token IDs."""
|
|
11
|
+
...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Marker for PEP 561
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hyzip
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Auto-Routing Hybrid Text Compressor (MoeZip + TikMax)
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: moezip
|
|
9
|
+
Requires-Dist: tiktoken>=0.5.0
|
|
10
|
+
|
|
11
|
+
# hyzip
|
|
12
|
+
|
|
13
|
+
Auto-Routing Hybrid Text Compression Engine combining **MoeZip** (2nd-Order Markov + LZ777) and **TikMax** (BPE + C++ LEB128 Varint).
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import hyzip
|
|
19
|
+
|
|
20
|
+
# Compress text (Auto-selects best engine)
|
|
21
|
+
compressed = hyzip.compress("Hello world!")
|
|
22
|
+
|
|
23
|
+
# Decompress text
|
|
24
|
+
text = hyzip.decompress(compressed)
|
|
25
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.py
|
|
4
|
+
hyzip/__init__.py
|
|
5
|
+
hyzip/_tikmax.pyi
|
|
6
|
+
hyzip/py.typed
|
|
7
|
+
hyzip.egg-info/PKG-INFO
|
|
8
|
+
hyzip.egg-info/SOURCES.txt
|
|
9
|
+
hyzip.egg-info/dependency_links.txt
|
|
10
|
+
hyzip.egg-info/requires.txt
|
|
11
|
+
hyzip.egg-info/top_level.txt
|
|
12
|
+
src/tikmax.cpp
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hyzip
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "pybind11>=2.10.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hyzip"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Auto-Routing Hybrid Text Compressor (MoeZip + TikMax)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
dependencies = [
|
|
13
|
+
"moezip",
|
|
14
|
+
"tiktoken>=0.5.0"
|
|
15
|
+
]
|
hyzip-0.1.0/setup.cfg
ADDED
hyzip-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from setuptools import setup, Extension, find_packages
|
|
3
|
+
import pybind11
|
|
4
|
+
|
|
5
|
+
cpp_args = ['/O2', '/std:c++20'] if os.name == 'nt' else ['-O3', '-std=c++20']
|
|
6
|
+
|
|
7
|
+
ext_tikmax = Extension(
|
|
8
|
+
'hyzip._tikmax',
|
|
9
|
+
sources=['src/tikmax.cpp'],
|
|
10
|
+
include_dirs=[pybind11.get_include()],
|
|
11
|
+
language='c++',
|
|
12
|
+
extra_compile_args=cpp_args
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
setup(
|
|
16
|
+
name="hyzip",
|
|
17
|
+
version="0.1.0",
|
|
18
|
+
install_requires=[
|
|
19
|
+
"moezip",
|
|
20
|
+
"tiktoken>=0.5.0"
|
|
21
|
+
],
|
|
22
|
+
packages=find_packages(),
|
|
23
|
+
ext_modules=[ext_tikmax],
|
|
24
|
+
package_data={"hyzip": ["*.pyi", "py.typed"]},
|
|
25
|
+
include_package_data=True,
|
|
26
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
#include <pybind11/pybind11.h>
|
|
3
|
+
#include <pybind11/stl.h>
|
|
4
|
+
#include <vector>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <string>
|
|
7
|
+
|
|
8
|
+
namespace py = pybind11;
|
|
9
|
+
|
|
10
|
+
static py::bytes cpp_pack_tokens(const std::vector<int32_t>& tokens) {
|
|
11
|
+
std::vector<uint8_t> out;
|
|
12
|
+
out.reserve(tokens.size() * 2);
|
|
13
|
+
|
|
14
|
+
int32_t prev = 0;
|
|
15
|
+
for (int32_t token : tokens) {
|
|
16
|
+
int32_t delta = token - prev;
|
|
17
|
+
prev = token;
|
|
18
|
+
uint32_t z_val = (delta >> 31) ^ (delta << 1);
|
|
19
|
+
|
|
20
|
+
while (z_val >= 0x80) {
|
|
21
|
+
out.push_back(static_cast<uint8_t>((z_val & 0x7F) | 0x80));
|
|
22
|
+
z_val >>= 7;
|
|
23
|
+
}
|
|
24
|
+
out.push_back(static_cast<uint8_t>(z_val & 0x7F));
|
|
25
|
+
}
|
|
26
|
+
return py::bytes(reinterpret_cast<const char*>(out.data()), out.size());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static std::vector<int32_t> cpp_unpack_tokens(const py::bytes& data) {
|
|
30
|
+
std::string str_data = data;
|
|
31
|
+
std::vector<int32_t> tokens;
|
|
32
|
+
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(str_data.data());
|
|
33
|
+
size_t size = str_data.size();
|
|
34
|
+
size_t i = 0;
|
|
35
|
+
|
|
36
|
+
int32_t prev = 0;
|
|
37
|
+
while (i < size) {
|
|
38
|
+
uint32_t z_val = 0;
|
|
39
|
+
int shift = 0;
|
|
40
|
+
while (i < size) {
|
|
41
|
+
uint8_t byte = ptr[i++];
|
|
42
|
+
z_val |= static_cast<uint32_t>(byte & 0x7F) << shift;
|
|
43
|
+
if (!(byte & 0x80)) break;
|
|
44
|
+
shift += 7;
|
|
45
|
+
}
|
|
46
|
+
int32_t delta = (z_val >> 1) ^ (-(z_val & 1));
|
|
47
|
+
int32_t token = prev + delta;
|
|
48
|
+
prev = token;
|
|
49
|
+
tokens.push_back(token);
|
|
50
|
+
}
|
|
51
|
+
return tokens;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
PYBIND11_MODULE(_tikmax, m) {
|
|
55
|
+
m.doc() = "tikmax: Ultra-fast Tiktoken BPE + C++ Varint bit-packer";
|
|
56
|
+
m.def("pack_tokens", &cpp_pack_tokens, py::arg("tokens"), "Packs integer token IDs into LEB128 + ZigZag bytes.");
|
|
57
|
+
m.def("unpack_tokens", &cpp_unpack_tokens, py::arg("data"), "Unpacks LEB128 + ZigZag bytes into token IDs.");
|
|
58
|
+
}
|