Mercurial
comparison dowa/dowa.h @ 5:3e12bf044589
Fixed Dowa hashmap to recursively add files into memory.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Sat, 27 Sep 2025 16:23:04 -0700 |
| parents | 2758f5527d2b |
| children | fa2b8af609d9 |
comparison
equal
deleted
inserted
replaced
| 4:0b3b4f5887bb | 5:3e12bf044589 |
|---|---|
| 11 #include <limits.h> | 11 #include <limits.h> |
| 12 | 12 |
| 13 #include "dowa_internal.h" | 13 #include "dowa_internal.h" |
| 14 | 14 |
| 15 #define HASH_KEY_NUMBER 5381 // DJD hash number | 15 #define HASH_KEY_NUMBER 5381 // DJD hash number |
| 16 | 16 #define ONE_MEGA_BYTE 1048576 |
| 17 typedef unsigned int uint32; | 17 typedef unsigned int uint32; |
| 18 typedef int int32; | 18 typedef int int32; |
| 19 typedef unsigned short uint16; | 19 typedef unsigned short uint16; |
| 20 typedef short int16; | 20 typedef short int16; |
| 21 typedef unsigned char uint8; | 21 typedef unsigned char uint8; |
| 28 // --- Arena --- // | 28 // --- Arena --- // |
| 29 typedef struct { | 29 typedef struct { |
| 30 char *buffer; | 30 char *buffer; |
| 31 size_t offset; | 31 size_t offset; |
| 32 size_t capacity; | 32 size_t capacity; |
| 33 } Dowa_Areana, *Dowa_PArena; | 33 } Dowa_Arena, *Dowa_PArena; |
| 34 | 34 |
| 35 extern Dowa_PArena Dowa_Arena_Initialize(size_t capacity); | 35 extern Dowa_PArena Dowa_Arena_Create(size_t capacity); |
| 36 extern void *Dowa_Arena_Allocate(Dowa_PArena p_arena, size_t size); | 36 extern void *Dowa_Arena_Allocate(Dowa_PArena p_arena, size_t size); |
| 37 extern void Dowa_Arena_Free(Dowa_PArena p_arena); | 37 extern void Dowa_Arena_Free(Dowa_PArena p_arena); |
| 38 | 38 |
| 39 // --- Map --- // | 39 // --- HashMap --- // |
| 40 typedef enum { | 40 typedef enum { |
| 41 DOWA_TYPE_BUFFER, | 41 DOWA_HASH_MAP_TYPE_BUFFER, |
| 42 DOWA_TYPE_STRING, | 42 DOWA_HASH_MAP_TYPE_STRING, |
| 43 DOWA_TYPE_INT, | 43 DOWA_HASH_MAP_TYPE_HASHMAP, |
| 44 } Dowa_ValueType; | 44 DOWA_HASH_MAP_TYPE_INT, |
| 45 } Dowa_HashMap_ValueType; | |
| 45 | 46 |
| 46 typedef struct { | 47 typedef struct { |
| 47 char *key; | 48 char *key; |
| 48 void *buffer; | 49 void *buffer; |
| 49 size_t capacity; | 50 size_t capacity; |
| 50 Dowa_ValueType type; | 51 Dowa_HashMap_ValueType type; |
| 51 } Dowa_HashEntry, *Dowa_PHashEntry; | 52 } Dowa_HashEntry, *Dowa_PHashEntry; |
| 52 | 53 |
| 53 typedef struct { | 54 typedef struct { |
| 54 Dowa_PHashEntry *entries; | 55 Dowa_PHashEntry *entries; |
| 55 size_t capacity; | 56 size_t capacity; |
| 56 uint32 current_capacity; | 57 uint32 current_capacity; |
| 57 } Dowa_HashMap, *Dowa_PHashMap; | 58 } Dowa_HashMap, *Dowa_PHashMap; |
| 58 | 59 |
| 59 extern Dowa_PHashMap Dowa_HashMap_Create(size_t capacity); | 60 extern Dowa_PHashMap Dowa_HashMap_Create(size_t capacity); |
| 60 extern int32 Dowa_HashMap_GetPosition(Dowa_PHashMap p_hash_map, char *key); | 61 extern void Dowa_HashMap_Free(Dowa_PHashMap p_hash_map); |
| 61 extern void Dowa_HashMap_PushValue(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size); | 62 extern int32 Dowa_HashMap_GetPosition(Dowa_PHashMap p_hash_map, char *key); |
| 62 extern void Dowa_HashMap_PushValueWithType(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_ValueType type); | 63 extern void *Dowa_HashMap_Get(Dowa_PHashMap p_hash_map, char *key); |
| 63 extern void Dowa_HashMap_PopKey(Dowa_PHashMap p_hash_map, char *key); | 64 extern void Dowa_HashMap_PushValue(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size); |
| 65 extern int32 Dowa_HashMap_PushValueWithTypeNoCopy(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); | |
| 66 extern int32 Dowa_HashMap_PushValueWithType(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); | |
| 67 extern void Dowa_HashMap_PopKey(Dowa_PHashMap p_hash_map, char *key); | |
| 64 | 68 |
| 65 // --- Maybe Useful --- // | 69 // --- Maybe Useful --- // |
| 66 extern void Dowa_HashMap_Print(Dowa_PHashMap map); | 70 extern void Dowa_HashMap_Print(Dowa_PHashMap map); |
| 67 // 0 for success, -1 for failure. | 71 // 0 for success, -1 for failure. Get all files in the folder into key and vlaues. |
| 68 extern int Dowa_Cache_Folder(Dowa_PHashMap map, const char *folder_path); | 72 extern int Dowa_HashMap_Cache_Folder(Dowa_PHashMap map, const char *folder_path); |
| 69 | 73 |
| 70 | 74 |
| 71 #endif | 75 #endif |