feat(lib): 添加哈希表实现及相关测试功能

🐛 fix(main): 修改OLED显示位置和配置
📝 docs(demo/list/test.c): 更新测试文件,添加哈希表测试用例
This commit is contained in:
JiXieShi
2024-12-16 23:40:13 +08:00
parent 3709d3d284
commit 23116b7e3d
7 changed files with 240 additions and 7 deletions

36
lib/list/inc/hash_table.h Normal file
View File

@@ -0,0 +1,36 @@
#pragma once
#ifndef HW_LIB_HASH_TABLE_H
#define HW_LIB_HASH_TABLE_H
#ifdef __cplusplus
extern "C" {
#endif
#define HT_PRIME_1 151
#define HT_PRIME_2 163
#define HT_INITIAL_BASE_SIZE 53
typedef struct Hash_Item
{
char* key;
char* value;
} Hash_Item_t;
typedef struct Hash_Table
{
int base_size;
int size;
int count;
Hash_Item_t** items;
} Hash_Table_t;
Hash_Table_t* ht_new();
void ht_del_hash_table(Hash_Table_t* ht);
void ht_insert(Hash_Table_t* ht, const char* key, const char* value);
char* ht_search(Hash_Table_t* ht, const char* key);
void ht_delete(Hash_Table_t* h, const char* key);
#ifdef __cplusplus
}
#endif
#endif //HW_LIB_HASH_TABLE_H