#include "strpool.h" void init_strpool(strpool_t *pool) { pool->ht.hash_func = (u32 (*)(const void *))smcc_strhash32; pool->ht.key_cmp = (int (*)(const void *, const void *))smcc_strcmp; hashmap_init(&pool->ht); } const char *strpool_intern(strpool_t *pool, const char *str) { void *existing = hashmap_get(&pool->ht, str); if (existing) { return existing; } usize len = smcc_strlen(str) + 1; char *new_str = smcc_malloc(len); if (!new_str) { LOG_ERROR("strpool: Failed to allocate memory for string"); return NULL; } smcc_memcpy(new_str, str, len); hashmap_set(&pool->ht, new_str, new_str); return new_str; } void strpool_destroy(strpool_t *pool) { hashmap_drop(&pool->ht); }