diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131058294.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131058294.png new file mode 100644 index 000000000..9029167d5 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131058294.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131132800.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131132800.png new file mode 100644 index 000000000..24159433a Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131132800.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131149737.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131149737.png new file mode 100644 index 000000000..74f77d60c Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131149737.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131221195.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131221195.png new file mode 100644 index 000000000..829ba7de9 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131221195.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131255814.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131255814.png new file mode 100644 index 000000000..c6cfcb895 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131255814.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131319213.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131319213.png new file mode 100644 index 000000000..bafbe8ba8 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131319213.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131327977.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131327977.png new file mode 100644 index 000000000..0dea82656 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131327977.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131348882.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131348882.png new file mode 100644 index 000000000..60e46fe47 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131348882.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131403511.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131403511.png new file mode 100644 index 000000000..e0c8295a1 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131403511.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131427721.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131427721.png new file mode 100644 index 000000000..eead259c2 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131427721.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131447209.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131447209.png new file mode 100644 index 000000000..f97895218 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131447209.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131505520.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131505520.png new file mode 100644 index 000000000..be8380328 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628131505520.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628132233620.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628132233620.png new file mode 100644 index 000000000..86c24f277 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628132233620.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133115520.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133115520.png new file mode 100644 index 000000000..fddafeffb Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133115520.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133135420.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133135420.png new file mode 100644 index 000000000..f07bf9cfc Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133135420.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133152340.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133152340.png new file mode 100644 index 000000000..61e8d63bb Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133152340.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133302284.png b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133302284.png new file mode 100644 index 000000000..61e3287cc Binary files /dev/null and b/APP_Framework/Applications/app_test/test_hash/README.assets/image-20230628133302284.png differ diff --git a/APP_Framework/Applications/app_test/test_hash/README.md b/APP_Framework/Applications/app_test/test_hash/README.md new file mode 100644 index 000000000..b8041d55e --- /dev/null +++ b/APP_Framework/Applications/app_test/test_hash/README.md @@ -0,0 +1,173 @@ +# 热身赛一级赛题1:基于cortex-m3-emulator实现哈希表并测试验证 + +参赛战队:bdislab_Rhodes 赛题issue:热身赛一级赛题1 完成情况:完成哈希表,支持链地址法解决哈希冲突 + +## 1. 简介 + +注册shell命令及哈希命令集说明 + +0.注册TestHash、creatHashTable命令,源文件见:xiuos/APP_Framework/Applications/app_test/test_hash/test_hash.c + +1.创建初始化哈希表 + +```QEMU +creatHashTable +``` + +说明: + +- 创建一个大小为10的哈希表并初始化 + +2.插入键值对(key,value) + +```QEMU +TestHash 1 key value +``` + +说明: + +- 根据key值进行哈希映射插入到哈希表中,若发生哈希冲突用链地址法解决哈希冲突 +- 若(key,value)已存在则不进行插入 +- 若key存在但value值不同,则替换value值 +- 注:key和value仅支持int类型 + +3.删除键值对(key,value) + +```QEMU +TestHash 2 key +``` + +说明: + +- 若哈希表中存在key值,则删除对应的(key,value)并显示success +- 若哈希表中找不到key值,则显示failed + +4.搜索key值 + +```QEMU +TestHash 3 key +``` + +说明: + +- 若哈希表中存在key值,则返回对应的(key,value)对 +- 若哈希表中不存在key值,则显示“query key(key),not exist” + +5.打印哈希表 + +```QEMU +TestHash 4 +``` + +说明: + +- 将当前哈希表打印出来 + +6.获取帮助 + +```QEMU +TestHash h +``` + +说明: + +- 获取帮助菜单 + +7.若输入的指令不符合上述任何一条则返回error + +## 2. 数据结构设计说明 + +首先设计了一个结构体Node表示每一个哈希节点,包含key值和value值,因为要使用链地址法解决哈希冲突,所以还要加上指向下一个节点的指针。然后又定义了哈希表的结构体,包含指向哈希节点指针的指针,即包含一系列指针的数组。 + +```C +#define TABLE_SIZE 10 //哈希表大小定为10 + +// 哈希节点 +typedef struct Node { + int key; + int value; + struct Node* next; +} Node; + +// 哈希表 +typedef struct HashTable { + Node** buckets; +} HashTable; +``` + +此外, + +```C +//创建哈希节点 +Node* createNode(int key, int value) +//创建并初始化哈希表 +HashTable* createHashTable() +//哈希函数 +int hashFunction(int key) +//搜索key值 +int search(HashTable* hashTable, int key) +//插入(key,value) +void insert(HashTable* hashTable, int key, int value) +//删除(key,value) +int removeEntry(HashTable* hashTable, int key) +//打印当前哈希表 +void printHashTable(HashTable* hashTable) +``` + +## 3. 测试程序说明 + +测试结果,打印验证功能,均正确 + +## 4. 运行结果(包含测试流程及截图) + +启动QEMU + +![image-20230628131058294](README.assets/image-20230628131058294.png) + +输入Help获取帮助,看到TestHash和createHashTable已经注册 + +![image-20230628131132800](README.assets/image-20230628131132800.png) + +输入createHashTable创建并初始化哈希表 + +![image-20230628131255814](README.assets/image-20230628131255814.png) + +输入TestHash h获取帮助 + +![image-20230628131221195](README.assets/image-20230628131221195.png) + +输入TestHash 1 2 12插入(2,12),显示插入成功。 + +![image-20230628133115520](README.assets/image-20230628133115520.png) + +输入TestHash 4查看当前哈希表状态,证明插入成功。 + +![image-20230628133152340](README.assets/image-20230628133152340.png) + +输入TestHash 1 2 10,将(2,12)修改为(2,10),再次打印哈希表证明修改成功 + +![image-20230628133302284](README.assets/image-20230628133302284.png) + +紧接着插入(5,15)和(55,77)并打印,再插入(65,12)并打印,均插入成功 + +![image-20230628131348882](README.assets/image-20230628131348882.png) + +![image-20230628131403511](README.assets/image-20230628131403511.png) + +输入TestHash 2 5删除(5,15)并打印,证明删除成功 + +![image-20230628131427721](README.assets/image-20230628131427721.png) + +删除表中不存在的key值4,显示failed + +![image-20230628132233620](README.assets/image-20230628132233620.png) + +查找key值55返回value值77,证明查找成功 + +![image-20230628131447209](README.assets/image-20230628131447209.png) + +查找哈希表中不存在的key值4,返回not exist + +![image-20230628131505520](README.assets/image-20230628131505520.png) + +测试完毕 \ No newline at end of file