Skip to content

Commit 826f2d2

Browse files
LessUpqwencoder
andcommitted
refactor: 重构项目目录结构,将算法实现移至algorithms/目录
- 移动 huffman/, arithmetic/, range/, rle/ 到 algorithms/ - 清理构建产物(PDB文件、__pycache__、test_decode调试工具) - 删除重复的docs/guide/目录(已被docs/en/guide/替代) - 更新Makefile、CI工作流、文档中的所有路径引用 - 更新RFC-0001架构图以反映新目录结构 - 添加空的specs/api/和specs/db/占位目录 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
1 parent c278ed7 commit 826f2d2

57 files changed

Lines changed: 291 additions & 806 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ jobs:
2929

3030
- name: Build Huffman C++
3131
run: |
32-
cd huffman/cpp
32+
cd algorithms/huffman/cpp
3333
g++ -std=c++17 -O2 -Wall -Wextra main.cpp -o huffman_cpp
3434
./huffman_cpp || true # Show usage
3535
3636
- name: Build Arithmetic C++
3737
run: |
38-
cd arithmetic/cpp
38+
cd algorithms/arithmetic/cpp
3939
g++ -std=c++17 -O2 -Wall -Wextra main.cpp -o arithmetic_cpp
4040
./arithmetic_cpp || true
4141
4242
- name: Build Range coder C++
4343
run: |
44-
cd range/cpp
44+
cd algorithms/range/cpp
4545
g++ -std=c++17 -O2 -Wall -Wextra main.cpp -o rangecoder_cpp
4646
./rangecoder_cpp || true
4747
4848
- name: Build RLE C++
4949
run: |
50-
cd rle/cpp
50+
cd algorithms/rle/cpp
5151
g++ -std=c++17 -O2 -Wall -Wextra main.cpp -o rle_cpp
5252
./rle_cpp || true
5353
@@ -79,28 +79,28 @@ jobs:
7979
8080
- name: Build Huffman Go
8181
run: |
82-
cd huffman/go
82+
cd algorithms/huffman/go
8383
go vet ./...
8484
go test ./...
8585
go build -o huffman_go .
8686
8787
- name: Build Arithmetic Go
8888
run: |
89-
cd arithmetic/go
89+
cd algorithms/arithmetic/go
9090
go vet ./...
9191
go test ./...
9292
go build -o arithmetic_go .
9393
9494
- name: Build Range coder Go
9595
run: |
96-
cd range/go
96+
cd algorithms/range/go
9797
go vet ./...
9898
go test ./...
9999
go build -o rangecoder_go ./cmd
100100
101101
- name: Build RLE Go
102102
run: |
103-
cd rle/go
103+
cd algorithms/rle/go
104104
go vet ./...
105105
go test ./...
106106
go build -o rle_go .
@@ -121,39 +121,39 @@ jobs:
121121

