Mercurial
comparison dowa/dowa.h @ 2:8a43dedbe530
[Dowa] Added HashMap and Updated Arena naming.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 24 Sep 2025 13:15:32 -0700 |
| parents | adcfad6e86fb |
| children | 2758f5527d2b |
comparison
equal
deleted
inserted
replaced
| 1:adcfad6e86fb | 2:8a43dedbe530 |
|---|---|
| 1 #ifndef DOWA | 1 #ifndef DOWA |
| 2 #define DOWA | 2 #define DOWA |
| 3 | 3 |
| 4 #include <stdio.h> | 4 #include <stdio.h> |
| 5 #include <string.h> // stdup | |
| 5 #include <stdlib.h> // only for malloc, free, stuff | 6 #include <stdlib.h> // only for malloc, free, stuff |
| 7 #include <assert.h> | |
| 6 #include "dowa_internal.h" | 8 #include "dowa_internal.h" |
| 9 | |
| 10 #define HASH_KEY_NUMBER 5381 // DJD hash number | |
| 7 | 11 |
| 8 typedef unsigned int uint32; | 12 typedef unsigned int uint32; |
| 9 typedef int int32; | 13 typedef int int32; |
| 10 typedef unsigned short uint16; | 14 typedef unsigned short uint16; |
| 11 typedef short int16; | 15 typedef short int16; |
| 19 // --- Arena --- // | 23 // --- Arena --- // |
| 20 typedef struct { | 24 typedef struct { |
| 21 char *buffer; | 25 char *buffer; |
| 22 size_t offset; | 26 size_t offset; |
| 23 size_t capacity; | 27 size_t capacity; |
| 24 } Areana, *PArena; | 28 } Dowa_Areana, *Dowa_PArena; |
| 25 | 29 |
| 26 void Dowa_ArenaIntialize(PArena p_arena, size_t capacity); | 30 extern Dowa_PArena Dowa_Arena_Initialize(size_t capacity); |
| 27 void *Dowa_ArenaAllocate(PArena p_arena, size_t size); | 31 extern void *Dowa_Arena_Allocate(Dowa_PArena p_arena, size_t size); |
| 28 void Dowa_ArenaFree(PArena p_arena); | 32 extern void Dowa_Arena_Free(Dowa_PArena p_arena); |
| 33 | |
| 34 // --- Map --- // | |
| 35 typedef struct { | |
| 36 char *key; | |
| 37 void *buffer; | |
| 38 size_t capacity; | |
| 39 } Dowa_HashEntry, *Dowa_PHashEntry; | |
| 40 | |
| 41 typedef struct { | |
| 42 Dowa_PHashEntry *entries; | |
| 43 size_t capacity; | |
| 44 uint32 current_capacity; | |
| 45 } Dowa_HashMap, *Dowa_PHashMap; | |
| 46 | |
| 47 extern Dowa_PHashMap Dowa_HashMap_Create(size_t capacity); | |
| 48 extern int32 Dowa_HashMap_GetPosition(Dowa_PHashMap p_hash_map, char *key); | |
| 49 extern void Dowa_HashMap_PushValue(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size); | |
| 50 extern void Dowa_HashMap_PopKey(Dowa_PHashMap p_hash_map, char *key); | |
| 51 | |
| 29 | 52 |
| 30 #endif | 53 #endif |