Mercurial
diff dowa/dowa.h @ 5:3e12bf044589
Fixed Dowa hashmap to recursively add files into memory.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Sat, 27 Sep 2025 16:23:04 -0700 |
| parents | 2758f5527d2b |
| children | fa2b8af609d9 |
line wrap: on
line diff
--- a/dowa/dowa.h Fri Sep 26 15:14:46 2025 -0700 +++ b/dowa/dowa.h Sat Sep 27 16:23:04 2025 -0700 @@ -13,7 +13,7 @@ #include "dowa_internal.h" #define HASH_KEY_NUMBER 5381 // DJD hash number - +#define ONE_MEGA_BYTE 1048576 typedef unsigned int uint32; typedef int int32; typedef unsigned short uint16; @@ -30,24 +30,25 @@ char *buffer; size_t offset; size_t capacity; -} Dowa_Areana, *Dowa_PArena; +} Dowa_Arena, *Dowa_PArena; -extern Dowa_PArena Dowa_Arena_Initialize(size_t capacity); +extern Dowa_PArena Dowa_Arena_Create(size_t capacity); extern void *Dowa_Arena_Allocate(Dowa_PArena p_arena, size_t size); extern void Dowa_Arena_Free(Dowa_PArena p_arena); -// --- Map --- // +// --- HashMap --- // typedef enum { - DOWA_TYPE_BUFFER, - DOWA_TYPE_STRING, - DOWA_TYPE_INT, -} Dowa_ValueType; + DOWA_HASH_MAP_TYPE_BUFFER, + DOWA_HASH_MAP_TYPE_STRING, + DOWA_HASH_MAP_TYPE_HASHMAP, + DOWA_HASH_MAP_TYPE_INT, +} Dowa_HashMap_ValueType; typedef struct { char *key; void *buffer; size_t capacity; - Dowa_ValueType type; + Dowa_HashMap_ValueType type; } Dowa_HashEntry, *Dowa_PHashEntry; typedef struct { @@ -56,16 +57,19 @@ uint32 current_capacity; } Dowa_HashMap, *Dowa_PHashMap; -extern Dowa_PHashMap Dowa_HashMap_Create(size_t capacity); -extern int32 Dowa_HashMap_GetPosition(Dowa_PHashMap p_hash_map, char *key); -extern void Dowa_HashMap_PushValue(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size); -extern void Dowa_HashMap_PushValueWithType(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_ValueType type); -extern void Dowa_HashMap_PopKey(Dowa_PHashMap p_hash_map, char *key); +extern Dowa_PHashMap Dowa_HashMap_Create(size_t capacity); +extern void Dowa_HashMap_Free(Dowa_PHashMap p_hash_map); +extern int32 Dowa_HashMap_GetPosition(Dowa_PHashMap p_hash_map, char *key); +extern void *Dowa_HashMap_Get(Dowa_PHashMap p_hash_map, char *key); +extern void Dowa_HashMap_PushValue(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size); +extern int32 Dowa_HashMap_PushValueWithTypeNoCopy(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); +extern int32 Dowa_HashMap_PushValueWithType(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); +extern void Dowa_HashMap_PopKey(Dowa_PHashMap p_hash_map, char *key); // --- Maybe Useful --- // extern void Dowa_HashMap_Print(Dowa_PHashMap map); -// 0 for success, -1 for failure. -extern int Dowa_Cache_Folder(Dowa_PHashMap map, const char *folder_path); +// 0 for success, -1 for failure. Get all files in the folder into key and vlaues. +extern int Dowa_HashMap_Cache_Folder(Dowa_PHashMap map, const char *folder_path); #endif