ADD file via upload
This commit is contained in:
parent
578a5d4689
commit
cb0ac9226f
|
@ -0,0 +1,99 @@
|
||||||
|
# ##基于cortex-m3-emulator实现哈希表并测试验证##
|
||||||
|
|
||||||
|
## 1. 简介
|
||||||
|
|
||||||
|
利用c语言实现了哈希表(HashMap),包括添加键值对(defaultPut),获取键对应的值(defaultGet), 删除健(defaultRemove),判断键是否存在(defaultExists),清空哈希表(defaultClear)等功能操作。
|
||||||
|
利用数组(Entry)作为存储空间,利用链表(*next)解决冲突。当哈希表的大小超过数组大小时,为避免冲突过多,可以扩充哈希表。
|
||||||
|
|
||||||
|
## 2. 数据结构设计说明
|
||||||
|
1.键值对结构
|
||||||
|
|
||||||
|
```c
|
||||||
|
typedef struct entry {
|
||||||
|
void* key; //键
|
||||||
|
void* value; //值
|
||||||
|
struct entry* next; //冲突链表
|
||||||
|
} * Entry;
|
||||||
|
```
|
||||||
|
2.哈希结构
|
||||||
|
|
||||||
|
```c
|
||||||
|
typedef struct hashMap {
|
||||||
|
int size; // 当前大小
|
||||||
|
int listSize; // 有效空间大小
|
||||||
|
int (*hashCode)(void*); // 哈希函数
|
||||||
|
int (*equal)(void*, void*); // 判等函数
|
||||||
|
Entry list; // 存储区域
|
||||||
|
void (*put)(struct hashMap*, void*, void*); // 添加键的函数
|
||||||
|
void* (*get)(struct hashMap*, void*); // 获取键对应值的函数
|
||||||
|
void (*remove)(struct hashMap*, void*); // 删除键
|
||||||
|
void (*clear)(struct hashMap*); // 清空Map
|
||||||
|
int (*exists)(struct hashMap*, void*); // 判断键是否存在
|
||||||
|
int autoAssign; // 设定是否根据当前数据量动态调整内存大小,默认开启
|
||||||
|
} * HashMap;
|
||||||
|
```
|
||||||
|
包括以下函数功能,分别为:
|
||||||
|
```c
|
||||||
|
createHashMap:创建一个哈希结构
|
||||||
|
defaultPut:添加键值对
|
||||||
|
defaultGet:获取键对应值
|
||||||
|
defaultRemove:删除指定键的键值对
|
||||||
|
defaultClear:清空Map的函数类型
|
||||||
|
defaultExists:判断键值是否存在
|
||||||
|
resetHashMap:重新构建哈希表
|
||||||
|
```
|
||||||
|
## 3. 测试程序说明
|
||||||
|
```c
|
||||||
|
1.测试了哈希表的添加键值对(defaultPut)
|
||||||
|
2.检查键是否存在(defaultExists)
|
||||||
|
3.获取键对应的值(defaultGet)
|
||||||
|
4.移除键值对(defaultRemove)
|
||||||
|
5.清空哈希表(defaultClear)等操作
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. 运行结果
|
||||||
|
|
||||||
|
1.在Linux命令行中执行以下命令,在menuconfig界面输入(/)查找test_hashmap位置
|
||||||
|
|
||||||
|
```c
|
||||||
|
cd ./Ubiquitous/XiZi_IIoT
|
||||||
|
make BOARD=cortex-m3-emulator distclean
|
||||||
|
make BOARD=cortex-m3-emulator menuconfig
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2.在menuconfig界面配置需要关闭和开启的功能,这里将test_hashmap开启(y),保存后双击快捷键ESC退出配置
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
3.继续执行以下命令,进行编译,生成配置文件
|
||||||
|
|
||||||
|
```
|
||||||
|
make BOARD=cortex-m3-emulator
|
||||||
|
```
|
||||||
|

|
||||||
|
|
||||||
|
4.编译正确无误,产生XiZi-cortex-m3-emulator.elf、XiZi-cortex-m3-emulator.bin文件。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
5.将XiZi-cortex-m3-emulator.bin文件复制至Windows实验目录。连接矽璓硬件终端至电脑后,启动K-Flash烧录系统
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
6.reset成功,K-Flash Terminal命令行界面如下
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
7.在弹出的终端中输入Help,验证Hash_Map注册Shell命令
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
8.执行Hash_Map命令,打印测试结果。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
如图所示,功能实现成功
|
Loading…
Reference in New Issue