@yeyelailou/co 0.0.2 → 0.0.4
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.
- package/README.md +73 -16
- package/bin//345/205/245/345/217/243.js +0 -8
- package/package.json +7 -6
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//345/220/257/345/212/250/345/231/250.c +3 -3
- package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//346/234/272/345/231/250/347/240/201/347/224/237/346/210/220/345/231/250.co +21 -1
- package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//350/207/252/344/270/276/347/274/226/350/257/221.sh +73 -0
- package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//350/207/252/344/270/276/351/252/214/350/257/201//347/274/226/350/257/221/351/251/261/345/212/250.co +3 -1
- package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//350/207/252/344/270/276/351/252/214/350/257/201//347/274/226/350/257/221/351/252/214/350/257/201.sh +24 -8
- package/bin/install.js +0 -276
- package//345/267/245/345/205/267/lsp/server.js +0 -419
- package//345/267/245/345/205/267/lsp//346/265/213/350/257/225.sh +0 -81
- package//345/267/245/345/205/267/vscode-cocn/extension.js +0 -203
- package//345/267/245/345/205/267/vscode-cocn/package.json +0 -58
- package//345/267/245/345/205/267/vscode-cocn/syntaxes/coCN.tmLanguage.json +0 -130
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/273/243/347/240/201/347/224/237/346/210/220/345/231/250.js +0 -2284
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/analysis.js +0 -116
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/benchmark_demo.js +0 -75
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/dominance.js +0 -158
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/gvn.js +0 -45
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/index.js +0 -121
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/ir.js +0 -237
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/constProp.js +0 -126
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/copyProp.js +0 -57
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/cse.js +0 -62
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/dce.js +0 -68
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/devirt.js +0 -38
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/escape.js +0 -67
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/inline.js +0 -142
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/passes/loopOpt.js +0 -215
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/peephole.js +0 -42
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/regalloc.js +0 -212
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/scheduler.js +0 -86
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/spill.js +0 -78
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/ssa.js +0 -235
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/traceSched.js +0 -47
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250/unroll.js +0 -46
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/harness.js +0 -33
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/run_all.js +0 -11
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_constfold.js +0 -58
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_dce.js +0 -49
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_e2e.js +0 -57
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_gvn_spill.js +0 -45
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_loop.js +0 -46
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_regalloc.js +0 -51
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//344/274/230/345/214/226/345/231/250//346/265/213/350/257/225/test_ssa.js +0 -65
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//345/205/245/345/217/243.c +0 -9
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//345/205/245/345/217/243.js +0 -38
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237/AST/345/267/245/345/205/267.js +0 -126
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237/index.js +0 -103
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//345/206/205/350/201/224.js +0 -194
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//345/207/275/346/225/260/347/211/271/345/214/226.js +0 -168
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/243/200/346/237/245/346/266/210/351/231/244.js +0 -166
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//345/206/205/350/201/224/346/265/213/350/257/225.js +0 -53
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//345/207/275/346/225/260/347/211/271/345/214/226/346/265/213/350/257/225.js +0 -67
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//347/253/257/345/210/260/347/253/257/346/265/213/350/257/225.js +0 -104
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//347/261/273/345/236/213/346/216/250/346/226/255/346/265/213/350/257/225.js +0 -87
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//350/277/220/350/241/214/346/265/213/350/257/225.js +0 -43
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//346/265/213/350/257/225//351/200/203/351/200/270/345/210/206/346/236/220/346/265/213/350/257/225.js +0 -58
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//347/211/271/345/214/226/347/274/223/345/255/230.js +0 -83
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//347/216/257/345/242/203.js +0 -126
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//347/261/273/345/236/213.js +0 -294
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//347/261/273/345/236/213/346/216/250/346/226/255.js +0 -461
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//350/260/203/347/224/250/345/233/276.js +0 -119
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/261/273/345/236/213/347/263/273/347/273/237//351/200/203/351/200/270/345/210/206/346/236/220.js +0 -184
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//347/274/226/350/257/221.sh +0 -45
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/alloc.c +0 -206
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/build.sh +0 -70
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/dict.c +0 -143
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/list.c +0 -148
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/math.c +0 -129
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/print.c +0 -135
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/rt.h +0 -177
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/string.c +0 -288
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/syscall.asm +0 -153
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266/test.c +0 -228
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266//344/270/264/346/227/266.c +0 -379
- package//345/267/245/345/205/267//345/216/237/347/224/237/347/274/226/350/257/221/345/231/250//350/277/220/350/241/214/346/227/266.c +0 -441
- package//345/267/245/345/205/267//350/207/252/344/270/276/347/274/226/350/257/221/345/231/250//346/267/261/345/272/246/346/257/224/350/276/203.js +0 -51
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/Empty.java +0 -1
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.c +0 -53
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.co +0 -42
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.go +0 -43
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.java +0 -29
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.js +0 -24
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.py +0 -36
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/bench.rs +0 -35
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/empty.co +0 -0
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/empty_c.c +0 -1
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/empty_go.go +0 -2
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224/empty_rs.rs +0 -1
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/213/274/346/216/245.c +0 -32
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/213/274/346/216/245.co +0 -10
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/216/222/345/272/217.c +0 -23
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/216/222/345/272/217.co +0 -31
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/226/220/346/263/242/351/202/243/345/245/221.c +0 -17
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/226/220/346/263/242/351/202/243/345/245/221.co +0 -10
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/346/226/220/346/263/242/351/202/243/345/245/22120.co +0 -10
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/347/264/257/345/212/240.c +0 -14
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200_/347/264/257/345/212/240.co +0 -10
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/257/271C/350/257/255/350/250/200/345/257/271/346/257/224/347/273/223/346/236/234.txt +0 -164
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206/fib.c +0 -9
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206/fib.co +0 -2
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206/sum.c +0 -10
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206/sum.co +0 -3
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206//350/256/241/346/265/213.sh +0 -32
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//345/276/256/345/237/272/345/207/206//350/256/241/346/265/213/347/273/223/346/236/234.txt +0 -7
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//350/241/245/346/265/213.sh +0 -45
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//350/256/241/346/265/213.sh +0 -163
- package//345/267/245/345/205/267//350/257/255/350/250/200/345/257/271/346/257/224//350/256/241/346/265/213/347/273/223/346/236/234.txt +0 -29
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/* ============================================================
|
|
2
|
-
* coCN 运行时 —— 列表 (动态数组)
|
|
3
|
-
* 结构: { int length; int capacity; void** items; }
|
|
4
|
-
* 热点路径 (append/get/set/pop) 在 rt.h 中 static inline
|
|
5
|
-
* 扩容走 _rt_list_reserve, 利用 mremap 原地扩展
|
|
6
|
-
* ============================================================ */
|
|
7
|
-
#include "rt.h"
|
|
8
|
-
|
|
9
|
-
#define INIT_CAP 16
|
|
10
|
-
|
|
11
|
-
rt_list_t *rt_list_create(void) {
|
|
12
|
-
rt_list_t *l = (rt_list_t *)rt_alloc(sizeof(rt_list_t));
|
|
13
|
-
if (!l) return NULL;
|
|
14
|
-
l->length = 0;
|
|
15
|
-
l->capacity = INIT_CAP;
|
|
16
|
-
l->items = (void **)rt_alloc(INIT_CAP * sizeof(void *));
|
|
17
|
-
return l;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
void _rt_list_reserve(rt_list_t *l, int newcap) {
|
|
21
|
-
if (newcap <= l->capacity) return;
|
|
22
|
-
l->items = (void **)rt_realloc(l->items, (size_t)newcap * sizeof(void *));
|
|
23
|
-
l->capacity = newcap;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/* 外部 API 包装 (调用内联版本) */
|
|
27
|
-
void rt_list_append(rt_list_t *l, void *val) {
|
|
28
|
-
rt_list_append_inline(l, val);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
void *rt_list_get(rt_list_t *l, int idx) {
|
|
32
|
-
return rt_list_get_inline(l, idx);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
void rt_list_set(rt_list_t *l, int idx, void *val) {
|
|
36
|
-
if (idx < 0) return;
|
|
37
|
-
if (idx >= l->capacity) _rt_list_reserve(l, idx + 1);
|
|
38
|
-
l->items[idx] = val;
|
|
39
|
-
if (idx + 1 > l->length) l->length = idx + 1;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
int rt_list_length(rt_list_t *l) {
|
|
43
|
-
return l->length;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
void *rt_list_pop(rt_list_t *l) {
|
|
47
|
-
return rt_list_pop_inline(l);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
void rt_list_insert(rt_list_t *l, int idx, void *val) {
|
|
51
|
-
if (idx < 0) idx = 0;
|
|
52
|
-
if (idx > l->length) idx = l->length;
|
|
53
|
-
if (l->length >= l->capacity)
|
|
54
|
-
_rt_list_reserve(l, l->capacity * 2);
|
|
55
|
-
for (int i = l->length; i > idx; i--)
|
|
56
|
-
l->items[i] = l->items[i - 1];
|
|
57
|
-
l->items[idx] = val;
|
|
58
|
-
l->length++;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
void rt_list_remove(rt_list_t *l, int idx) {
|
|
62
|
-
if (idx < 0 || idx >= l->length) return;
|
|
63
|
-
for (int i = idx; i < l->length - 1; i++)
|
|
64
|
-
l->items[i] = l->items[i + 1];
|
|
65
|
-
l->length--;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
rt_list_t *rt_list_concat(rt_list_t *a, rt_list_t *b) {
|
|
69
|
-
rt_list_t *out = rt_list_create();
|
|
70
|
-
int total = a->length + b->length;
|
|
71
|
-
if (total > out->capacity) _rt_list_reserve(out, total);
|
|
72
|
-
for (int i = 0; i < a->length; i++) out->items[i] = a->items[i];
|
|
73
|
-
for (int i = 0; i < b->length; i++) out->items[a->length + i] = b->items[i];
|
|
74
|
-
out->length = total;
|
|
75
|
-
return out;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
rt_list_t *rt_list_slice(rt_list_t *l, int start, int end) {
|
|
79
|
-
rt_list_t *out = rt_list_create();
|
|
80
|
-
if (start < 0) start = 0;
|
|
81
|
-
if (end > l->length) end = l->length;
|
|
82
|
-
int n = end - start;
|
|
83
|
-
if (n <= 0) return out;
|
|
84
|
-
if (n > out->capacity) _rt_list_reserve(out, n);
|
|
85
|
-
for (int i = 0; i < n; i++) out->items[i] = l->items[start + i];
|
|
86
|
-
out->length = n;
|
|
87
|
-
return out;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/* 快速排序: 小规模插入排序, 大规模递归 */
|
|
91
|
-
#define INSERTION_THRESHOLD 16
|
|
92
|
-
|
|
93
|
-
static void insertion_sort(rt_list_t *l, int lo, int hi,
|
|
94
|
-
int (*cmp)(void *a, void *b)) {
|
|
95
|
-
for (int i = lo + 1; i <= hi; i++) {
|
|
96
|
-
void *key = l->items[i];
|
|
97
|
-
int j = i - 1;
|
|
98
|
-
while (j >= lo && cmp(l->items[j], key) > 0) {
|
|
99
|
-
l->items[j + 1] = l->items[j];
|
|
100
|
-
j--;
|
|
101
|
-
}
|
|
102
|
-
l->items[j + 1] = key;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
static void qsort_range(rt_list_t *l, int lo, int hi,
|
|
107
|
-
int (*cmp)(void *a, void *b)) {
|
|
108
|
-
while (hi - lo > INSERTION_THRESHOLD) {
|
|
109
|
-
/* 三取样 pivot */
|
|
110
|
-
int mid = (lo + hi) >> 1;
|
|
111
|
-
if (cmp(l->items[lo], l->items[mid]) > 0) {
|
|
112
|
-
void *t = l->items[lo]; l->items[lo] = l->items[mid]; l->items[mid] = t;
|
|
113
|
-
}
|
|
114
|
-
if (cmp(l->items[lo], l->items[hi]) > 0) {
|
|
115
|
-
void *t = l->items[lo]; l->items[lo] = l->items[hi]; l->items[hi] = t;
|
|
116
|
-
}
|
|
117
|
-
if (cmp(l->items[mid], l->items[hi]) > 0) {
|
|
118
|
-
void *t = l->items[mid]; l->items[mid] = l->items[hi]; l->items[hi] = t;
|
|
119
|
-
}
|
|
120
|
-
void *pivot = l->items[mid];
|
|
121
|
-
|
|
122
|
-
int i = lo, j = hi;
|
|
123
|
-
while (i <= j) {
|
|
124
|
-
while (cmp(l->items[i], pivot) < 0) i++;
|
|
125
|
-
while (cmp(l->items[j], pivot) > 0) j--;
|
|
126
|
-
if (i <= j) {
|
|
127
|
-
void *tmp = l->items[i];
|
|
128
|
-
l->items[i] = l->items[j];
|
|
129
|
-
l->items[j] = tmp;
|
|
130
|
-
i++; j--;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/* 尾递归优化: 先排小的一侧 */
|
|
134
|
-
if (j - lo < hi - i) {
|
|
135
|
-
qsort_range(l, lo, j, cmp);
|
|
136
|
-
lo = i;
|
|
137
|
-
} else {
|
|
138
|
-
qsort_range(l, i, hi, cmp);
|
|
139
|
-
hi = j;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
void rt_list_sort(rt_list_t *l, int (*cmp)(void *a, void *b)) {
|
|
145
|
-
if (l->length < 2) return;
|
|
146
|
-
qsort_range(l, 0, l->length - 1, cmp);
|
|
147
|
-
insertion_sort(l, 0, l->length - 1, cmp);
|
|
148
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/* ============================================================
|
|
2
|
-
* coCN 运行时 —— 数学函数
|
|
3
|
-
* 精度稍低但比 libm 快 (泰勒展开 / 查表 / 多项式逼近)
|
|
4
|
-
* ============================================================ */
|
|
5
|
-
#include "rt.h"
|
|
6
|
-
|
|
7
|
-
#define PI 3.14159265358979323846
|
|
8
|
-
#define PI2 6.28318530717958647692
|
|
9
|
-
#define EPS 1e-9
|
|
10
|
-
|
|
11
|
-
int rt_abs(int n) { return n < 0 ? -n : n; }
|
|
12
|
-
int rt_min(int a, int b) { return a < b ? a : b; }
|
|
13
|
-
int rt_max(int a, int b) { return a > b ? a : b; }
|
|
14
|
-
|
|
15
|
-
double rt_floor(double x) {
|
|
16
|
-
long l = (long)x;
|
|
17
|
-
if (x < 0 && (double)l != x) l--;
|
|
18
|
-
return (double)l;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
double rt_ceil(double x) {
|
|
22
|
-
long l = (long)x;
|
|
23
|
-
if (x > 0 && (double)l != x) l++;
|
|
24
|
-
return (double)l;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
double rt_round(double x) {
|
|
28
|
-
if (x >= 0) return rt_floor(x + 0.5);
|
|
29
|
-
else return rt_ceil(x - 0.5);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/* x^2 */
|
|
33
|
-
static inline double sq(double x) { return x * x; }
|
|
34
|
-
|
|
35
|
-
/* ------------------------------------------------------------
|
|
36
|
-
* double rt_sqrt(double x) -- 牛顿迭代
|
|
37
|
-
* ------------------------------------------------------------ */
|
|
38
|
-
double rt_sqrt(double x) {
|
|
39
|
-
if (x <= 0) return 0;
|
|
40
|
-
double g = x;
|
|
41
|
-
for (int i = 0; i < 32; i++)
|
|
42
|
-
g = 0.5 * (g + x / g);
|
|
43
|
-
return g;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/* ------------------------------------------------------------
|
|
47
|
-
* double rt_exp(double x) -- 泰勒级数
|
|
48
|
-
* ------------------------------------------------------------ */
|
|
49
|
-
double rt_exp(double x) {
|
|
50
|
-
if (x < -700) return 0;
|
|
51
|
-
double sum = 1, term = 1;
|
|
52
|
-
for (int i = 1; i < 60; i++) {
|
|
53
|
-
term *= x / i;
|
|
54
|
-
sum += term;
|
|
55
|
-
if (term < EPS && term > -EPS) break;
|
|
56
|
-
}
|
|
57
|
-
return sum;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/* ------------------------------------------------------------
|
|
61
|
-
* double rt_log(double x) -- 自然对数
|
|
62
|
-
* log(x) = 2*atanh((x-1)/(x+1)) 级数
|
|
63
|
-
* ------------------------------------------------------------ */
|
|
64
|
-
double rt_log(double x) {
|
|
65
|
-
if (x <= 0) return -1e30;
|
|
66
|
-
if (x == 1) return 0;
|
|
67
|
-
double y = (x - 1.0) / (x + 1.0);
|
|
68
|
-
double y2 = y * y;
|
|
69
|
-
double sum = y;
|
|
70
|
-
double term = y;
|
|
71
|
-
for (int i = 1; i < 40; i++) {
|
|
72
|
-
term *= y2;
|
|
73
|
-
sum += term / (2.0 * i + 1.0);
|
|
74
|
-
}
|
|
75
|
-
return 2.0 * sum;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
double rt_log2(double x) { return rt_log(x) / rt_log(2.0); }
|
|
79
|
-
double rt_log10(double x) { return rt_log(x) / rt_log(10.0); }
|
|
80
|
-
|
|
81
|
-
/* ------------------------------------------------------------
|
|
82
|
-
* double rt_pow(double base, double exp)
|
|
83
|
-
* ------------------------------------------------------------ */
|
|
84
|
-
double rt_pow(double base, double exp) {
|
|
85
|
-
if (exp == 0) return 1;
|
|
86
|
-
if (base == 0) return 0;
|
|
87
|
-
return rt_exp(exp * rt_log(base));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/* ------------------------------------------------------------
|
|
91
|
-
* double rt_sin(double x) -- 泰勒展开 (先归约到 [-pi, pi])
|
|
92
|
-
* ------------------------------------------------------------ */
|
|
93
|
-
double rt_sin(double x) {
|
|
94
|
-
/* 范围归约 */
|
|
95
|
-
while (x > PI) x -= PI2;
|
|
96
|
-
while (x < -PI) x += PI2;
|
|
97
|
-
double x2 = x * x;
|
|
98
|
-
double s = x;
|
|
99
|
-
double term = x;
|
|
100
|
-
for (int i = 1; i < 15; i++) {
|
|
101
|
-
term *= -x2 / (2.0 * i * (2.0 * i + 1.0));
|
|
102
|
-
s += term;
|
|
103
|
-
}
|
|
104
|
-
return s;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
double rt_cos(double x) {
|
|
108
|
-
return rt_sin(x + PI / 2.0);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
double rt_tan(double x) {
|
|
112
|
-
double c = rt_cos(x);
|
|
113
|
-
if (c < EPS && c > -EPS) return 1e30;
|
|
114
|
-
return rt_sin(x) / c;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/* ------------------------------------------------------------
|
|
118
|
-
* 随机数 (线性同余, 简单快速)
|
|
119
|
-
* ------------------------------------------------------------ */
|
|
120
|
-
static unsigned int rng_state = 1;
|
|
121
|
-
|
|
122
|
-
void rt_srand(unsigned int seed) {
|
|
123
|
-
rng_state = seed;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
int rt_rand(void) {
|
|
127
|
-
rng_state = rng_state * 1103515245u + 12345u;
|
|
128
|
-
return (int)(rng_state & 0x7fffffff);
|
|
129
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/* ============================================================
|
|
2
|
-
* coCN 运行时 —— 打印函数
|
|
3
|
-
* - 64KB 缓冲, 批量 write 系统调用
|
|
4
|
-
* - 查表法 itoa: 一次处理 2 位数字
|
|
5
|
-
* ============================================================ */
|
|
6
|
-
#include "rt.h"
|
|
7
|
-
|
|
8
|
-
#define BUF_SIZE 65536
|
|
9
|
-
|
|
10
|
-
static char pbuf[BUF_SIZE];
|
|
11
|
-
static int poff = 0;
|
|
12
|
-
|
|
13
|
-
void rt_flush(void) {
|
|
14
|
-
if (poff > 0) {
|
|
15
|
-
rt_write(1, pbuf, (size_t)poff);
|
|
16
|
-
poff = 0;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
void rt_print_char(char c) {
|
|
21
|
-
if (poff >= BUF_SIZE) rt_flush();
|
|
22
|
-
pbuf[poff++] = c;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
void rt_print_newline(void) {
|
|
26
|
-
rt_print_char('\n');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
void rt_print_str(const char *s) {
|
|
30
|
-
while (*s) {
|
|
31
|
-
if (poff >= BUF_SIZE) rt_flush();
|
|
32
|
-
pbuf[poff++] = *s++;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/* ------------------------------------------------------------
|
|
37
|
-
* 查表: 00..99 的两位 ASCII 表示
|
|
38
|
-
* ------------------------------------------------------------ */
|
|
39
|
-
static const char digits[200] =
|
|
40
|
-
"00010203040506070809"
|
|
41
|
-
"10111213141516171819"
|
|
42
|
-
"20212223242526272829"
|
|
43
|
-
"30313233343536373839"
|
|
44
|
-
"40414243444546474849"
|
|
45
|
-
"50515253545556575859"
|
|
46
|
-
"60616263646566676869"
|
|
47
|
-
"70717273747576777879"
|
|
48
|
-
"80818283848586878889"
|
|
49
|
-
"90919293949596979899";
|
|
50
|
-
|
|
51
|
-
/* ------------------------------------------------------------
|
|
52
|
-
* 无符号长整型 -> 字符串 (查表法, 一次 2 位)
|
|
53
|
-
* ------------------------------------------------------------ */
|
|
54
|
-
static void append_ulong(unsigned long n) {
|
|
55
|
-
char tmp[24];
|
|
56
|
-
int len = 0;
|
|
57
|
-
|
|
58
|
-
if (n == 0) {
|
|
59
|
-
tmp[len++] = '0';
|
|
60
|
-
} else {
|
|
61
|
-
/* 一次处理 2 位数字 */
|
|
62
|
-
while (n >= 100) {
|
|
63
|
-
unsigned q = n / 100;
|
|
64
|
-
unsigned r = n - q * 100;
|
|
65
|
-
tmp[len++] = digits[r * 2 + 1];
|
|
66
|
-
tmp[len++] = digits[r * 2];
|
|
67
|
-
n = q;
|
|
68
|
-
}
|
|
69
|
-
/* 剩余 1-2 位 */
|
|
70
|
-
if (n >= 10) {
|
|
71
|
-
unsigned r = n;
|
|
72
|
-
tmp[len++] = digits[r * 2 + 1];
|
|
73
|
-
tmp[len++] = digits[r * 2];
|
|
74
|
-
} else {
|
|
75
|
-
tmp[len++] = '0' + (char)n;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/* 逆序输出 */
|
|
80
|
-
for (int i = len - 1; i >= 0; i--)
|
|
81
|
-
rt_print_char(tmp[i]);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
void rt_print_uint(unsigned int n) {
|
|
85
|
-
append_ulong(n);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
void rt_print_ulong(unsigned long n) {
|
|
89
|
-
append_ulong(n);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
void rt_print_int(int n) {
|
|
93
|
-
if (n < 0) {
|
|
94
|
-
rt_print_char('-');
|
|
95
|
-
append_ulong((unsigned long)(-(unsigned int)n));
|
|
96
|
-
} else {
|
|
97
|
-
append_ulong((unsigned long)n);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
void rt_print_long(long n) {
|
|
102
|
-
if (n < 0) {
|
|
103
|
-
rt_print_char('-');
|
|
104
|
-
append_ulong((unsigned long)(-(unsigned long)n));
|
|
105
|
-
} else {
|
|
106
|
-
append_ulong((unsigned long)n);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
void rt_print_bool(int b) {
|
|
111
|
-
if (b) rt_print_str("真");
|
|
112
|
-
else rt_print_str("假");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/* ------------------------------------------------------------
|
|
116
|
-
* void rt_print_double(double d)
|
|
117
|
-
* 简单实现: 整数部分 + 6 位小数
|
|
118
|
-
* ------------------------------------------------------------ */
|
|
119
|
-
void rt_print_double(double d) {
|
|
120
|
-
if (d != d) { rt_print_str("NaN"); return; }
|
|
121
|
-
if (d < 0) { rt_print_char('-'); d = -d; }
|
|
122
|
-
|
|
123
|
-
long whole = (long)d;
|
|
124
|
-
double frac = d - (double)whole;
|
|
125
|
-
|
|
126
|
-
append_ulong((unsigned long)whole);
|
|
127
|
-
rt_print_char('.');
|
|
128
|
-
|
|
129
|
-
for (int i = 0; i < 6; i++) {
|
|
130
|
-
frac *= 10.0;
|
|
131
|
-
int digit = (int)frac;
|
|
132
|
-
rt_print_char('0' + (char)digit);
|
|
133
|
-
frac -= digit;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/* ============================================================
|
|
2
|
-
* coCN 轻量级原生运行时 —— 公共头文件
|
|
3
|
-
* 纯 freestanding 环境:不依赖 libc,直接系统调用
|
|
4
|
-
* 目标:比 glibc 更快的内存分配与字符串操作
|
|
5
|
-
* ============================================================ */
|
|
6
|
-
#ifndef RT_H
|
|
7
|
-
#define RT_H
|
|
8
|
-
|
|
9
|
-
/* ---------- 基础类型(freestanding,不引入 stddef.h/stdint.h) ---------- */
|
|
10
|
-
typedef unsigned long size_t;
|
|
11
|
-
typedef long ssize_t;
|
|
12
|
-
typedef unsigned long uintptr_t;
|
|
13
|
-
typedef unsigned char uint8_t;
|
|
14
|
-
typedef unsigned short uint16_t;
|
|
15
|
-
typedef unsigned int uint32_t;
|
|
16
|
-
typedef unsigned long long uint64_t;
|
|
17
|
-
/* int64_t 不自定义: SSE2 头文件会从系统 stdint 引入, 避免冲突 */
|
|
18
|
-
|
|
19
|
-
#ifndef NULL
|
|
20
|
-
#define NULL ((void *)0)
|
|
21
|
-
#endif
|
|
22
|
-
|
|
23
|
-
#define likely(x) __builtin_expect(!!(x), 1)
|
|
24
|
-
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
25
|
-
|
|
26
|
-
/* ---------- 系统调用封装(来自 syscall.asm) ---------- */
|
|
27
|
-
/* ssize_t rt_write(int fd, const void *buf, size_t count); */
|
|
28
|
-
long rt_write(int fd, const void *buf, size_t count);
|
|
29
|
-
/* void rt_exit(int code) __attribute__((noreturn)); */
|
|
30
|
-
void rt_exit(int code);
|
|
31
|
-
/* void *rt_mmap(void *addr, size_t len, int prot, int flags, int fd, long offset); */
|
|
32
|
-
void *rt_mmap(void *addr, size_t len, int prot, int flags, int fd, long offset);
|
|
33
|
-
/* void *rt_mremap(void *old_addr, size_t old_size, size_t new_size, int flags); */
|
|
34
|
-
void *rt_mremap(void *old_addr, size_t old_size, size_t new_size, int flags);
|
|
35
|
-
/* int rt_munmap(void *addr, size_t len); */
|
|
36
|
-
int rt_munmap(void *addr, size_t len);
|
|
37
|
-
/* int rt_brk(void *addr); */
|
|
38
|
-
long rt_brk(void *addr);
|
|
39
|
-
/* int rt_open(const char *path, int flags, int mode); */
|
|
40
|
-
int rt_open(const char *path, int flags, int mode);
|
|
41
|
-
/* ssize_t rt_read(int fd, void *buf, size_t count); */
|
|
42
|
-
long rt_read(int fd, void *buf, size_t count);
|
|
43
|
-
/* int rt_close(int fd); */
|
|
44
|
-
int rt_close(int fd);
|
|
45
|
-
/* long rt_gettimeofday(void); 返回微秒时间戳 */
|
|
46
|
-
long rt_gettimeofday(void);
|
|
47
|
-
/* long rt_monotonic_us(void); 返回单调时钟微秒(用于 benchmark) */
|
|
48
|
-
long rt_monotonic_us(void);
|
|
49
|
-
|
|
50
|
-
/* mmap 常量(x86-64 Linux) */
|
|
51
|
-
#define RT_PROT_READ 0x1
|
|
52
|
-
#define RT_PROT_WRITE 0x2
|
|
53
|
-
#define RT_MAP_PRIVATE 0x02
|
|
54
|
-
#define RT_MAP_ANON 0x20
|
|
55
|
-
#define RT_FD_ANON (-1)
|
|
56
|
-
|
|
57
|
-
/* ---------- 内存分配器(alloc.c) ---------- */
|
|
58
|
-
void *rt_alloc(size_t size);
|
|
59
|
-
void rt_free(void *ptr);
|
|
60
|
-
void *rt_realloc(void *ptr, size_t size);
|
|
61
|
-
void *rt_calloc(size_t nmemb, size_t size);
|
|
62
|
-
|
|
63
|
-
/* ---------- 字符串操作(string.c) ---------- */
|
|
64
|
-
size_t rt_strlen(const char *s);
|
|
65
|
-
char *rt_strcpy(char *dst, const char *src);
|
|
66
|
-
char *rt_strncpy(char *dst, const char *src, size_t n);
|
|
67
|
-
char *rt_strcat(char *dst, const char *src);
|
|
68
|
-
int rt_strcmp(const char *a, const char *b);
|
|
69
|
-
int rt_strncmp(const char *a, const char *b, size_t n);
|
|
70
|
-
char *rt_strdup(const char *s);
|
|
71
|
-
char *rt_str_concat(const char *a, const char *b);
|
|
72
|
-
char *rt_str_sub(const char *s, int start, int len);
|
|
73
|
-
int rt_str_index(const char *s, const char *needle);
|
|
74
|
-
char *rt_str_replace(const char *s, const char *from, const char *to);
|
|
75
|
-
char **rt_str_split(const char *s, char delim, int *out_count);
|
|
76
|
-
char *rt_str_join(char **parts, int count, const char *sep);
|
|
77
|
-
|
|
78
|
-
/* 编译器可能隐式调用的内存原语 */
|
|
79
|
-
void *rt_memset(void *dst, int c, size_t n);
|
|
80
|
-
void *rt_memcpy(void *dst, const void *src, size_t n);
|
|
81
|
-
void *rt_memmove(void *dst, const void *src, size_t n);
|
|
82
|
-
int rt_memcmp(const void *a, const void *b, size_t n);
|
|
83
|
-
|
|
84
|
-
/* ---------- 列表 list.c ---------- */
|
|
85
|
-
typedef struct {
|
|
86
|
-
int length;
|
|
87
|
-
int capacity;
|
|
88
|
-
void **items;
|
|
89
|
-
} rt_list_t;
|
|
90
|
-
|
|
91
|
-
rt_list_t *rt_list_create(void);
|
|
92
|
-
void rt_list_append(rt_list_t *l, void *val);
|
|
93
|
-
void *rt_list_get(rt_list_t *l, int idx);
|
|
94
|
-
void rt_list_set(rt_list_t *l, int idx, void *val);
|
|
95
|
-
int rt_list_length(rt_list_t *l);
|
|
96
|
-
void *rt_list_pop(rt_list_t *l);
|
|
97
|
-
void rt_list_insert(rt_list_t *l, int idx, void *val);
|
|
98
|
-
void rt_list_remove(rt_list_t *l, int idx);
|
|
99
|
-
rt_list_t *rt_list_concat(rt_list_t *a, rt_list_t *b);
|
|
100
|
-
rt_list_t *rt_list_slice(rt_list_t *l, int start, int end);
|
|
101
|
-
void rt_list_sort(rt_list_t *l, int (*cmp)(void *a, void *b));
|
|
102
|
-
|
|
103
|
-
/* 内部: 扩容 (list.c 中定义) */
|
|
104
|
-
void _rt_list_reserve(rt_list_t *l, int newcap);
|
|
105
|
-
|
|
106
|
-
/* 热点路径内联: append/get/set/length/pop 可被编译器内联 */
|
|
107
|
-
static inline void rt_list_append_inline(rt_list_t *l, void *val) {
|
|
108
|
-
if (unlikely(l->length >= l->capacity))
|
|
109
|
-
_rt_list_reserve(l, l->capacity * 2);
|
|
110
|
-
l->items[l->length++] = val;
|
|
111
|
-
}
|
|
112
|
-
static inline void *rt_list_get_inline(rt_list_t *l, int idx) {
|
|
113
|
-
if (idx < 0 || idx >= l->length) return NULL;
|
|
114
|
-
return l->items[idx];
|
|
115
|
-
}
|
|
116
|
-
static inline int rt_list_length_inline(rt_list_t *l) {
|
|
117
|
-
return l->length;
|
|
118
|
-
}
|
|
119
|
-
static inline void *rt_list_pop_inline(rt_list_t *l) {
|
|
120
|
-
if (l->length <= 0) return NULL;
|
|
121
|
-
return l->items[--l->length];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/* ---------- 字典 dict.c ---------- */
|
|
125
|
-
typedef struct {
|
|
126
|
-
char *key;
|
|
127
|
-
void *val;
|
|
128
|
-
int used; /* 1=占用, 0=空, -1=已删除(墓碑) */
|
|
129
|
-
} rt_entry_t;
|
|
130
|
-
|
|
131
|
-
typedef struct {
|
|
132
|
-
int size;
|
|
133
|
-
int capacity;
|
|
134
|
-
rt_entry_t *buckets;
|
|
135
|
-
} rt_dict_t;
|
|
136
|
-
|
|
137
|
-
rt_dict_t *rt_dict_create(void);
|
|
138
|
-
void *rt_dict_get(rt_dict_t *d, const char *key);
|
|
139
|
-
int rt_dict_set(rt_dict_t *d, const char *key, void *val);
|
|
140
|
-
void *rt_dict_remove(rt_dict_t *d, const char *key);
|
|
141
|
-
int rt_dict_contains(rt_dict_t *d, const char *key);
|
|
142
|
-
int rt_dict_size(rt_dict_t *d);
|
|
143
|
-
rt_list_t *rt_dict_keys(rt_dict_t *d);
|
|
144
|
-
rt_list_t *rt_dict_values(rt_dict_t *d);
|
|
145
|
-
|
|
146
|
-
/* ---------- 打印 print.c ---------- */
|
|
147
|
-
void rt_print_int(int n);
|
|
148
|
-
void rt_print_uint(unsigned int n);
|
|
149
|
-
void rt_print_long(long n);
|
|
150
|
-
void rt_print_ulong(unsigned long n);
|
|
151
|
-
void rt_print_double(double d);
|
|
152
|
-
void rt_print_str(const char *s);
|
|
153
|
-
void rt_print_bool(int b);
|
|
154
|
-
void rt_print_newline(void);
|
|
155
|
-
void rt_print_char(char c);
|
|
156
|
-
void rt_flush(void);
|
|
157
|
-
|
|
158
|
-
/* ---------- 数学 math.c ---------- */
|
|
159
|
-
int rt_abs(int n);
|
|
160
|
-
int rt_min(int a, int b);
|
|
161
|
-
int rt_max(int a, int b);
|
|
162
|
-
double rt_pow(double base, double exp);
|
|
163
|
-
double rt_sqrt(double x);
|
|
164
|
-
double rt_sin(double x);
|
|
165
|
-
double rt_cos(double x);
|
|
166
|
-
double rt_tan(double x);
|
|
167
|
-
double rt_log(double x);
|
|
168
|
-
double rt_log2(double x);
|
|
169
|
-
double rt_log10(double x);
|
|
170
|
-
double rt_exp(double x);
|
|
171
|
-
double rt_floor(double x);
|
|
172
|
-
double rt_ceil(double x);
|
|
173
|
-
double rt_round(double x);
|
|
174
|
-
int rt_rand(void);
|
|
175
|
-
void rt_srand(unsigned int seed);
|
|
176
|
-
|
|
177
|
-
#endif /* RT_H */
|