comparison dowa/dowa.h @ 22:947b81010aba

[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
author June Park <parkjune1995@gmail.com>
date Tue, 07 Oct 2025 07:11:02 -0700
parents 09def63429b9
children 84672efec192
comparison
equal deleted inserted replaced
21:09def63429b9 22:947b81010aba
32 char *Dowa_Int32ToString(uint32 value, char *buffer); 32 char *Dowa_Int32ToString(uint32 value, char *buffer);
33 33
34 34
35 // --- Arena Allocator --- // 35 // --- Arena Allocator --- //
36 typedef struct { 36 typedef struct {
37 char *buffer; 37 char *buffer;
38 size_t offset; 38 size_t offset;
39 size_t capacity; 39 size_t capacity;
40 } Dowa_Arena, *Dowa_PArena; 40 } Dowa_Arena, *Dowa_PArena;
41 41
42 /* Creates a new arena with the specified capacity (in bytes). Returns a pointer to the arena, or NULL on failure. */ 42 /* Creates a new arena with the specified capacity (in bytes). Returns a pointer to the arena, or NULL on failure. */
43 extern Dowa_PArena Dowa_Arena_Create(size_t capacity); 43 extern Dowa_PArena Dowa_Arena_Create(size_t capacity);
44 /* 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. */ 44 /* 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. */
45 extern void *Dowa_Arena_Allocate(Dowa_PArena arena, size_t size); 45 extern void *Dowa_Arena_Allocate(Dowa_PArena arena, size_t size);
46 /* Destroys the arena and frees its underlying memory block.*/ 46 /* Destroys the arena and frees its underlying memory block.*/
47 extern void Dowa_Arena_Destroy(Dowa_PArena arena); 47 extern void Dowa_Arena_Destroy(Dowa_PArena arena);
48 /* Strdup but saves within the arena */
49 extern void *Dowa_Arena_Copy(Dowa_PArena p_arena, const void *src, size_t size);
48 50
49 51
50 // --- HashMap --- // 52 // --- HashMap --- //
51 typedef enum { 53 typedef enum {
52 DOWA_HASH_MAP_TYPE_BUFFER, // Raw byte buffer 54 DOWA_HASH_MAP_TYPE_BUFFER, // Raw byte buffer
53 DOWA_HASH_MAP_TYPE_STRING, // Null-terminated string 55 DOWA_HASH_MAP_TYPE_STRING, // Null-terminated string
54 DOWA_HASH_MAP_TYPE_HASHMAP, // Nested hashmap 56 DOWA_HASH_MAP_TYPE_HASHMAP, // Nested hashmap
55 DOWA_HASH_MAP_TYPE_INT // Integer value 57 DOWA_HASH_MAP_TYPE_INT // Integer value
56 } Dowa_HashMap_ValueType; 58 } Dowa_HashMap_ValueType;
57 59
58 typedef struct { 60 typedef struct {
59 char *key; 61 char *key;
60 void *buffer; 62 void *buffer;
61 size_t capacity; 63 size_t capacity;
62 Dowa_HashMap_ValueType type; 64 Dowa_HashMap_ValueType type;
65 struct Dowa_HashEntry *next;
63 } Dowa_HashEntry, *Dowa_PHashEntry; 66 } Dowa_HashEntry, *Dowa_PHashEntry;
64 67
65 typedef struct { 68 typedef struct {
66 Dowa_PHashEntry *entries; 69 Dowa_PHashEntry *entries;
67 size_t capacity; 70 size_t capacity;