feat(rust): port histogram counting primitives

Move byte histogram counting into Rust for FSE and Huffman compression callers.
The implementation preserves the C workspace contract, checked alphabet path,
fast path, empty-input behavior, and C ABI while the original C source becomes
a header-only compatibility shim.

Focused tests cover count accumulation, invalid alphabets, workspace failures,
and striped large inputs. Higher-level compression remains C for now.

Test Plan:
- cargo fmt --check
- cargo test --all-targets
- cargo clippy --all-targets -- -D warnings
- cargo build --release
- make -C tests fuzzer
- ./tests/fuzzer -i1 --no-big-tests
- compile hist.c with -Werror and -Wredundant-decls

Refs: rust/README.md
This commit is contained in:
2026-07-10 20:06:25 +02:00
parent 26b5e202ee
commit 158cd680d9
4 changed files with 382 additions and 195 deletions
+8 -6
View File
@@ -20,14 +20,16 @@ zstd ABI:
- Entropy coding
- `entropy_common` reads FSE normalized counts and Huffman statistics.
- `fse_decompress` builds FSE decoding tables and decodes FSE streams.
- Compression primitives
- `hist` counts byte frequencies for FSE and Huffman compression.
- Runtime support
- `threading` provides platform pthread wrappers required by zstd headers.
- `pool` implements the bounded worker pool used by multithreaded compression.
The remaining compression, general decompression, dictionary, legacy, and CLI
translation units are still C. They must move before the rewrite is complete.
Keeping that boundary explicit prevents a passing hybrid build from being
mistaken for the final all-Rust result.
The remaining block compression, general decompression, dictionary, legacy,
and CLI translation units are still C. They must move before the rewrite is
complete. Keeping that boundary explicit prevents a passing hybrid build from
being mistaken for the final all-Rust result.
## Compatibility boundary
@@ -56,8 +58,8 @@ Then run original compatibility tests from the repository root, starting with
the narrow target for the component being migrated. For example:
```sh
make -C tests poolTests
./tests/poolTests
make -C tests fuzzer
./tests/fuzzer -i1 --no-big-tests
```
Broader `tests/Makefile` targets remain the authoritative integration gates as