Skip to content

Commit 666822d

Browse files
committed
docs: complete documentation parity and accuracy fixes
## 中文基准测试文档补全 - 添加 Arithmetic 和 Range Coder 性能表格 - 添加交互式图表组件 <BenchmarkChart /> - 补充"如何复现"和"另见"章节 - 补充完整的测试数据表格(包含 10MiB 文件) - 添加输出格式说明和添加新基准测试章节 ## C++ API 文档更新 - 移除"零依赖"描述,更新为"共享依赖" - 明确说明依赖 algorithms/shared/cpp/ 中的公共代码 - 统一中英文档结构 ## 验证 - ✅ 文档构建成功 - ✅ 中英文档内容一致
1 parent dbb6a6b commit 666822d

4 files changed

Lines changed: 145 additions & 21 deletions

File tree

docs/en/api/cpp.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
See also: [Streaming API](/en/api/streaming)
44

5-
All C++ implementations remain single-file algorithm cores, but now share a C++17 streaming/buffer facade under `algorithms/shared/cpp/include/compresskit/`.
5+
All C++ implementations keep single-file algorithm cores, but now depend on a shared streaming/buffer facade under `algorithms/shared/cpp/include/compresskit/`.
66

77
## Compilation
88

@@ -101,9 +101,8 @@ Repeated `(count: uint32 LE, value: byte)` pairs.
101101

102102
| Pattern | Description |
103103
|---------|-------------|
104-
| Single file | Each algorithm in one `main.cpp` |
105-
| Zero dependencies | Only standard library |
106-
| `#include <...>` | Standard library only |
104+
| Single-file core | Each algorithm core in one `main.cpp` |
105+
| Shared dependencies | Uses common code from `algorithms/shared/cpp/` |
107106
| Error handling | `fprintf(stderr, ...)` + `exit(1)` |
108107
| Memory management | `std::unique_ptr` with custom deleters |
109108

docs/zh/api/cpp.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
另请参阅: [Streaming API](/zh/api/streaming)
44

5-
所有 C++ 算法核心仍然保持单文件、零依赖风格,但现在额外共享了 `algorithms/shared/cpp/include/compresskit/` 下的 streaming / buffer 门面层。
5+
所有 C++ 算法核心仍然保持单文件风格,但现在依赖 `algorithms/shared/cpp/include/compresskit/` 下的共享 streaming/buffer 门面层。
66

77
## 编译
88

@@ -20,7 +20,7 @@ g++ -std=c++17 -O2 -Wall -Wextra -o <binary> main.cpp
2020
| `-fsanitize=address` | 地址消毒器(调试版本) |
2121
| `-fsanitize=undefined` | 未定义行为消毒器(调试版本) |
2222

23-
## Huffman 编码
23+
## Huffman 编码 (`algorithms/huffman/cpp/main.cpp`)
2424

2525
```bash
2626
./huffman_cpp encode input.bin output.huf
@@ -44,21 +44,57 @@ g++ -std=c++17 -O2 -Wall -Wextra -o <binary> main.cpp
4444

4545
---
4646

47-
## 算术编码 / 区间编码 / RLE
47+
## 算术编码 (`algorithms/arithmetic/cpp/main.cpp`)
4848

49-
遵循相同的单文件、零依赖模式。CLI 接口统一为:
49+
```bash
50+
./arithmetic_cpp encode input.bin output.aenc
51+
./arithmetic_cpp decode output.aenc decoded.bin
52+
```
53+
54+
### 关键类
55+
56+
- `ArithmeticEncoder` — 状态机,包含 `low``high``pendingBits`
57+
- `ArithmeticDecoder` — 解码器,包含 `code` 初始化
58+
59+
---
60+
61+
## 区间编码 (`algorithms/range/cpp/main.cpp`)
5062

5163
```bash
52-
<algorithm>_cpp encode <input> <output>
53-
<algorithm>_cpp decode <input> <output>
64+
./rangecoder_cpp encode input.bin output.rcnc
65+
./rangecoder_cpp decode output.rcnc decoded.bin
5466
```
5567

56-
### 通用模式
68+
### 文件格式
69+
70+
| 偏移 | 大小 | 字段 |
71+
|------|------|------|
72+
| 0 | 4B | 魔数: `RCNC` |
73+
| 4 | 4B | 频率表大小 |
74+
| 8 | 可变 | 频率表 |
75+
| ... | 可变 | 字节流(重归一化区间) |
76+
77+
---
78+
79+
## RLE (`algorithms/rle/cpp/main.cpp`)
80+
81+
```bash
82+
./rle_cpp encode input.bin output.rle
83+
./rle_cpp decode output.rle decoded.bin
84+
```
85+
86+
### 文件格式
87+
88+
重复的 `(count: uint32 LE, value: byte)` 对。
89+
90+
---
91+
92+
## 通用模式
5793

5894
| 模式 | 描述 |
5995
|------|------|
60-
| 单文件 | 每个算法在一个 `main.cpp`|
61-
| 零依赖 | 仅使用标准库 |
96+
| 单文件核心 | 每个算法核心在一个 `main.cpp`|
97+
| 共享依赖 | 使用 `algorithms/shared/cpp/` 中的公共代码 |
6298
| 错误处理 | `fprintf(stderr, ...)` + `exit(1)` |
6399
| 内存管理 | `std::unique_ptr` + 自定义删除器 |
64100

docs/zh/benchmarks/how-to-run.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ cd algorithms/rle/benchmark
3838
python3 bench.py
3939
```
4040

