forgot header

This commit is contained in:
Krzosa Karol
2025-01-20 10:24:10 +01:00
parent f863f847dc
commit 6f53fa4db0

View File

@@ -0,0 +1,53 @@
typedef struct ht_key_value_t ht_key_value_t;
struct ht_key_value_t {
union {
s8_t key_string;
u64 key_u64;
void *key_ptr;
};
union {
s8_t value_string;
void *value_ptr;
u64 value_u64;
};
};
typedef struct ht_node_t ht_node_t;
struct ht_node_t {
ht_node_t *next;
ht_key_value_t kv;
};
typedef struct ht_bucket_t ht_bucket_t;
struct ht_bucket_t {
ht_node_t *first;
ht_node_t *last;
};
typedef struct ht_t ht_t;
struct ht_t {
ma_arena_t *arena;
i32 item_count;
i32 bucket_count;
ht_bucket_t *buckets;
};
fn ht_t *ht_create(ma_arena_t *arena, i32 size);
fn ht_node_t *ht_insert_kv(ht_t *ht, u64 hash, ht_key_value_t kv);
fn ht_node_t *ht_insert_u64(ht_t *ht, u64 key, u64 value);
fn ht_node_t *ht_insert_ptr(ht_t *ht, void *key, void *value);
fn ht_node_t *ht_insert_string(ht_t *ht, s8_t key, s8_t value);
fn ht_node_t *ht_insert_string_ptr(ht_t *ht, s8_t key, void *value);
fn ht_node_t *ht_search_u64_ex(ht_t *ht, u64 key);
fn ht_node_t *ht_search_ptr_ex(ht_t *ht, void *key);
fn ht_node_t *ht_search_string_ex(ht_t *ht, s8_t key);
fn u64 *ht_search_u64(ht_t *ht, u64 key);
fn void **ht_search_ptr(ht_t *ht, void *key);
fn s8_t *ht_search_string(ht_t *ht, s8_t key);
fn void **ht_search_string_ptr(ht_t *ht, s8_t key);
///////////////////////////////
// string interning
#define s8i_t s8_t
fn s8i_t *intern_string(ht_t *ht, s8_t string);
fn s8i_t *internf(ht_t *ht, char *str, ...);