122122
- name: Check Rust formatting
123123
run: |
124-
for file in huffman/rust/main.rs arithmetic/rust/main.rs rle/rust/main.rs; do
124+
for file in algorithms/huffman/rust/main.rs algorithms/arithmetic/rust/main.rs algorithms/rle/rust/main.rs; do
125125
if [ -f "$file" ]; then
126126
rustfmt --check "$file" || exit 1
127127
fi
128128
done
129-
if [ -f "range/rust/Cargo.toml" ]; then
130-
cd range/rust && cargo fmt --check
129+
if [ -f "algorithms/range/rust/Cargo.toml" ]; then
130+
cd algorithms/range/rust && cargo fmt --check
131131
fi
132132
133133
- name: Build Huffman Rust
134134
run: |
135-
cd huffman/rust
135+
cd algorithms/huffman/rust
136136
rustc -O main.rs -o huffman_rust
137137
rustc --test main.rs -o huffman_rust_test
138138
./huffman_rust_test
139139
140140
- name: Build Arithmetic Rust
141141
run: |
142-
cd arithmetic/rust
142+
cd algorithms/arithmetic/rust
143143
rustc -O main.rs -o arithmetic_rust
144144
rustc --test main.rs -o arithmetic_rust_test
145145
./arithmetic_rust_test
146146
147147
- name: Build and check Range coder Rust
148148
run: |
149-
cd range/rust
149+
cd algorithms/range/rust
150150
cargo clippy -- -D warnings
151151
cargo test
152152
cargo build --release
153153
154154
- name: Build RLE Rust
155155
run: |
156-
cd rle/rust
156+
cd algorithms/rle/rust
157157
rustc -O main.rs -o rle_rust
158158
rustc --test main.rs -o rle_rust_test
159159
./rle_rust_test
@@ -188,48 +188,48 @@ jobs:
188188
- name: Build all implementations
189189
run: |
190190
# C++
191-
cd huffman/cpp && g++ -std=c++17 -O2 main.cpp -o huffman_cpp && cd ../..
192-
cd arithmetic/cpp && g++ -std=c++17 -O2 main.cpp -o arithmetic_cpp && cd ../..
193-
cd range/cpp && g++ -std=c++17 -O2 main.cpp -o rangecoder_cpp && cd ../..
194-
cd rle/cpp && g++ -std=c++17 -O2 main.cpp -o rle_cpp && cd ../..
191+
cd algorithms/huffman/cpp && g++ -std=c++17 -O2 main.cpp -o huffman_cpp && cd ../..
192+
cd algorithms/arithmetic/cpp && g++ -std=c++17 -O2 main.cpp -o arithmetic_cpp && cd ../..
193+
cd algorithms/range/cpp && g++ -std=c++17 -O2 main.cpp -o rangecoder_cpp && cd ../..
194+
cd algorithms/rle/cpp && g++ -std=c++17 -O2 main.cpp -o rle_cpp && cd ../..
195195
196196
# Go
197-
cd huffman/go && go build -o huffman_go . && cd ../..
198-
cd arithmetic/go && go build -o arithmetic_go . && cd ../..
199-
cd range/go && go build -o rangecoder_go ./cmd && cd ../..
200-
cd rle/go && go build -o rle_go . && cd ../..
197+
cd algorithms/huffman/go && go build -o huffman_go . && cd ../..
198+
cd algorithms/arithmetic/go && go build -o arithmetic_go . && cd ../..
199+
cd algorithms/range/go && go build -o rangecoder_go ./cmd && cd ../..
200+
cd algorithms/rle/go && go build -o rle_go . && cd ../..
201201
202202
# Rust
203-
cd huffman/rust && rustc -O main.rs -o huffman_rust && cd ../..
204-
cd arithmetic/rust && rustc -O main.rs -o arithmetic_rust && cd ../..
205-
cd range/rust && cargo build --bin rangecoder --release && cd ../..
206-
cd rle/rust && rustc -O main.rs -o rle_rust && cd ../..
203+
cd algorithms/huffman/rust && rustc -O main.rs -o huffman_rust && cd ../..
204+
cd algorithms/arithmetic/rust && rustc -O main.rs -o arithmetic_rust && cd ../..
205+
cd algorithms/range/rust && cargo build --bin rangecoder --release && cd ../..
206+
cd algorithms/rle/rust && rustc -O main.rs -o rle_rust && cd ../..
207207
208208
- name: Test Huffman correctness
209209
run: |
210210
TEST_FILE="tests/data/random_1MiB.bin"
211211
212212
echo "Testing Huffman C++..."
213-
./huffman/cpp/huffman_cpp encode "$TEST_FILE" /tmp/huf_cpp.enc
214-
./huffman/cpp/huffman_cpp decode /tmp/huf_cpp.enc /tmp/huf_cpp.dec
213+
./algorithms/huffman/cpp/huffman_cpp encode "$TEST_FILE" /tmp/huf_cpp.enc
214+
./algorithms/huffman/cpp/huffman_cpp decode /tmp/huf_cpp.enc /tmp/huf_cpp.dec
215215
diff "$TEST_FILE" /tmp/huf_cpp.dec
216216
217217
echo "Testing Huffman Go..."
218-
./huffman/go/huffman_go encode "$TEST_FILE" /tmp/huf_go.enc
219-
./huffman/go/huffman_go decode /tmp/huf_go.enc /tmp/huf_go.dec
218+
./algorithms/huffman/go/huffman_go encode "$TEST_FILE" /tmp/huf_go.enc
219+
./algorithms/huffman/go/huffman_go decode /tmp/huf_go.enc /tmp/huf_go.dec
220220
diff "$TEST_FILE" /tmp/huf_go.dec
221221
222222
echo "Testing Huffman Rust..."
223-
./huffman/rust/huffman_rust encode "$TEST_FILE" /tmp/huf_rust.enc
224-
./huffman/rust/huffman_rust decode /tmp/huf_rust.enc /tmp/huf_rust.dec
223+
./algorithms/huffman/rust/huffman_rust encode "$TEST_FILE" /tmp/huf_rust.enc
224+
./algorithms/huffman/rust/huffman_rust decode /tmp/huf_rust.enc /tmp/huf_rust.dec
225225
diff "$TEST_FILE" /tmp/huf_rust.dec
226226
227227
echo "Testing cross-language (C++ encode -> Go decode)..."
228-
./huffman/go/huffman_go decode /tmp/huf_cpp.enc /tmp/huf_cross_go.dec
228+
./algorithms/huffman/go/huffman_go decode /tmp/huf_cpp.enc /tmp/huf_cross_go.dec
229229
diff "$TEST_FILE" /tmp/huf_cross_go.dec
230230
231231
echo "Testing cross-language (C++ encode -> Rust decode)..."
232-
./huffman/rust/huffman_rust decode /tmp/huf_cpp.enc /tmp/huf_cross_rust.dec
232+
./algorithms/huffman/rust/huffman_rust decode /tmp/huf_cpp.enc /tmp/huf_cross_rust.dec
233233
diff "$TEST_FILE" /tmp/huf_cross_rust.dec
234234
235235
echo "Huffman tests passed!"
@@ -239,26 +239,26 @@ jobs:
239239
TEST_FILE="tests/data/random_1MiB.bin"
240240
241241
echo "Testing Arithmetic C++..."
242-
./arithmetic/cpp/arithmetic_cpp encode "$TEST_FILE" /tmp/arith_cpp.enc
243-
./arithmetic/cpp/arithmetic_cpp decode /tmp/arith_cpp.enc /tmp/arith_cpp.dec
242+
./algorithms/arithmetic/cpp/arithmetic_cpp encode "$TEST_FILE" /tmp/arith_cpp.enc
243+
./algorithms/arithmetic/cpp/arithmetic_cpp decode /tmp/arith_cpp.enc /tmp/arith_cpp.dec
244244
diff "$TEST_FILE" /tmp/arith_cpp.dec
245245
246246
echo "Testing Arithmetic Go..."
247-
./arithmetic/go/arithmetic_go encode "$TEST_FILE" /tmp/arith_go.enc
248-
./arithmetic/go/arithmetic_go decode /tmp/arith_go.enc /tmp/arith_go.dec
247+
./algorithms/arithmetic/go/arithmetic_go encode "$TEST_FILE" /tmp/arith_go.enc
248+
./algorithms/arithmetic/go/arithmetic_go decode /tmp/arith_go.enc /tmp/arith_go.dec
249249
diff "$TEST_FILE" /tmp/arith_go.dec
250250
251251
echo "Testing Arithmetic Rust..."
252-
./arithmetic/rust/arithmetic_rust encode "$TEST_FILE" /tmp/arith_rust.enc
253-
./arithmetic/rust/arithmetic_rust decode /tmp/arith_rust.enc /tmp/arith_rust.dec
252+
./algorithms/arithmetic/rust/arithmetic_rust encode "$TEST_FILE" /tmp/arith_rust.enc
253+
./algorithms/arithmetic/rust/arithmetic_rust decode /tmp/arith_rust.enc /tmp/arith_rust.dec
254254
diff "$TEST_FILE" /tmp/arith_rust.dec
255255
256256
echo "Testing cross-language (C++ encode -> Go decode)..."
257-
./arithmetic/go/arithmetic_go decode /tmp/arith_cpp.enc /tmp/arith_cross_go.dec
257+
./algorithms/arithmetic/go/arithmetic_go decode /tmp/arith_cpp.enc /tmp/arith_cross_go.dec
258258
diff "$TEST_FILE" /tmp/arith_cross_go.dec
259259
260260
echo "Testing cross-language (C++ encode -> Rust decode)..."
261-
./arithmetic/rust/arithmetic_rust decode /tmp/arith_cpp.enc /tmp/arith_cross_rust.dec
261+
./algorithms/arithmetic/rust/arithmetic_rust decode /tmp/arith_cpp.enc /tmp/arith_cross_rust.dec
262262
diff "$TEST_FILE" /tmp/arith_cross_rust.dec
263263
264264
echo "Arithmetic tests passed!"
@@ -269,19 +269,19 @@ jobs:
269269
# Using smaller test file until this is fixed
270270
TEST_FILE="tests/data/random_10MiB.bin"
271271
SMALL_TEST_FILE="/tmp/range_small.bin"
272-
RANGE_RUST="./range/rust/target/release/rangecoder"
272+
RANGE_RUST="./algorithms/range/rust/target/release/rangecoder"
273273
274274
# Create 100KB test file for range coder
275275
dd if="$TEST_FILE" of="$SMALL_TEST_FILE" bs=1024 count=100 2>/dev/null
276276
277277
echo "Testing Range coder C++..."
278-
./range/cpp/rangecoder_cpp encode "$SMALL_TEST_FILE" /tmp/range_cpp.enc
279-
./range/cpp/rangecoder_cpp decode /tmp/range_cpp.enc /tmp/range_cpp.dec
278+
./algorithms/range/cpp/rangecoder_cpp encode "$SMALL_TEST_FILE" /tmp/range_cpp.enc
279+
./algorithms/range/cpp/rangecoder_cpp decode /tmp/range_cpp.enc /tmp/range_cpp.dec
280280
diff "$SMALL_TEST_FILE" /tmp/range_cpp.dec
281281
282282
echo "Testing Range coder Go..."
283-
./range/go/rangecoder_go encode "$SMALL_TEST_FILE" /tmp/range_go.enc
284-
./range/go/rangecoder_go decode /tmp/range_go.enc /tmp/range_go.dec
283+
./algorithms/range/go/rangecoder_go encode "$SMALL_TEST_FILE" /tmp/range_go.enc
284+
./algorithms/range/go/rangecoder_go decode /tmp/range_go.enc /tmp/range_go.dec
285285
diff "$SMALL_TEST_FILE" /tmp/range_go.dec
286286
287287
echo "Testing Range coder Rust..."
@@ -290,7 +290,7 @@ jobs:
290290
diff "$SMALL_TEST_FILE" /tmp/range_rust.dec
291291
292292
echo "Testing cross-language (C++ encode -> Go decode)..."
293-
./range/go/rangecoder_go decode /tmp/range_cpp.enc /tmp/range_cross_go.dec
293+
./algorithms/range/go/rangecoder_go decode /tmp/range_cpp.enc /tmp/range_cross_go.dec
294294
diff "$SMALL_TEST_FILE" /tmp/range_cross_go.dec
295295
296296
echo "Testing cross-language (C++ encode -> Rust decode)..."
@@ -304,26 +304,26 @@ jobs:
304304
TEST_FILE="tests/data/repetitive_10MiB.bin"
305305
306306
echo "Testing RLE C++..."
307-
./rle/cpp/rle_cpp encode "$TEST_FILE" /tmp/rle_cpp.enc
308-
./rle/cpp/rle_cpp decode /tmp/rle_cpp.enc /tmp/rle_cpp.dec
307+
./algorithms/rle/cpp/rle_cpp encode "$TEST_FILE" /tmp/rle_cpp.enc
308+
./algorithms/rle/cpp/rle_cpp decode /tmp/rle_cpp.enc /tmp/rle_cpp.dec
309309
diff "$TEST_FILE" /tmp/rle_cpp.dec
310310
311311
echo "Testing RLE Go..."
312-
./rle/go/rle_go encode "$TEST_FILE" /tmp/rle_go.enc
313-
./rle/go/rle_go decode /tmp/rle_go.enc /tmp/rle_go.dec
312+
./algorithms/rle/go/rle_go encode "$TEST_FILE" /tmp/rle_go.enc
313+
./algorithms/rle/go/rle_go decode /tmp/rle_go.enc /tmp/rle_go.dec
314314
diff "$TEST_FILE" /tmp/rle_go.dec
315315
316316
echo "Testing RLE Rust..."
317-
./rle/rust/rle_rust encode "$TEST_FILE" /tmp/rle_rust.enc
318-
./rle/rust/rle_rust decode /tmp/rle_rust.enc /tmp/rle_rust.dec
317+
./algorithms/rle/rust/rle_rust encode "$TEST_FILE" /tmp/rle_rust.enc
318+
./algorithms/rle/rust/rle_rust decode /tmp/rle_rust.enc /tmp/rle_rust.dec
319319
diff "$TEST_FILE" /tmp/rle_rust.dec
320320
321321
echo "Testing cross-language (C++ encode -> Go decode)..."
322-
./rle/go/rle_go decode /tmp/rle_cpp.enc /tmp/rle_cross_go.dec
322+
./algorithms/rle/go/rle_go decode /tmp/rle_cpp.enc /tmp/rle_cross_go.dec
323323
diff "$TEST_FILE" /tmp/rle_cross_go.dec
324324
325325
echo "Testing cross-language (C++ encode -> Rust decode)..."
326-
./rle/rust/rle_rust decode /tmp/rle_cpp.enc /tmp/rle_cross_rust.dec
326+
./algorithms/rle/rust/rle_rust decode /tmp/rle_cpp.enc /tmp/rle_cross_rust.dec
327327
diff "$TEST_FILE" /tmp/rle_cross_rust.dec
328328
329329
echo "RLE tests passed!"

