31 lines
593 B
C
31 lines
593 B
C
#ifndef HASHMAP_H
|
||
#define HASHMAP_H
|
||
|
||
#define HMAP_SIZE 64
|
||
|
||
typedef struct HashMapEntry {
|
||
char* key;
|
||
void* value;
|
||
struct HashMapEntry* next;
|
||
} HashMapEntry;
|
||
|
||
typedef struct {
|
||
HashMapEntry* buckets[HMAP_SIZE];
|
||
} HashMap;
|
||
|
||
// 初始化哈希表
|
||
void hmap_init(HashMap* map);
|
||
|
||
// 插入键值对
|
||
void hmap_put(HashMap* map, const char* key, void* value);
|
||
|
||
// 查找键值
|
||
void* hmap_get(HashMap* map, const char* key);
|
||
|
||
// 检查键是否存在
|
||
int hmap_contains(HashMap* map, const char* key);
|
||
|
||
// 释放哈希表内存(不释放value)
|
||
void hmap_destroy(HashMap* map);
|
||
|
||
#endif |