Mercurial
diff dowa/dowa.h @ 65:ecb6ee6a22c3
[Misc] I will no longer drink cool aids of capital P.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 24 Dec 2025 06:22:59 -0800 |
| parents | a30944e5719e |
| children | 75de5903355c |
line wrap: on
line diff
--- a/dowa/dowa.h Tue Dec 23 15:18:46 2025 -0800 +++ b/dowa/dowa.h Wed Dec 24 06:22:59 2025 -0800 @@ -45,22 +45,22 @@ char *buffer; size_t offset; size_t capacity; -} Dowa_Arena, *Dowa_PArena; +} Dowa_Arena; /* Creates a new arena with the specified capacity (in bytes). Returns a pointer to the arena, or NULL on failure. */ -extern Dowa_PArena Dowa_Arena_Create(size_t capacity); +extern Dowa_Arena *Dowa_Arena_Create(size_t capacity); /* Allocates a block of memory of the given size from the arena. Returns pointer to the allocated memory, or NULL if there is insufficient space. */ -extern void *Dowa_Arena_Allocate(Dowa_PArena arena, size_t size); +extern void *Dowa_Arena_Allocate(Dowa_Arena *arena, size_t size); /* Destroys the arena and frees its underlying memory block.*/ -extern void Dowa_Arena_Destroy(Dowa_PArena arena); +extern void Dowa_Arena_Destroy(Dowa_Arena *arena); /* Strdup but saves within the arena */ -extern void *Dowa_Arena_Copy(Dowa_PArena p_arena, const void *src, size_t size); +extern void *Dowa_Arena_Copy(Dowa_Arena *p_arena, const void *src, size_t size); /* Resets the arena offset to 0, allowing reuse without freeing */ -extern void Dowa_Arena_Reset(Dowa_PArena p_arena); +extern void Dowa_Arena_Reset(Dowa_Arena *p_arena); /* Returns the current number of bytes allocated in the arena */ -extern size_t Dowa_Arena_Get_Used(Dowa_PArena p_arena); +extern size_t Dowa_Arena_Get_Used(Dowa_Arena *p_arena); /* Returns the remaining capacity in bytes */ -extern size_t Dowa_Arena_Get_Remaining(Dowa_PArena p_arena); +extern size_t Dowa_Arena_Get_Remaining(Dowa_Arena *p_arena); // --- HashMap --- // @@ -72,44 +72,44 @@ } Dowa_HashMap_ValueType; typedef struct Dowa_HashEntry { - char *key; - void *buffer; - size_t capacity; - Dowa_HashMap_ValueType type; - struct Dowa_HashEntry *next; -} Dowa_HashEntry, *Dowa_PHashEntry; + char *key; + void *buffer; + size_t capacity; + Dowa_HashMap_ValueType type; + struct Dowa_HashEntry *next; +} Dowa_HashEntry; typedef struct { - Dowa_PHashEntry *entries; + Dowa_HashEntry **entries; size_t capacity; uint32 current_capacity; - Dowa_PArena p_arena; -} Dowa_HashMap, *Dowa_PHashMap; + Dowa_Arena *p_arena; +} Dowa_HashMap; /* Creates a new hashmap with the given initial capacity. Returns pointer to the hashmap, or NULL on failure. */ -extern Dowa_PHashMap Dowa_HashMap_Create(size_t capacity); +extern Dowa_HashMap *Dowa_HashMap_Create(size_t capacity); /* Creates a new hashmap with the given initial capacity, using the provided arena for all internal allocations. Returns pointer to the hashmap, or NULL on failure. */ -extern Dowa_PHashMap Dowa_HashMap_Create_With_Arena(size_t capacity, Dowa_PArena arena); +extern Dowa_HashMap *Dowa_HashMap_Create_With_Arena(size_t capacity, Dowa_Arena *arena); /* Destroys the hashmap and frees all associated memory */ -extern void Dowa_HashMap_Destroy(Dowa_PHashMap p_hash_map); +extern void Dowa_HashMap_Destroy(Dowa_HashMap *p_hash_map); /* Returns the index of the entry for the specified key, or -1 if the key is not found. */ -extern int32 Dowa_HashMap_Get_Position(Dowa_PHashMap p_hash_map, const char *key); +extern int32 Dowa_HashMap_Get_Position(Dowa_HashMap *p_hash_map, const char *key); /* Retrieves the value buffer for the specified key, or NULL if the key does not exist. */ -extern void *Dowa_HashMap_Get(Dowa_PHashMap p_hash_map, const char *key); +extern void *Dowa_HashMap_Get(Dowa_HashMap *p_hash_map, const char *key); /* Inserts a copy of the given value into the hashmap under the specified key. Uses DOWA_HASH_MAP_TYPE_BUFFER as the entry type. */ -extern void Dowa_HashMap_Push_Value(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size); +extern void Dowa_HashMap_Push_Value(Dowa_HashMap *p_hash_map, const char *key, void *value, size_t value_size); /* Inserts a copy of the given value with the specified type into the hashmap under the key. Returns the index of the new entry, or -1 on failure. */ -extern 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); +extern int32 Dowa_HashMap_Push_Value_With_Type(Dowa_HashMap *p_hash_map, const char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); /* Inserts a value pointer into the hashmap under the specified key without copying data. The caller retains ownership of the pointer. Returns the entry index, or -1 on failure. */ -extern 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); +extern int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_HashMap *p_hash_map, const char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); /* Removes the entry with the specified key from the hashmap and frees its data if owned. */ -extern void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, const char *key); +extern void Dowa_HashMap_Pop_Key(Dowa_HashMap *p_hash_map, const char *key); /* Returns TRUE if the key exists in the hashmap, FALSE otherwise. */ -extern boolean Dowa_HashMap_Has_Key(Dowa_PHashMap p_hash_map, const char *key); +extern boolean Dowa_HashMap_Has_Key(Dowa_HashMap *p_hash_map, const char *key); /* Removes all entries from the hashmap without destroying it. */ -extern void Dowa_HashMap_Clear(Dowa_PHashMap p_hash_map); +extern void Dowa_HashMap_Clear(Dowa_HashMap *p_hash_map); /* Returns the number of entries currently in the hashmap. */ -extern uint32 Dowa_HashMap_Get_Count(Dowa_PHashMap p_hash_map); +extern uint32 Dowa_HashMap_Get_Count(Dowa_HashMap *p_hash_map); // --- String manipuliation -- // // Splice string from start to end @@ -119,10 +119,10 @@ // --- Utility Functions --- // /* Prints all entries in the hashmap to stdout for debugging purposes. */ -extern void Dowa_HashMap_Print(Dowa_PHashMap map); +extern void Dowa_HashMap_Print(Dowa_HashMap *map); #ifdef DIRECTORY /* Loads all files from the specified folder into the hashmap. Uses file names as keys and file contents as values. Returns 0 on success, or -1 on failure. */ -extern int Dowa_HashMap_Cache_Folder(Dowa_PHashMap map, const char *folder_path); +extern int Dowa_HashMap_Cache_Folder(Dowa_HashMap *map, const char *folder_path); #endif