AGENTS.md

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,72 @@
11
# Project Philosophy: Spec-Driven Development (SDD)
22

3-
This project strictly follows the **Spec-Driven Development (SDD)** paradigm. All code implementations are based on the specification documents in the `/specs` directory as the Single Source of Truth.
3+
This project strictly follows the **Spec-Driven Development (SDD)** paradigm. All code implementations must be based on the specification documents in the `/specs` directory as the Single Source of Truth.
44

55
## Directory Context
66

77
| Directory | Purpose |
88
|-----------|---------|
99
| `/specs/product/` | Product feature definitions and acceptance criteria |
1010
| `/specs/rfc/` | Technical design documents (architecture, patterns, decisions) |
11-
| `/specs/api/` | API interface definitions (OpenAPI, schemas) |
12-
| `/specs/db/` | Database model definitions (if applicable) |
13-
| `/specs/testing/` | Test specifications and cross-language verification rules |
14-
| `/docs/` | User-facing documentation (VitePress site) |
11+
| `/specs/api/` | API interface definitions (OpenAPI, GraphQL schemas) |
12+
| `/specs/db/` | Database model definitions |
13+
| `/specs/testing/` | Test specifications and BDD test cases |
14+
| `/docs/` | User-facing documentation (VitePress documentation site) |
1515

