comparison dowa/dowa.h @ 60:d64a8c189a77

Merged
author June Park <me@mrjunejune.com>
date Sat, 20 Dec 2025 13:56:01 -0500
parents e06bc03d9618
children fff1b048dda6
comparison
equal deleted inserted replaced
50:983769fba767 60:d64a8c189a77
4 #include <stdio.h> 4 #include <stdio.h>
5 #include <string.h> // stdup 5 #include <string.h> // stdup
6 #include <stdlib.h> // only for malloc, free, stuff 6 #include <stdlib.h> // only for malloc, free, stuff
7 #include <assert.h> // mostly for TODO 7 #include <assert.h> // mostly for TODO
8 #include <dirent.h> // some functions loop through files 8 #include <dirent.h> // some functions loop through files
9 #include <math.h> // I am not re-writing stuff I guess...
9 10
10 #include <sys/stat.h> 11 #include <sys/stat.h>
11 #include <limits.h> 12 #include <limits.h>
12 13
13 #include "dowa_internal.h" 14 #include "dowa_internal.h"
52 extern void *Dowa_Arena_Allocate(Dowa_PArena arena, size_t size); 53 extern void *Dowa_Arena_Allocate(Dowa_PArena arena, size_t size);
53 /* Destroys the arena and frees its underlying memory block.*/ 54 /* Destroys the arena and frees its underlying memory block.*/
54 extern void Dowa_Arena_Destroy(Dowa_PArena arena); 55 extern void Dowa_Arena_Destroy(Dowa_PArena arena);
55 /* Strdup but saves within the arena */ 56 /* Strdup but saves within the arena */
56 extern void *Dowa_Arena_Copy(Dowa_PArena p_arena, const void *src, size_t size); 57 extern void *Dowa_Arena_Copy(Dowa_PArena p_arena, const void *src, size_t size);
58 /* Resets the arena offset to 0, allowing reuse without freeing */
59 extern void Dowa_Arena_Reset(Dowa_PArena p_arena);
60 /* Returns the current number of bytes allocated in the arena */
61 extern size_t Dowa_Arena_Get_Used(Dowa_PArena p_arena);
62 /* Returns the remaining capacity in bytes */
63 extern size_t Dowa_Arena_Get_Remaining(Dowa_PArena p_arena);
57 64
58 65
59 // --- HashMap --- // 66 // --- HashMap --- //
60 typedef enum { 67 typedef enum {
61 DOWA_HASH_MAP_TYPE_BUFFER, // Raw byte buffer 68 DOWA_HASH_MAP_TYPE_BUFFER, // Raw byte buffer
62 DOWA_HASH_MAP_TYPE_STRING, // Null-terminated string 69 DOWA_HASH_MAP_TYPE_STRING, // Null-terminated string
63 DOWA_HASH_MAP_TYPE_HASHMAP, // Nested hashmap 70 DOWA_HASH_MAP_TYPE_HASHMAP, // Nested hashmap
64 DOWA_HASH_MAP_TYPE_INT // Integer value 71 DOWA_HASH_MAP_TYPE_INT // Integer value
65 } Dowa_HashMap_ValueType; 72 } Dowa_HashMap_ValueType;
66 73
67 typedef struct { 74 typedef struct Dowa_HashEntry {
68 char *key; 75 char *key;
69 void *buffer; 76 void *buffer;
70 size_t capacity; 77 size_t capacity;
71 Dowa_HashMap_ValueType type; 78 Dowa_HashMap_ValueType type;
72 struct Dowa_HashEntry *next; 79 struct Dowa_HashEntry *next;
95 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); 102 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);
96 /* 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. */ 103 /* 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. */
97 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); 104 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);
98 /* Removes the entry with the specified key from the hashmap and frees its data if owned. */ 105 /* Removes the entry with the specified key from the hashmap and frees its data if owned. */
99 extern void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, const char *key); 106 extern void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, const char *key);
107 /* Returns TRUE if the key exists in the hashmap, FALSE otherwise. */
108 extern boolean Dowa_HashMap_Has_Key(Dowa_PHashMap p_hash_map, const char *key);
109 /* Removes all entries from the hashmap without destroying it. */
110 extern void Dowa_HashMap_Clear(Dowa_PHashMap p_hash_map);
111 /* Returns the number of entries currently in the hashmap. */
112 extern uint32 Dowa_HashMap_Get_Count(Dowa_PHashMap p_hash_map);
100 113
101 // --- Utility Functions --- // 114 // --- Utility Functions --- //
102 /* Prints all entries in the hashmap to stdout for debugging purposes. */ 115 /* Prints all entries in the hashmap to stdout for debugging purposes. */
103 extern void Dowa_HashMap_Print(Dowa_PHashMap map); 116 extern void Dowa_HashMap_Print(Dowa_PHashMap map);
104 /* 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. */ 117 /* 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. */