2023_open_source_contest_warmup_1st_issue1

This commit is contained in:
jager 2023-06-28 13:38:34 +08:00
parent 6e9ffb0b39
commit 616633eb0a
18 changed files with 173 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -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)
测试完毕