smcc/lib/utils/ds/hashtable.h
ZZY 2b4857001c feat(frontend): 重构词法分析器
- 添加 .gitignore 文件,忽略编译器生成的二进制文件
- 重构 lexer.c 文件,改进了关键字处理和字符串处理
- 更新前端的前端、解析器和 AST 相关文件,以适应新的词法分析器
- 优化了 token 相关的定义和函数,引入了新的 token 类型
2025-03-23 12:13:16 +08:00

40 lines
1.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __SMCC_HASHTABLE_H__
#define __SMCC_HASHTABLE_H__
#include <lib/rt/rt_alloc.h>
#include "vector.h"
// 哈希表条目状态标记
typedef enum hash_table_entry_state {
ENTRY_EMPTY,
ENTRY_ACTIVE,
ENTRY_TOMBSTONE
} ht_entry_state_t;
// 哈希表条目结构不管理key/value内存
typedef struct hash_entry {
const void* key; // 由调用者管理
void* value; // 由调用者管理
u32_t hash; // 预计算哈希值
ht_entry_state_t state; // 条目状态
} hash_entry_t;
// 哈希表主体结构
typedef struct hash_table {
vector_header(entries, hash_entry_t); // 使用vector管理条目
u32_t count; // 有效条目数(不含墓碑)
u32_t tombstone_count; // 墓碑数量
u32_t (*hash_func)(const void* key);
int(*key_cmp)(const void* key1, const void* key2);
} hash_table_t;
// WARN you need set hash_func and key_cmp before use
void hashtable_init(hash_table_t* ht) ;
void* hashtable_set(hash_table_t* ht, const void* key, void* value);
void* hashtable_get(hash_table_t* ht, const void* key);
void* hashtable_get(hash_table_t* ht, const void* key);
void hashtable_destory(hash_table_t* ht);
#endif // __SMCC_HASHTABLE_H__