#include "test_support.h"
int main(void){
puts("MBSKY | mbsky.com | independently authored C11 case");
Hash h={0};int out;CHECK(hash_put(&h,1,100));CHECK(hash_put(&h,11,300));CHECK(hash_put(&h,-9,-1));CHECK(hash_get(&h,1,&out)&&out==100);CHECK(hash_get(&h,11,&out)&&out==300);CHECK(hash_get(&h,-9,&out)&&out==-1);CHECK(!hash_get(&h,99,&out));CHECK(hash_put(&h,1,999));CHECK(hash_get(&h,1,&out)&&out==999);state("collision-keys",(int[]){1,11,-9},3);state("collision-values",(int[]){999,300,-1},3);CHECK(hash_delete(&h,11));CHECK(!hash_get(&h,11,&out));CHECK(hash_get(&h,1,&out)&&out==999);allocation_fail_after(0);CHECK(!hash_put(&h,21,4));allocation_fail_after(-1);hash_clear(&h);OpenHash o={0};CHECK(open_put(&o,1,10));CHECK(open_put(&o,11,20));CHECK(open_put(&o,21,30));CHECK(open_delete(&o,11));CHECK(open_get(&o,21,&out)&&out==30);CHECK(open_put(&o,31,40));CHECK(open_get(&o,31,&out)&&out==40);CHECK(open_put(&o,21,33));CHECK(open_get(&o,21,&out)&&out==33);state("tombstone-reuse",(int[]){o.state[1],o.state[2],o.state[3]},3);OpenHash full={0};for(int i=0;i<BUCKETS;++i)CHECK(open_put(&full,i,i));CHECK(!open_put(&full,101,7));CHECK(!open_get(&full,111,&out));
return finish();
}
本例需在 Windows,Zig0.14.1 cc,C11 -Wall -Wextra -Werror -pedantic -g -O0;浏览器独立状态回放 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows,Zig0.14.1 cc,C11 -Wall -Wextra -Werror -pedantic -g -O0;浏览器独立状态回放
入口文件:projects/dsa-lab/c-dsa-hash-table.c
预期结果与验证条件观察提示
- 本章固定输入命名断言通过,编译和执行无未处置诊断
- 自有分配器存活计数归零,值/顺序/状态和错误分支符合明确约定;不等同全部内存与全部输入证明
请结合实际环境逐项观察。
附件与关联工程包下载
课程关联工程包(登记关联20章) · 含当前章节或实例 · mbskycom202611a545.zip