Mercurial
diff 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 |
line wrap: on
line diff
--- a/dowa/dowa.h Mon Oct 06 10:57:30 2025 -0700 +++ b/dowa/dowa.h Tue Oct 07 07:11:02 2025 -0700 @@ -34,9 +34,9 @@ // --- Arena Allocator --- // typedef struct { - char *buffer; - size_t offset; - size_t capacity; + char *buffer; + size_t offset; + size_t capacity; } Dowa_Arena, *Dowa_PArena; /* Creates a new arena with the specified capacity (in bytes). Returns a pointer to the arena, or NULL on failure. */ @@ -45,21 +45,24 @@ extern void *Dowa_Arena_Allocate(Dowa_PArena arena, size_t size); /* Destroys the arena and frees its underlying memory block.*/ extern void Dowa_Arena_Destroy(Dowa_PArena arena); +/* Strdup but saves within the arena */ +extern void *Dowa_Arena_Copy(Dowa_PArena p_arena, const void *src, size_t size); // --- HashMap --- // typedef enum { - DOWA_HASH_MAP_TYPE_BUFFER, // Raw byte buffer - DOWA_HASH_MAP_TYPE_STRING, // Null-terminated string - DOWA_HASH_MAP_TYPE_HASHMAP, // Nested hashmap - DOWA_HASH_MAP_TYPE_INT // Integer value + DOWA_HASH_MAP_TYPE_BUFFER, // Raw byte buffer + DOWA_HASH_MAP_TYPE_STRING, // Null-terminated string + DOWA_HASH_MAP_TYPE_HASHMAP, // Nested hashmap + DOWA_HASH_MAP_TYPE_INT // Integer value } Dowa_HashMap_ValueType; typedef struct { - char *key; - void *buffer; - size_t capacity; - Dowa_HashMap_ValueType type; + char *key; + void *buffer; + size_t capacity; + Dowa_HashMap_ValueType type; + struct Dowa_HashEntry *next; } Dowa_HashEntry, *Dowa_PHashEntry; typedef struct {