1616
## AI Agent Workflow Instructions
1717

1818
When you (AI) are asked to develop a new feature, modify an existing one, or fix a bug, **you must strictly follow this workflow without skipping any steps**:
1919

20-
### Step 1: Review Specs
20+
### Step 1: Review Specs (审查规范)
2121

22-
- First, read the relevant documents in `/specs` (product requirements, RFCs, API definitions).
22+
- Before writing any code, first read the relevant documents in `/specs` (product requirements, RFCs, API definitions).
2323
- If the user's request conflicts with existing specs, **stop immediately** and point out the conflict. Ask the user whether to update the spec first.
24+
- 如果用户指令与现有 Spec 冲突,请立即停止编码,并指出冲突点,询问用户是否需要先更新 Spec。
2425

25-
### Step 2: Spec-First Update
26+
### Step 2: Spec-First Update (规范优先)
2627

2728
- If this is a new feature, or if existing interfaces/database structures need to change, **you must first propose modifying or creating the appropriate spec documents** (e.g., `openapi.yaml` or RFC documents).
2829
- Wait for user confirmation of the spec changes before proceeding to the code writing phase.
30+
- 如果这是一个新功能,或者需要改变现有的接口/数据库结构,**必须首先提议修改或创建相应的 Spec 文档**。等待用户确认 Spec 的修改后,才能进入代码编写阶段。
2931

