annotate dowa/d_memory.c @ 71:75de5903355c

Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
author June Park <parkjune1995@gmail.com>
date Sun, 28 Dec 2025 20:34:22 -0800
parents ecb6ee6a22c3
children 4532ce6d9eb8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1 #include "dowa.h"
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
3 // --- Arena --- //
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
4 Dowa_Arena *Dowa_Arena_Create(size_t capacity)
1
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
5 {
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
6 Dowa_Arena *p_arena = malloc(sizeof(Dowa_Arena));
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
7 if (p_arena == NULL)
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
8 {
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
9 perror("malloc");
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
10 return NULL;
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
11 }
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
12 p_arena->buffer = malloc(capacity);
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
13 if (p_arena->buffer == NULL)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
14 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
15 perror("malloc");
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
16 Dowa_Free(p_arena);
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
17 return NULL;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
18 }
1
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
19 p_arena->offset = 0;
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
20 p_arena->capacity = capacity;
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
21 return p_arena;
1
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
22 }
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
23
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
24 void *Dowa_Arena_Allocate(Dowa_Arena *p_arena, size_t size)
1
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
25 {
71
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
26 return Dowa_Arena_Allocate_Aligned(p_arena, size, sizeof(void*) * 2);
1
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
27 }
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
28
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
29 void Dowa_Arena_Destroy(Dowa_Arena *p_arena)
1
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
30 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
31 if (!p_arena) return;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
32
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
33 if (p_arena->buffer)
36
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
34 Dowa_Free(p_arena->buffer);
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
35 Dowa_Free(p_arena);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
36 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
37
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
38 void *Dowa_Arena_Copy(Dowa_Arena *p_arena, const void *src, size_t size)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
39 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
40 if (p_arena == NULL || src == NULL || size == 0)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
41 return NULL;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
42
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
43 void *dest = Dowa_Arena_Allocate(p_arena, size);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
44 if (!dest)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
45 return NULL;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
46
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
47 memcpy(dest, src, size);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
48 return dest;
1
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
49 }
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
50
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
51 void Dowa_Arena_Reset(Dowa_Arena *p_arena)
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
52 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
53 if (!p_arena) return;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
54 p_arena->offset = 0;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
55 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
56
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
57 size_t Dowa_Arena_Get_Used(Dowa_Arena *p_arena)
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
58 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
59 if (!p_arena) return 0;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
60 return p_arena->offset;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
61 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
62
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
63 size_t Dowa_Arena_Get_Remaining(Dowa_Arena *p_arena)
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
64 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
65 if (!p_arena) return 0;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
66 return p_arena->capacity - p_arena->offset;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
67 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
68
71
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
69 void *Dowa_Arena_Allocate_Aligned(Dowa_Arena *p_arena, size_t size, size_t alignment)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
70 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
71 if (!p_arena || !p_arena->buffer || size == 0 || alignment == 0)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
72 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
73
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
74 size_t current_address = (size_t)(p_arena->buffer + p_arena->offset);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
75 size_t aligned_address = (current_address + alignment - 1) & ~(alignment - 1);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
76 size_t padding = aligned_address - current_address;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
77
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
78 if (p_arena->offset + padding + size > p_arena->capacity)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
79 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
80
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
81 p_arena->offset += padding;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
82 void *p_result = p_arena->buffer + p_arena->offset;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
83 p_arena->offset += size;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
84 return p_result;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
85 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
86
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
87 // --- NEW stb_ds-style Array Implementation --- //
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
88
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
89 void* dowa__array_grow(void* p_array, size_t element_size, size_t minimum_capacity, Dowa_Arena* p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
90 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
91 Dowa_Array_Header* p_header;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
92 size_t new_capacity;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
93 size_t current_capacity;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
94
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
95 if (p_array)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
96 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
97 p_header = dowa__header(p_array);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
98 current_capacity = p_header->capacity;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
99
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
100 if (p_header->allocator_type == DOWA_ALLOCATOR_ARENA && p_header->p_arena != p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
101 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
102 fprintf(stderr, "Error: Cannot mix arena allocators\n");
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
103 return p_array;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
104 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
105 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
106 else
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
107 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
108 current_capacity = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
109 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
110
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
111 if (current_capacity >= minimum_capacity && p_array != NULL)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
112 return p_array;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
113
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
114 new_capacity = current_capacity * 2;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
115 if (new_capacity < 4)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
116 new_capacity = 4;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
117 if (new_capacity < minimum_capacity)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
118 new_capacity = minimum_capacity;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
119
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
120 size_t total_size = sizeof(Dowa_Array_Header) + (element_size * new_capacity);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
121
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
122 if (p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
123 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
124 // Array header and data must be properly aligned
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
125 size_t alignment = element_size >= 16 ? 16 : (element_size >= 8 ? 8 : element_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
126 Dowa_Array_Header* p_new_header = (Dowa_Array_Header*)Dowa_Arena_Allocate_Aligned(p_arena, total_size, alignment);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
127 if (!p_new_header)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
128 return p_array;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
129
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
130 void* p_new_array = (char*)p_new_header + sizeof(Dowa_Array_Header);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
131
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
132 if (p_array)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
133 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
134 memcpy(p_new_array, p_array, element_size * p_header->length);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
135 p_new_header->length = p_header->length;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
136 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
137 else
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
138 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
139 p_new_header->length = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
140 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
141
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
142 p_new_header->capacity = new_capacity;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
143 p_new_header->allocator_type = DOWA_ALLOCATOR_ARENA;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
144 p_new_header->p_arena = p_arena;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
145 p_new_header->p_hash = p_array ? p_header->p_hash : NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
146
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
147 return p_new_array;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
148 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
149 else
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
150 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
151 Dowa_Array_Header* p_new_header;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
152
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
153 if (p_array)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
154 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
155 p_header = dowa__header(p_array);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
156 p_new_header = (Dowa_Array_Header*)realloc(p_header, total_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
157 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
158 else
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
159 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
160 p_new_header = (Dowa_Array_Header*)malloc(total_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
161 if (p_new_header)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
162 p_new_header->length = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
163 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
164
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
165 if (!p_new_header)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
166 return p_array;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
167
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
168 p_new_header->capacity = new_capacity;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
169 p_new_header->allocator_type = DOWA_ALLOCATOR_MALLOC;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
170 p_new_header->p_arena = NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
171 p_new_header->p_hash = NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
172
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
173 return (char*)p_new_header + sizeof(Dowa_Array_Header);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
174 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
175 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
176
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
177 void dowa__array_free(void* p_array)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
178 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
179 if (!p_array)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
180 return;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
181
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
182 Dowa_Array_Header* p_header = dowa__header(p_array);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
183
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
184 if (p_header->allocator_type == DOWA_ALLOCATOR_MALLOC)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
185 free(p_header);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
186 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
187
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
188 // --- NEW stb_ds-style HashMap Implementation --- //
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
189
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
190 #define DOWA_HASH_EMPTY 0xFFFFFFFF
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
191 #define DOWA_HASH_TOMBSTONE 0xFFFFFFFE
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
192
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
193 uint32 dowa__hash_bytes(void* p_key, size_t key_size)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
194 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
195 uint32 hash = HASH_KEY_NUMBER;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
196 uint8* p_bytes = (uint8*)p_key;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
197
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
198 for (size_t i = 0; i < key_size; i++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
199 hash = ((hash << 5) + hash) + p_bytes[i];
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
200
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
201 if (hash == DOWA_HASH_EMPTY || hash == DOWA_HASH_TOMBSTONE)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
202 hash = HASH_KEY_NUMBER;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
203
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
204 return hash;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
205 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
206
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
207 static Dowa_Hash_Index* dowa__hashmap_get_index(void* p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
208 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
209 if (!p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
210 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
211
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
212 Dowa_Array_Header* p_header = dowa__header(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
213 return (Dowa_Hash_Index*)p_header->p_hash;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
214 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
215
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
216 static void* dowa__hashmap_find_slot(void* p_map, size_t element_size, void* p_key, size_t key_size, uint32 hash, boolean* p_found)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
217 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
218 Dowa_Hash_Index* p_index = dowa__hashmap_get_index(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
219 if (!p_index || !p_index->p_buckets)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
220 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
221 *p_found = FALSE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
222 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
223 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
224
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
225 size_t bucket_mask = p_index->bucket_count - 1;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
226 size_t bucket_index = hash & bucket_mask;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
227 size_t probe_step = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
228
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
229 while (1)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
230 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
231 Dowa_Hash_Bucket* p_bucket = &p_index->p_buckets[bucket_index];
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
232
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
233 for (size_t i = 0; i < DOWA_HASH_BUCKET_SIZE; i++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
234 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
235 if (p_bucket->hash[i] == DOWA_HASH_EMPTY)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
236 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
237 *p_found = FALSE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
238 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
239 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
240
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
241 if (p_bucket->hash[i] == hash && p_bucket->index[i] != DOWA_HASH_TOMBSTONE)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
242 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
243 uint32 array_index = p_bucket->index[i];
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
244 char* p_element = (char*)p_map + (array_index * element_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
245
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
246 char** p_stored_key_ptr = (char**)p_element;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
247 char* p_stored_key = *p_stored_key_ptr;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
248 char* p_search_key = (char*)p_key;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
249
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
250 if (memcmp(p_stored_key, p_search_key, key_size) == 0)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
251 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
252 *p_found = TRUE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
253 return p_element;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
254 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
255 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
256 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
257
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
258 probe_step++;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
259 bucket_index = (hash + (probe_step * probe_step)) & bucket_mask;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
260
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
261 if (probe_step > p_index->bucket_count)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
262 break;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
263 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
264
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
265 *p_found = FALSE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
266 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
267 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
268
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
269 void* dowa__hashmap_get_ptr(void* p_map, size_t element_size, void* p_key, size_t key_size)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
270 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
271 if (!p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
272 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
273
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
274 uint32 hash = dowa__hash_bytes(p_key, key_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
275 boolean found = FALSE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
276 void* p_result = dowa__hashmap_find_slot(p_map, element_size, p_key, key_size, hash, &found);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
277
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
278 return found ? p_result : NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
279 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
280
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
281 void* dowa__hashmap_get(void* p_map, size_t element_size, void* p_key, size_t key_size)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
282 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
283 void* p_kv = dowa__hashmap_get_ptr(p_map, element_size, p_key, key_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
284 if (!p_kv)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
285 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
286
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
287 return (char*)p_kv + key_size;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
288 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
289
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
290 boolean dowa__hashmap_has_key(void* p_map, size_t element_size, void* p_key, size_t key_size)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
291 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
292 return dowa__hashmap_get_ptr(p_map, element_size, p_key, key_size) != NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
293 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
294
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
295 static void* dowa__hashmap_rehash(void* p_map, size_t element_size, size_t new_bucket_count, Dowa_Arena* p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
296 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
297 Dowa_Hash_Index* p_old_index = dowa__hashmap_get_index(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
298 if (!p_old_index)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
299 return p_map;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
300
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
301 size_t bucket_alloc_size = sizeof(Dowa_Hash_Bucket) * new_bucket_count;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
302 Dowa_Hash_Bucket* p_new_buckets;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
303
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
304 if (p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
305 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
306 p_new_buckets = (Dowa_Hash_Bucket*)Dowa_Arena_Allocate_Aligned(p_arena, bucket_alloc_size, DOWA_HASH_CACHE_LINE_SIZE);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
307 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
308 else
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
309 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
310 if (posix_memalign((void**)&p_new_buckets, DOWA_HASH_CACHE_LINE_SIZE, bucket_alloc_size) != 0)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
311 p_new_buckets = NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
312 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
313
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
314 if (!p_new_buckets)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
315 return p_map;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
316
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
317 for (size_t i = 0; i < new_bucket_count; i++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
318 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
319 for (size_t j = 0; j < DOWA_HASH_BUCKET_SIZE; j++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
320 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
321 p_new_buckets[i].hash[j] = DOWA_HASH_EMPTY;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
322 p_new_buckets[i].index[j] = DOWA_HASH_EMPTY;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
323 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
324 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
325
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
326 Dowa_Hash_Index* p_new_index;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
327 if (p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
328 p_new_index = (Dowa_Hash_Index*)Dowa_Arena_Allocate_Aligned(p_arena, sizeof(Dowa_Hash_Index), 16);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
329 else
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
330 p_new_index = (Dowa_Hash_Index*)malloc(sizeof(Dowa_Hash_Index));
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
331
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
332 if (!p_new_index)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
333 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
334 if (!p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
335 free(p_new_buckets);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
336 return p_map;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
337 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
338
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
339 p_new_index->bucket_count = new_bucket_count;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
340 p_new_index->item_count = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
341 p_new_index->tombstone_count = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
342 p_new_index->allocator_type = p_arena ? DOWA_ALLOCATOR_ARENA : DOWA_ALLOCATOR_MALLOC;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
343 p_new_index->p_arena = p_arena;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
344 p_new_index->p_buckets = p_new_buckets;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
345
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
346 size_t map_length = Dowa_Array_Length(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
347 for (size_t i = 0; i < map_length; i++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
348 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
349 char* p_element = (char*)p_map + (i * element_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
350 char** p_key_ptr = (char**)p_element;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
351 char* p_key_data = *p_key_ptr;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
352 uint32 hash = dowa__hash_bytes(p_key_data, strlen(p_key_data) + 1);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
353
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
354 size_t bucket_mask = new_bucket_count - 1;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
355 size_t bucket_index = hash & bucket_mask;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
356 size_t probe_step = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
357 boolean inserted = FALSE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
358
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
359 while (!inserted && probe_step <= new_bucket_count)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
360 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
361 Dowa_Hash_Bucket* p_bucket = &p_new_buckets[bucket_index];
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
362
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
363 for (size_t j = 0; j < DOWA_HASH_BUCKET_SIZE; j++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
364 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
365 if (p_bucket->hash[j] == DOWA_HASH_EMPTY)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
366 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
367 p_bucket->hash[j] = hash;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
368 p_bucket->index[j] = (uint32)i;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
369 p_new_index->item_count++;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
370 inserted = TRUE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
371 break;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
372 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
373 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
374
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
375 if (!inserted)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
376 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
377 probe_step++;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
378 bucket_index = (hash + (probe_step * probe_step)) & bucket_mask;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
379 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
380 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
381 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
382
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
383 if (p_old_index->allocator_type == DOWA_ALLOCATOR_MALLOC)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
384 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
385 if (p_old_index->p_buckets)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
386 free(p_old_index->p_buckets);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
387 free(p_old_index);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
388 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
389
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
390 dowa__header(p_map)->p_hash = p_new_index;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
391 return p_map;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
392 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
393
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
394 void* dowa__hashmap_push(void* p_map, size_t element_size, void* p_key, size_t key_size, Dowa_Arena* p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
395 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
396 uint32 hash = dowa__hash_bytes(p_key, key_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
397
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
398 if (p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
399 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
400 boolean found = FALSE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
401 dowa__hashmap_find_slot(p_map, element_size, p_key, key_size, hash, &found);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
402 if (found)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
403 return p_map;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
404 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
405
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
406 p_map = dowa__array_grow(p_map, element_size, 0, p_arena);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
407
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
408 Dowa_Hash_Index* p_index = dowa__hashmap_get_index(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
409 if (!p_index)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
410 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
411 size_t initial_bucket_count = 4;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
412 size_t bucket_alloc_size = sizeof(Dowa_Hash_Bucket) * initial_bucket_count;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
413 Dowa_Hash_Bucket* p_buckets;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
414
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
415 if (p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
416 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
417 p_buckets = (Dowa_Hash_Bucket*)Dowa_Arena_Allocate_Aligned(p_arena, bucket_alloc_size, DOWA_HASH_CACHE_LINE_SIZE);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
418 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
419 else
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
420 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
421 if (posix_memalign((void**)&p_buckets, DOWA_HASH_CACHE_LINE_SIZE, bucket_alloc_size) != 0)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
422 p_buckets = NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
423 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
424
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
425 if (!p_buckets)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
426 return p_map;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
427
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
428 for (size_t i = 0; i < initial_bucket_count; i++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
429 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
430 for (size_t j = 0; j < DOWA_HASH_BUCKET_SIZE; j++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
431 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
432 p_buckets[i].hash[j] = DOWA_HASH_EMPTY;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
433 p_buckets[i].index[j] = DOWA_HASH_EMPTY;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
434 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
435 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
436
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
437 if (p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
438 p_index = (Dowa_Hash_Index*)Dowa_Arena_Allocate_Aligned(p_arena, sizeof(Dowa_Hash_Index), 16);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
439 else
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
440 p_index = (Dowa_Hash_Index*)malloc(sizeof(Dowa_Hash_Index));
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
441
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
442 if (!p_index)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
443 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
444 if (!p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
445 free(p_buckets);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
446 return p_map;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
447 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
448
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
449 p_index->bucket_count = initial_bucket_count;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
450 p_index->item_count = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
451 p_index->tombstone_count = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
452 p_index->allocator_type = p_arena ? DOWA_ALLOCATOR_ARENA : DOWA_ALLOCATOR_MALLOC;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
453 p_index->p_arena = p_arena;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
454 p_index->p_buckets = p_buckets;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
455
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
456 dowa__header(p_map)->p_hash = p_index;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
457 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
458
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
459 // Rehash when load factor exceeds ~50% (bucket_count * BUCKET_SIZE * 0.5)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
460 // This ensures we rehash before probe chains get too long
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
461 if (p_index->item_count + p_index->tombstone_count >= p_index->bucket_count * 4)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
462 p_map = dowa__hashmap_rehash(p_map, element_size, p_index->bucket_count * 2, p_arena);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
463
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
464 p_index = dowa__hashmap_get_index(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
465
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
466 Dowa_Array_Header* p_header = dowa__header(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
467 uint32 new_index = (uint32)p_header->length;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
468 char* p_new_element = (char*)p_map + (new_index * element_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
469
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
470 char* p_key_copy;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
471 if (p_arena)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
472 p_key_copy = (char*)Dowa_Arena_Allocate(p_arena, key_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
473 else
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
474 p_key_copy = (char*)malloc(key_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
475
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
476 if (!p_key_copy)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
477 return p_map;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
478
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
479 memcpy(p_key_copy, p_key, key_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
480
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
481 memcpy(p_new_element, &p_key_copy, sizeof(char*));
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
482 p_header->length++;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
483
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
484 // Try to insert into hash table - if it fails, rehash and retry
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
485 boolean inserted = FALSE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
486 for (int attempt = 0; attempt < 2 && !inserted; attempt++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
487 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
488 if (attempt == 1)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
489 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
490 // First attempt failed - rehash to make more room
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
491 p_header->length--; // Undo the array length increment temporarily
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
492 p_map = dowa__hashmap_rehash(p_map, element_size, p_index->bucket_count * 2, p_arena);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
493 p_index = dowa__hashmap_get_index(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
494 p_header = dowa__header(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
495
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
496 // Restore array state
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
497 new_index = (uint32)p_header->length;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
498 p_new_element = (char*)p_map + (new_index * element_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
499 memcpy(p_new_element, &p_key_copy, sizeof(char*));
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
500 p_header->length++;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
501 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
502
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
503 size_t bucket_mask = p_index->bucket_count - 1;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
504 size_t bucket_index = hash & bucket_mask;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
505 size_t probe_step = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
506
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
507 while (!inserted && probe_step <= p_index->bucket_count)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
508 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
509 Dowa_Hash_Bucket* p_bucket = &p_index->p_buckets[bucket_index];
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
510
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
511 for (size_t i = 0; i < DOWA_HASH_BUCKET_SIZE; i++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
512 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
513 if (p_bucket->hash[i] == DOWA_HASH_EMPTY || p_bucket->hash[i] == DOWA_HASH_TOMBSTONE)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
514 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
515 if (p_bucket->hash[i] == DOWA_HASH_TOMBSTONE)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
516 p_index->tombstone_count--;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
517
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
518 p_bucket->hash[i] = hash;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
519 p_bucket->index[i] = new_index;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
520 p_index->item_count++;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
521 inserted = TRUE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
522 break;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
523 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
524 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
525
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
526 if (!inserted)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
527 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
528 probe_step++;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
529 bucket_index = (hash + (probe_step * probe_step)) & bucket_mask;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
530 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
531 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
532 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
533
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
534 return p_map;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
535 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
536
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
537 void dowa__hashmap_delete(void* p_map, size_t element_size, void* p_key, size_t key_size)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
538 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
539 if (!p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
540 return;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
541
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
542 Dowa_Hash_Index* p_index = dowa__hashmap_get_index(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
543 if (!p_index || !p_index->p_buckets)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
544 return;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
545
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
546 uint32 hash = dowa__hash_bytes(p_key, key_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
547 size_t bucket_mask = p_index->bucket_count - 1;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
548 size_t bucket_index = hash & bucket_mask;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
549 size_t probe_step = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
550
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
551 while (probe_step <= p_index->bucket_count)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
552 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
553 Dowa_Hash_Bucket* p_bucket = &p_index->p_buckets[bucket_index];
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
554
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
555 for (size_t i = 0; i < DOWA_HASH_BUCKET_SIZE; i++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
556 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
557 if (p_bucket->hash[i] == DOWA_HASH_EMPTY)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
558 return;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
559
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
560 if (p_bucket->hash[i] == hash && p_bucket->index[i] != DOWA_HASH_TOMBSTONE)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
561 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
562 uint32 array_index = p_bucket->index[i];
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
563 char* p_element = (char*)p_map + (array_index * element_size);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
564
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
565 char** p_stored_key_ptr = (char**)p_element;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
566 char* p_stored_key = *p_stored_key_ptr;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
567 char* p_search_key = (char*)p_key;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
568
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
569 if (memcmp(p_stored_key, p_search_key, key_size) == 0)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
570 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
571 if (dowa__header(p_map)->allocator_type == DOWA_ALLOCATOR_MALLOC)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
572 free(p_stored_key);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
573
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
574 p_bucket->hash[i] = DOWA_HASH_TOMBSTONE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
575 p_bucket->index[i] = DOWA_HASH_TOMBSTONE;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
576 p_index->item_count--;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
577 p_index->tombstone_count++;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
578 return;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
579 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
580 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
581 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
582
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
583 probe_step++;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
584 bucket_index = (hash + (probe_step * probe_step)) & bucket_mask;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
585 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
586 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
587
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
588 void dowa__hashmap_clear(void* p_map, size_t element_size)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
589 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
590 if (!p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
591 return;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
592
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
593 Dowa_Array_Header* p_header = dowa__header(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
594 p_header->length = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
595
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
596 Dowa_Hash_Index* p_index = dowa__hashmap_get_index(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
597 if (p_index && p_index->p_buckets)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
598 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
599 for (size_t i = 0; i < p_index->bucket_count; i++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
600 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
601 for (size_t j = 0; j < DOWA_HASH_BUCKET_SIZE; j++)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
602 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
603 p_index->p_buckets[i].hash[j] = DOWA_HASH_EMPTY;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
604 p_index->p_buckets[i].index[j] = DOWA_HASH_EMPTY;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
605 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
606 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
607 p_index->item_count = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
608 p_index->tombstone_count = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
609 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
610 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
611
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
612 void dowa__hashmap_free(void* p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
613 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
614 if (!p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
615 return;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
616
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
617 Dowa_Hash_Index* p_index = dowa__hashmap_get_index(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
618 if (p_index && p_index->allocator_type == DOWA_ALLOCATOR_MALLOC)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
619 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
620 if (p_index->p_buckets)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
621 free(p_index->p_buckets);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
622 free(p_index);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
623 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
624
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
625 dowa__array_free(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
626 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
627
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
628 size_t dowa__hashmap_count(void* p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
629 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
630 if (!p_map)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
631 return 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
632
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
633 Dowa_Hash_Index* p_index = dowa__hashmap_get_index(p_map);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
634 return p_index ? p_index->item_count : 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
635 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
636
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
637 /*
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
638 // --- OLD HashMap Implementation (Commented out for migration) --- //
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
639 Dowa_HashMap *Dowa_HashMap_Create(size_t capacity)
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
640 {
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
641 Dowa_HashMap *p_hash_map;
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
642 p_hash_map = malloc(sizeof(Dowa_HashMap));
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
643 if (p_hash_map == NULL)
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
644 {
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
645 return NULL;
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
646 }
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
647 p_hash_map->entries = calloc(capacity, sizeof(*p_hash_map->entries));
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
648 if (p_hash_map->entries == NULL)
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
649 {
36
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
650 Dowa_Free(p_hash_map);
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
651 return NULL;
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
652 }
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
653 p_hash_map->capacity = capacity;
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
654 p_hash_map->current_capacity = 0;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
655 p_hash_map->p_arena = NULL;
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
656 return p_hash_map;
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
657 }
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
658
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
659 Dowa_HashMap *Dowa_HashMap_Create_With_Arena(size_t capacity, Dowa_Arena *p_arena)
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
660 {
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
661 if (p_arena == NULL)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
662 {
21
09def63429b9 [Dowa] Updated the naming scheme and tests.
June Park <parkjune1995@gmail.com>
parents: 20
diff changeset
663 printf("Arena is NULL\n");
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
664 return Dowa_HashMap_Create(capacity);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
665 }
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
666
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
667 Dowa_HashMap *p_hash_map;
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
668 p_hash_map = Dowa_Arena_Allocate(p_arena, sizeof(Dowa_HashMap));
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
669 if (p_hash_map == NULL)
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
670 {
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
671 return NULL;
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
672 }
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
673 p_hash_map->entries = Dowa_Arena_Allocate(p_arena, sizeof(*p_hash_map->entries) * capacity);
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
674 if (p_hash_map->entries == NULL)
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
675 {
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
676 return NULL;
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
677 }
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
678 memset(p_hash_map->entries, 0, capacity * sizeof *p_hash_map->entries);
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
679 p_hash_map->capacity = capacity;
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
680 p_hash_map->current_capacity = 0;
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
681 p_hash_map->p_arena = p_arena;
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
682 return p_hash_map;
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
683 }
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
684
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
685 void Dowa_HashMap_Destroy(Dowa_HashMap *p_hash_map)
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
686 {
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
687 if (!p_hash_map) return;
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
688
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
689 if (p_hash_map->p_arena)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
690 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
691 // Free arena instead of the map...
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
692 // Dowa_Arena_Destroy(p_hash_map->p_arena);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
693 return;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
694 }
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
695 else
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
696 {
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
697 Dowa_HashEntry *entry;
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
698 Dowa_HashEntry *next;
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
699 if (p_hash_map->entries)
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
700 {
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
701 for (int idx=0; idx<p_hash_map->capacity; idx++)
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
702 {
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
703 entry = p_hash_map->entries[idx];
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
704 while (entry)
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
705 {
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
706 next = entry->next;
36
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
707 Dowa_Free(entry->key);
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
708 Dowa_Free(entry->buffer);
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
709 Dowa_Free(entry);
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
710 entry = next;
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
711 }
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
712 }
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
713 }
36
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
714 Dowa_Free(p_hash_map->entries);
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
715 }
36
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
716 Dowa_Free(p_hash_map);
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
717 }
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
718
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
719 int32 Dowa_HashMap_Get_Position(Dowa_HashMap *p_hash_map, const char *key)
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
720 {
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
721 if (!p_hash_map || !key)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
722 return -1;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
723
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
724 int32 hash_val = HASH_KEY_NUMBER;
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
725 int32 c;
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
726 while ((c = *key++))
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
727 {
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
728 hash_val = (hash_val << 5) + hash_val + c;
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
729 }
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
730 return hash_val % p_hash_map->capacity;
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
731 }
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
732
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
733 void *Dowa_HashMap_Get(Dowa_HashMap *p_hash_map, const char *key)
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
734 {
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
735 if (!p_hash_map || !key)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
736 return NULL;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
737
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
738 int idx = Dowa_HashMap_Get_Position(p_hash_map, key);
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
739 Dowa_HashEntry *entry = p_hash_map->entries[idx];
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
740
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
741 while (entry)
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
742 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
743 if (strcmp(entry->key, key) == 0)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
744 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
745 return entry->buffer;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
746 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
747 entry = entry->next;
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
748 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
749
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
750 return NULL;
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
751 }
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
752
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
753
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
754 int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_HashMap *p_hash_map, const char *key,
21
09def63429b9 [Dowa] Updated the naming scheme and tests.
June Park <parkjune1995@gmail.com>
parents: 20
diff changeset
755 void *value, size_t value_size,
09def63429b9 [Dowa] Updated the naming scheme and tests.
June Park <parkjune1995@gmail.com>
parents: 20
diff changeset
756 Dowa_HashMap_ValueType type)
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
757 {
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
758 if (!p_hash_map || !key || !value)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
759 return -1;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
760
21
09def63429b9 [Dowa] Updated the naming scheme and tests.
June Park <parkjune1995@gmail.com>
parents: 20
diff changeset
761 int idx = Dowa_HashMap_Get_Position(p_hash_map, key);
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
762 Dowa_HashEntry *entry = p_hash_map->entries[idx];
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
763 Dowa_HashEntry *prev = NULL;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
764
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
765 // Old key
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
766 while (entry)
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
767 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
768 if (strcmp(entry->key, key) == 0)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
769 {
36
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
770 // Fails if it the key exists...
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
771 return -1;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
772 }
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
773 prev = entry;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
774 entry = entry->next;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
775 }
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
776
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
777 // New Key
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
778 entry = p_hash_map->p_arena ?
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
779 Dowa_Arena_Allocate(p_hash_map->p_arena, sizeof(Dowa_HashEntry)) :
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
780 malloc(sizeof(Dowa_HashEntry));
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
781 if (!entry) { perror("malloc or arena alloc"); return -1; }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
782
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
783 entry->key = p_hash_map->p_arena ?
71
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
784 Dowa_Arena_Copy(p_hash_map->p_arena, key, strlen(key) + 1) :
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
785 strdup(key);
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
786 if (!entry->key)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
787 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
788 perror("strdup or arena copy");
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
789 if (!p_hash_map->p_arena) Dowa_Free(entry);
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
790 return -1;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
791 }
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
792 entry->buffer = value;
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
793 entry->capacity = value_size;
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
794 entry->type = type;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
795 entry->next = NULL;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
796
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
797 if (prev)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
798 prev->next = entry;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
799 else
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
800 p_hash_map->entries[idx] = entry;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
801
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
802 p_hash_map->current_capacity++;
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
803 return 0;
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
804 }
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
805
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
806 int32 Dowa_HashMap_Push_Value_With_Type(Dowa_HashMap *p_hash_map, const char *key,
21
09def63429b9 [Dowa] Updated the naming scheme and tests.
June Park <parkjune1995@gmail.com>
parents: 20
diff changeset
807 void *value, size_t value_size,
09def63429b9 [Dowa] Updated the naming scheme and tests.
June Park <parkjune1995@gmail.com>
parents: 20
diff changeset
808 Dowa_HashMap_ValueType type)
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
809 {
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
810 if (!p_hash_map || !key || !value)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
811 return -1;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
812
21
09def63429b9 [Dowa] Updated the naming scheme and tests.
June Park <parkjune1995@gmail.com>
parents: 20
diff changeset
813 int idx = Dowa_HashMap_Get_Position(p_hash_map, key);
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
814 Dowa_HashEntry *entry = p_hash_map->entries[idx];
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
815 Dowa_HashEntry *prev = NULL;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
816
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
817 // Check for existing key
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
818 while (entry)
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
819 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
820 if (strcmp(entry->key, key) == 0)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
821 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
822 if (!p_hash_map->p_arena && entry->buffer)
36
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
823 Dowa_Free(entry->buffer);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
824
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
825 entry->buffer = p_hash_map->p_arena ?
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
826 Dowa_Arena_Allocate(p_hash_map->p_arena, value_size) :
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
827 malloc(value_size);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
828 if (!entry->buffer) { perror("malloc or arena alloc"); return -1; }
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
829
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
830 memcpy(entry->buffer, value, value_size);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
831 entry->capacity = value_size;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
832 entry->type = type;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
833 return 0;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
834 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
835 prev = entry;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
836 entry = entry->next;
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
837 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
838
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
839 // New Key
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
840 entry = p_hash_map->p_arena ?
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
841 Dowa_Arena_Allocate(p_hash_map->p_arena, sizeof(Dowa_HashEntry)) :
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
842 malloc(sizeof(Dowa_HashEntry));
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
843 if (!entry) { perror("malloc or arena alloc"); return -1; }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
844
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
845 entry->key = p_hash_map->p_arena ?
71
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
846 Dowa_Arena_Copy(p_hash_map->p_arena, key, strlen(key) + 1) :
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
847 strdup(key);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
848 if (!entry->key) { perror("strdup"); return -1; }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
849
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
850 entry->buffer = p_hash_map->p_arena ?
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
851 Dowa_Arena_Allocate(p_hash_map->p_arena, value_size) :
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
852 malloc(value_size);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
853 if (!entry->buffer) { perror("malloc or arena alloc"); return -1; }
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
854
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
855 memcpy(entry->buffer, value, value_size);
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
856 entry->capacity = value_size;
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
857 entry->type = type;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
858 entry->next = NULL;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
859
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
860 if (prev)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
861 prev->next = entry;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
862 else
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
863 p_hash_map->entries[idx] = entry;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
864
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
865 p_hash_map->current_capacity++;
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
866 return 0;
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
867 }
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
868
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
869 void Dowa_HashMap_Push_Value(Dowa_HashMap *p_hash_map, const char *key, void *value, size_t value_size)
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
870 {
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
871 Dowa_HashMap_Push_Value_With_Type(p_hash_map, key, value, value_size, DOWA_HASH_MAP_TYPE_BUFFER);
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
872 }
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
873
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
874 void Dowa_HashMap_Pop_Key(Dowa_HashMap *p_hash_map, const char *key)
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
875 {
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
876 if (!p_hash_map || !key)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
877 return;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
878
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
879 int idx = Dowa_HashMap_Get_Position(p_hash_map, key);
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
880 Dowa_HashEntry *entry = p_hash_map->entries[idx];
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
881 Dowa_HashEntry *prev = NULL;
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
882
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
883 while (entry)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
884 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
885 if (strcmp(entry->key, key) == 0)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
886 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
887 if (prev)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
888 prev->next = entry->next;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
889 else
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
890 p_hash_map->entries[idx] = entry->next;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
891
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
892 if (!(p_hash_map->p_arena))
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
893 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
894 Dowa_Free(entry->key);
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
895 Dowa_Free(entry->buffer);
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
896 Dowa_Free(entry);
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
897 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
898
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
899 if (p_hash_map->current_capacity > 0)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
900 p_hash_map->current_capacity--;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
901 return;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
902 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
903 prev = entry;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
904 entry = entry->next;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
905 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
906 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
907
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
908 boolean Dowa_HashMap_Has_Key(Dowa_HashMap *p_hash_map, const char *key)
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
909 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
910 if (!p_hash_map || !key)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
911 return FALSE;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
912
21
09def63429b9 [Dowa] Updated the naming scheme and tests.
June Park <parkjune1995@gmail.com>
parents: 20
diff changeset
913 int idx = Dowa_HashMap_Get_Position(p_hash_map, key);
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
914 Dowa_HashEntry *entry = p_hash_map->entries[idx];
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
915
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
916 while (entry)
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
917 {
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
918 if (strcmp(entry->key, key) == 0)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
919 return TRUE;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
920 entry = entry->next;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
921 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
922
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
923 return FALSE;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
924 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
925
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
926 void Dowa_HashMap_Clear(Dowa_HashMap *p_hash_map)
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
927 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
928 if (!p_hash_map) return;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
929
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
930 if (p_hash_map->p_arena)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
931 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
932 for (int idx=0; idx<p_hash_map->capacity; idx++)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
933 p_hash_map->entries[idx] = NULL;
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
934 }
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
935 else
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
936 {
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
937 Dowa_HashEntry *entry;
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
938 Dowa_HashEntry *next;
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
939 if (p_hash_map->entries)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
940 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
941 for (int idx=0; idx<p_hash_map->capacity; idx++)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
942 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
943 entry = p_hash_map->entries[idx];
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
944 while (entry)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
945 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
946 next = entry->next;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
947 Dowa_Free(entry->key);
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
948 Dowa_Free(entry->buffer);
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
949 Dowa_Free(entry);
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
950 entry = next;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
951 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
952 p_hash_map->entries[idx] = NULL;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
953 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
954 }
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
955 }
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
956 p_hash_map->current_capacity = 0;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
957 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
958
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
959 uint32 Dowa_HashMap_Get_Count(Dowa_HashMap *p_hash_map)
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
960 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
961 if (!p_hash_map) return 0;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
962 return p_hash_map->current_capacity;
2
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
963 }
8a43dedbe530 [Dowa] Added HashMap and Updated Arena naming.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
964
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
965 void Dowa_HashMap_Print(Dowa_HashMap *map)
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
966 {
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
967 if (!map)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
968 {
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
969 printf("HashMap is NULL\n");
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
970 return;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
971 }
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
972
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
973 printf("\n-----------\n\n");
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
974 for (size_t i = 0; i < map->capacity; ++i)
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
975 {
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
976 Dowa_HashEntry *e = map->entries[i];
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
977 while (e)
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
978 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
979 if (!e) break;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
980 printf("%s: ", e->key);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
981 switch (e->type)
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
982 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
983 case DOWA_HASH_MAP_TYPE_BUFFER:
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
984 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
985 unsigned char *p = e->buffer;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
986 for (size_t j = 0; j < e->capacity; ++j)
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
987 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
988 printf("%02x", p[j]);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
989 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
990 printf("\n");
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
991 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
992 break;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
993 case DOWA_HASH_MAP_TYPE_STRING:
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
994 {
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
995 printf("%.*s\n", (int)e->capacity, (char*)e->buffer);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
996 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
997 break;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
998 case DOWA_HASH_MAP_TYPE_HASHMAP:
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
999 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1000 printf("This is a hashmap with size of %zu, and pointer %p\n", e->capacity, (void *)e);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1001 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1002 break;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1003 case DOWA_HASH_MAP_TYPE_INT:
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1004 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1005 printf("%d\n", *(int32*)e->buffer);
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1006 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1007 break;
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1008 default:
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1009 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1010 printf("<unknown type>\n");
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1011 }
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1012 }
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1013 e = e->next;
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1014 }
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1015 }
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1016 printf("-----------\n");
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1017 }
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1018
71
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1019 // -- Array --//
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1020 Dowa_Array *Dowa_Array_Init()
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1021 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1022 Dowa_Array *dowa_array = malloc(sizeof(Dowa_Array));
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1023 if (dowa_array == NULL)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1024 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1025 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1026 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1027
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1028 dowa_array->capacity = DOWA_ARRAY_DEFAULT_CAPACITY;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1029 dowa_array->items = (Dowa_Array_Item *)malloc(sizeof(Dowa_Array_Item) * DOWA_ARRAY_DEFAULT_CAPACITY);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1030 if (dowa_array->items == NULL)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1031 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1032 return NULL;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1033 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1034
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1035 dowa_array->current_length = 0;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1036 return dowa_array;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1037 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1038
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1039 // void Dowa_Array_Push_Value(Dowa_Array *dowa_array, void *buffer, uint32 length)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1040 // {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1041 // if (dowa_array->current_length == dowa_array->capacity)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1042 // {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1043 // dowa_array->items = realloc(dowa_array->items, sizeof(Dowa_Array_Item) * dowa_array->capacity * 2);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1044 // dowa_array->capacity = dowa_array->capacity * 2;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1045 // }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1046 // Dowa_Array_Item *item = &(dowa_array->items[dowa_array->current_length]);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1047 // item->value = malloc(length);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1048 // if (item->value == NULL)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1049 // {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1050 // // didn't alloc should raise an error.
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1051 // return;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1052 // }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1053 // memcpy(item->value, buffer, length);
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1054 // item->length = length;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1055 // dowa_array->current_length += 1;
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1056 // }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1057
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1058
64
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 52
diff changeset
1059 #ifdef DIRECTORY
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
1060 int Dowa_HashMap_Cache_Folder(Dowa_HashMap *p_hash_map, const char *folder_path)
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1061 {
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
1062 if (!p_hash_map || !folder_path)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
1063 return -1;
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
1064
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1065 DIR *dir = opendir(folder_path);
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1066 if (!dir) { perror("opendir"); return -1; }
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1067
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1068 struct dirent *entry;
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1069 while ((entry = readdir(dir)))
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1070 {
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1071 // skip "." and ".."
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1072 if (entry->d_name[0] == '.' &&
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1073 (entry->d_name[1] == '\0' ||
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1074 (entry->d_name[1] == '.' && entry->d_name[2] == '\0')))
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1075 continue;
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1076
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1077 char fullpath[PATH_MAX];
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1078 snprintf(fullpath, sizeof fullpath, "%s/%s", folder_path, entry->d_name);
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1079
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1080 struct stat st;
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1081 if (stat(fullpath, &st) < 0) { perror("stat"); continue; }
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1082
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1083 if (S_ISREG(st.st_mode))
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1084 {
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1085 size_t size = (size_t)st.st_size;
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1086 FILE *f = fopen(fullpath, "rb");
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1087 if (!f) { perror("fopen"); continue; }
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1088
64
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 52
diff changeset
1089 // Allocate exact file size (no extra byte for null terminator)
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
1090 void *buf = p_hash_map->p_arena ?
64
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 52
diff changeset
1091 Dowa_Arena_Allocate(p_hash_map->p_arena, size) :
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 52
diff changeset
1092 malloc(size);
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1093 if (!buf) { perror("malloc"); fclose(f); closedir(dir); return -1; }
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1094
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1095 if (fread(buf, 1, size, f) != size)
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1096 {
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1097 perror("fread");
36
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 32
diff changeset
1098 if (!p_hash_map->p_arena) Dowa_Free(buf);
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1099 fclose(f);
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1100 continue;
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1101 }
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1102 fclose(f);
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1103
64
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 52
diff changeset
1104 // Store file data as-is without null terminator (for binary files like images)
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 52
diff changeset
1105 Dowa_HashMap_Push_Value_With_Type(p_hash_map, entry->d_name, buf, size, DOWA_HASH_MAP_TYPE_STRING);
52
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
1106 if (!p_hash_map->p_arena)
636eab07809d Fixed dowa memory problems. Add few more utility functions.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
1107 Dowa_Free(buf); // Dowa_HashMap_PushValue made its own copy
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1108 }
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1109 else if (S_ISDIR(st.st_mode))
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1110 {
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.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
1111 // TODO: Adjust the sizes of the recursive map?
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 64
diff changeset
1112 Dowa_HashMap *p_child_map = Dowa_HashMap_Create_With_Arena(100, p_hash_map->p_arena);
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1113 if (!p_child_map)
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1114 {
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1115 perror("Dowa_HashMap_Create");
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1116 return -1;
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1117 }
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1118 if (Dowa_HashMap_Cache_Folder(p_child_map, fullpath) == -1)
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1119 {
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1120 perror("Dowa_HashMap_Cache_Folder");
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1121 return -1;
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1122 }
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1123
6
1e61008b9980 [Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents: 5
diff changeset
1124 // Should not copy as we malloced already.
20
0a9e67c7039a [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
1125 if (Dowa_HashMap_Push_Value_With_Type_NoCopy(p_hash_map, entry->d_name, p_child_map,
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1126 sizeof(p_child_map), DOWA_HASH_MAP_TYPE_HASHMAP) == -1)
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1127 {
21
09def63429b9 [Dowa] Updated the naming scheme and tests.
June Park <parkjune1995@gmail.com>
parents: 20
diff changeset
1128 Dowa_HashMap_Destroy(p_child_map);
5
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1129 return -1;
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1130 }
3e12bf044589 Fixed Dowa hashmap to recursively add files into memory.
June Park <parkjune1995@gmail.com>
parents: 3
diff changeset
1131 }
3
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1132 }
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1133 closedir(dir);
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1134 return 0;
2758f5527d2b [Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents: 2
diff changeset
1135 }
64
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 52
diff changeset
1136 #endif
71
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
1137 */