#include void scc_strpool_init(scc_strpool_t *pool) { pool->ht.hash_func = (u32 (*)(const void *))scc_strhash32; pool->ht.key_cmp = (int (*)(const void *, const void *))scc_strcmp; scc_hashtable_init(&pool->ht); } const char *scc_strpool_intern(scc_strpool_t *pool, const char *str) { void *existing = scc_hashtable_get(&pool->ht, str); if (existing) { return existing; } usize len = scc_strlen(str) + 1; char *new_str = scc_malloc(len); if (!new_str) { LOG_ERROR("strpool: Failed to allocate memory for string"); return NULL; } scc_memcpy(new_str, str, len); scc_hashtable_set(&pool->ht, new_str, new_str); return new_str; } void scc_strpool_drop(scc_strpool_t *pool) { scc_hashtable_drop(&pool->ht); } void scc_strpool_foreach(scc_strpool_t *pool, scc_strpool_iter_fn iter_func, void *context) { scc_hashtable_foreach(&pool->ht, (scc_hashtable_iter_fn)iter_func, context); }