30-
### Step 3: Implementation
32+
### Step 3: Implementation (代码实现)
3133

3234
- When writing code, **100% adhere to the definitions in the specs** (including variable naming, API paths, data types, status codes, etc.).
3335
- Do not add features in the code that are not defined in the specs (No Gold-Plating).
36+
- 编写代码时,必须 100% 遵守 Spec 中的定义(包括变量命名、API 路径、数据类型、状态码等)。不要在代码中擅自添加 Spec 中未定义的功能。
3437

35-
### Step 4: Test Against Spec
38+
### Step 4: Test Against Spec (测试验证)
3639

3740
- Write unit and integration tests based on the acceptance criteria in `/specs`.
3841
- Ensure test cases cover all boundary conditions described in the specs.
42+
- 根据 `/specs` 中的验收标准(Acceptance Criteria)编写单元测试和集成测试。确保测试用例覆盖了 Spec 中描述的所有边界情况。
3943

4044
## Code Generation Rules
4145

42-
- Any externally exposed API changes must synchronously update the relevant spec files in `/specs/`.
46+
- Any externally exposed API changes must synchronously update the relevant spec files in `/specs/api/`.
4347
- If uncertain about technical details, consult the architecture conventions in `/specs/rfc/`. Do not invent design patterns on your own.
4448
- All error messages must be in English.
45-
- Follow language-specific conventions (C++17, Go 1.21+, Rust 1.70+).
49+
- Follow language-specific conventions:
50+
- **C++17**: Google C++ Style Guide, 4-space indentation, snake_case for functions/variables, PascalCase for classes
51+
- **Go 1.21+**: gofmt formatting, go vet analysis, Effective Go conventions
52+
- **Rust 1.70+**: rustfmt formatting, clippy linting, Rust API Guidelines
53+
- **Python 3.8+**: PEP 8 style, 4-space indentation
4654