41-
## 测试数据
41+
## 基准测试配置
42+
43+
### 测试数据
4244

4345
| 文件 | 生成方式 | 大小 |
4446
|------|----------|------|
45-
| `random_1MiB.bin` | `os.urandom(1024*1024)` | 1 MiB |
46-
| `random_10MiB.bin` | `os.urandom(10*1024*1024)` | 10 MiB |
47-
| `repetitive_1MiB.bin` | 重复 256 字节模式 | 1 MiB |
48-
| `textli_1MiB.bin` | 加权英文字母 | 1 MiB |
47+
| `tests/data/random_1MiB.bin` | `os.urandom(1024*1024)` | 1 MiB |
48+
| `tests/data/random_10MiB.bin` | `os.urandom(10*1024*1024)` | 10 MiB |
49+
| `tests/data/repetitive_1MiB.bin` | 重复 256 字节模式 | 1 MiB |
50+
| `tests/data/repetitive_10MiB.bin` | 重复 256 字节模式 | 10 MiB |
51+
| `tests/data/textli_1MiB.bin` | 加权英文字母 | 1 MiB |
52+
| `tests/data/textli_10MiB.bin` | 加权英文字母 | 10 MiB |
4953

5054
重新生成:
5155

@@ -55,7 +59,7 @@ make test-data
5559
python3 tests/gen_testdata.py
5660
```
5761

58-
## 测量指标
62+
### 测量指标
5963

6064
| 指标 | 描述 |
6165
|------|------|
@@ -65,6 +69,39 @@ python3 tests/gen_testdata.py
6569
| 解码速度 | MiB/s = 输入大小 / 解码时间 |
6670
| 压缩比 | 输出大小 / 输入大小(越小越好) |
6771

72+
### 输出格式
73+
74+
结果保存在 `reports/` 目录:
75+
76+
```
77+
reports/
78+
├── huffman_cpp_report.txt
79+
├── huffman_go_report.txt
80+
├── huffman_rust_report.txt
81+
├── arithmetic_cpp_report.txt
82+
├── ...
83+
```
84+
85+
每个报告包含:
86+
87+
```
88+
Algorithm: Huffman
89+
Language: C++
90+
Input: 10 MiB random data
91+
Encode: 245 ms (40.8 MiB/s)
92+
Decode: 198 ms (50.5 MiB/s)
93+
Compression ratio: 1.23
94+
```
95+
96+
## 添加新基准测试
97+
98+
添加新测试数据集:
99+
100+
1. 编辑 `tests/gen_testdata.py`
101+
2.`generate_random_file()` 中添加生成代码或创建新生成器
102+
3. 运行 `make test-data`
103+
4. 编辑相应的 `benchmark/bench.py` 以包含新文件
104+
68105
## 故障排除
69106

70107
### "Binary not found"

docs/zh/benchmarks/results.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
基准测试结果取决于硬件和操作系统。请在本地运行 `make bench` 获取您系统的数值。
77
:::
88

9+
## 交互式性能图表
10+
11+
<BenchmarkChart />
12+
913
## 测试数据
1014

1115
| 数据集 | 大小 | 描述 |
@@ -22,12 +26,41 @@
2226
| Go | 10 MiB 随机 | ~300 | ~250 | ~33 | ~40 | ~1.2× |
2327
| Rust | 10 MiB 随机 | ~220 | ~180 | ~45 | ~55 | ~1.2× |
2428
| C++ | 10 MiB 类文本 | ~200 | ~160 | ~50 | ~62 | ~1.8× |
29+
| Go | 10 MiB 类文本 | ~250 | ~200 | ~40 | ~50 | ~1.8× |
30+
| Rust | 10 MiB 类文本 | ~180 | ~140 | ~55 | ~71 | ~1.8× |
2531

2632
**关键发现:**
2733
- Huffman 在类文本数据上表现最好(频率分布不均匀)
2834
- Rust 始终最快,C++ 和 Go 相当
2935
- 随机数据压缩比 ≈ 1.2×(接近熵限)
3036

37+
## 算术编码
38+
39+
| 语言 | 输入 | 编码 (ms) | 解码 (ms) | 压缩比 |
40+
|------|------|-----------|-----------|--------|
41+
| C++ | 10 MiB 随机 | ~350 | ~300 | ~1.2× |
42+
| Go | 10 MiB 随机 | ~400 | ~350 | ~1.2× |
43+
| Rust | 10 MiB 随机 | ~320 | ~280 | ~1.2× |
44+
| C++ | 10 MiB 类文本 | ~300 | ~250 | ~1.8× |
45+
46+
**关键发现:**
47+
- 算术编码比 Huffman 慢约 40%,但压缩率更好
48+
- Go 实现由于边界检查开销最大
49+
- 分数位编码比 Huffman 提升 5-10% 压缩率
50+
51+
## 区间编码
52+
53+
| 语言 | 输入 | 编码 (ms) | 解码 (ms) | 压缩比 |
54+
|------|------|-----------|-----------|--------|
55+
| C++ | 10 MiB 随机 | ~200 | ~180 | ~1.2× |
56+
| Go | 10 MiB 随机 | ~250 | ~220 | ~1.2× |
57+
| Rust | 10 MiB 随机 | ~180 | ~150 | ~1.2× |
58+
59+
**关键发现:**
60+
- 区间编码比算术编码快约 30%(字节级 I/O vs 位级)
61+
- 压缩率与算术编码相同
62+
- ⚠️ 已知问题:解码在 >500KB 文件上会卡住,请使用较小的测试文件
63+
3164
## RLE
3265

3366
| 语言 | 输入 | 编码 (ms) | 解码 (ms) | 压缩比 |
@@ -39,12 +72,12 @@
3972

4073
**关键发现:**
4174
- RLE 在重复数据上是最快的算法
42-
- 随机数据用 RLE 会膨胀 ~
75+
- 随机数据用 RLE 会膨胀 ~(每个字节变成 5 字节:4 字节计数 + 1 字节值)
4376
- 最适合作为 BWT 等变换的预处理
4477

4578
## 跨语言对比
4679

47-
### 速度(最快 → 最慢)
80+
### 速度排名(最快 → 最慢)
4881

4982
| 算法 | 编码 | 解码 |
5083
|------|------|------|
@@ -61,3 +94,22 @@
6194
| 算术编码 | 1.2× | 1.0× | 1.9× |
6295
| 区间编码 | 1.2× | 1.0× | 1.9× |
6396
| RLE | 0.2×(膨胀) | 25× | 1.1× |
97+
98+
## 如何复现
99+
100+
```bash
101+
# 生成测试数据
102+
make test-data
103+
104+
# 运行所有基准测试
105+
make bench
106+
107+
# 结果保存在 reports/ 目录
108+
ls reports/
109+
```
110+
111+
## 另见
112+
113+
- [如何运行基准测试](/zh/benchmarks/how-to-run) — 详细说明
114+
- [跨语言测试](/zh/testing/cross-language) — 验证方法
115+
- [算法指南](/zh/guide/algorithms) — 对比和选择指南

0 commit comments

Comments
 (0)