Mercurial
diff dowa/d_memory.c @ 21:09def63429b9
[Dowa] Updated the naming scheme and tests.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Mon, 06 Oct 2025 10:57:30 -0700 |
| parents | 0a9e67c7039a |
| children | 947b81010aba |
line wrap: on
line diff
--- a/dowa/d_memory.c Mon Oct 06 10:13:41 2025 -0700 +++ b/dowa/d_memory.c Mon Oct 06 10:57:30 2025 -0700 @@ -26,7 +26,7 @@ return currnet_ptr; } -void Dowa_Arena_Destory(Dowa_PArena p_arena) +void Dowa_Arena_Destroy(Dowa_PArena p_arena) { if (p_arena) { @@ -56,10 +56,10 @@ return p_hash_map; } -Dowa_PHashMap Dowa_HashMap_Create(size_t capacity, Dowa_PArena p_arena) +Dowa_PHashMap Dowa_HashMap_Create_With_Arena(size_t capacity, Dowa_PArena p_arena) { if (p_arena == NULL) - printf("Arena is NULL"); + printf("Arena is NULL\n"); return Dowa_HashMap_Create(capacity); Dowa_PHashMap p_hash_map; @@ -80,12 +80,12 @@ return p_hash_map; } -void Dowa_HashMap_Destory(Dowa_PHashMap p_hash_map) +void Dowa_HashMap_Destroy(Dowa_PHashMap p_hash_map) { if (!p_hash_map) return; if (p_hash_map->p_arena) - Dowa_Arena_Destory(p_hash_map->p_arena); + Dowa_Arena_Destroy(p_hash_map->p_arena); else { Dowa_PHashEntry entry; @@ -107,7 +107,7 @@ free(p_hash_map); } -int32 Dowa_HashMap_Get_Position(Dowa_PHashMap p_hash_map, char *key) +int32 Dowa_HashMap_Get_Position(Dowa_PHashMap p_hash_map, const char *key) { int32 hash_val = HASH_KEY_NUMBER; int32 c; @@ -118,7 +118,7 @@ return hash_val % p_hash_map->capacity; } -void *Dowa_HashMap_Get(Dowa_PHashMap p_hash_map, char *key) +void *Dowa_HashMap_Get(Dowa_PHashMap p_hash_map, const char *key) { int idx_foo = Dowa_HashMap_Get_Position(p_hash_map, key); void *value = p_hash_map->entries[idx_foo]; @@ -129,9 +129,11 @@ return ((Dowa_PHashEntry) value)->buffer; } -int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type) +int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_PHashMap p_hash_map, const char *key, + void *value, size_t value_size, + Dowa_HashMap_ValueType type) { - int idx = Dowa_HashMap_GetPosition(p_hash_map, key); + int idx = Dowa_HashMap_Get_Position(p_hash_map, key); Dowa_PHashEntry entry = p_hash_map->entries[idx]; if (entry) free(entry->buffer); @@ -152,9 +154,11 @@ return 0; } -int32 Dowa_HashMap_Push_Value_With_Type(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type) +int32 Dowa_HashMap_Push_Value_With_Type(Dowa_PHashMap p_hash_map, const char *key, + void *value, size_t value_size, + Dowa_HashMap_ValueType type) { - int idx = Dowa_HashMap_GetPosition(p_hash_map, key); + int idx = Dowa_HashMap_Get_Position(p_hash_map, key); Dowa_PHashEntry entry = p_hash_map->entries[idx]; if (entry) free(entry->buffer); @@ -180,14 +184,14 @@ return 0; } -void Dowa_HashMap_Push_Value(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size) +void Dowa_HashMap_Push_Value(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size) { Dowa_HashMap_Push_Value_With_Type(p_hash_map, key, value, value_size, DOWA_HASH_MAP_TYPE_BUFFER); } -void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, char *key) +void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, const char *key) { - int idx = Dowa_HashMap_GetPosition(p_hash_map, key); + int idx = Dowa_HashMap_Get_Position(p_hash_map, key); Dowa_PHashEntry entry = p_hash_map->entries[idx]; if (entry) { @@ -273,8 +277,8 @@ if (!f) { perror("fopen"); continue; } void *buf = p_hash_map->p_arena ? - Dowa_Arena_Allocate(p_hash_map->p_arena, value_size) : - malloc(value_size); + Dowa_Arena_Allocate(p_hash_map->p_arena, size) : + malloc(size); if (!buf) { perror("malloc"); fclose(f); closedir(dir); return -1; } if (fread(buf, 1, size, f) != size) @@ -286,12 +290,12 @@ } fclose(f); - Dowa_HashMap_PushValueWithType(p_hash_map, entry->d_name, buf, size, DOWA_HASH_MAP_TYPE_STRING); + Dowa_HashMap_Push_Value_With_Type(p_hash_map, entry->d_name, buf, size, DOWA_HASH_MAP_TYPE_STRING); free(buf); // Dowa_HashMap_PushValue made its own copy } else if (S_ISDIR(st.st_mode)) { - Dowa_PHashMap p_child_map = Dowa_HashMap_Create(100, p_hash_map->p_arena); + Dowa_PHashMap p_child_map = Dowa_HashMap_Create_With_Arena(100, p_hash_map->p_arena); if (!p_child_map) { perror("Dowa_HashMap_Create"); @@ -307,7 +311,7 @@ if (Dowa_HashMap_Push_Value_With_Type_NoCopy(p_hash_map, entry->d_name, p_child_map, sizeof(p_child_map), DOWA_HASH_MAP_TYPE_HASHMAP) == -1) { - Dowa_HashMap_Destory(p_child_map); + Dowa_HashMap_Destroy(p_child_map); return -1; } }