4755
## Why This Matters
4856

49-
1. **Prevent AI Hallucinations**: AI tends to "freestyle" without context. Forcing it to read `/specs` in the first step anchors its thinking scope.
50-
2. **Constrain Modification Path**: Declaring "modify specs before code" ensures document-code synchronization.
51-
3. **Improve PR Quality**: When AI generates Pull Requests, the implementation will be highly aligned with business logic because it's developed based on the acceptance criteria defined in the specs.
57+
1. **Prevent AI Hallucinations (防范 AI 幻觉)**: AI tends to "freestyle" without context. Forcing it to read `/specs` in the first step anchors its thinking scope.
58+
2. **Constrain Modification Path (约束修改路径)**: Declaring "modify specs before code" ensures document-code synchronization (Document-Code Synchronization).
59+
3. **Improve PR Quality (提高 PR 质量)**: When AI generates Pull Requests, the implementation will be highly aligned with business logic because it's developed based on the acceptance criteria defined in the specs.
60+
61+
## Project-Specific Notes
62+
63+
This project implements compression algorithms (Huffman, Arithmetic Coding, Range Coder, RLE) in multiple languages (C++17, Go, Rust). Key considerations:
64+
65+
- **Cross-Language Compatibility**: All implementations must share identical binary file formats
66+
- **Unified CLI Interface**: `./binary <encode|decode> <input> <output>`
67+
- **Security Constraints**: Max input 4 GiB, max output 1 GiB to prevent decompression bombs
68+
- **Testing Focus**: Cross-language encode/decode verification is mandatory
69+
70+
For detailed product requirements, see [specs/product/encoding-project.md](specs/product/encoding-project.md).
71+
For architecture decisions, see [specs/rfc/0001-core-architecture.md](specs/rfc/0001-core-architecture.md).
72+
For testing specifications, see [specs/testing/cross-language.md](specs/testing/cross-language.md).

0 commit comments

Comments
 (0)