2
3
4
5
6
7
8
9
10
11#ifndef GIMBAL_ARRAY_MAP_H
12#define GIMBAL_ARRAY_MAP_H
14#include "../core/gimbal_typedefs.h"
15#include "../strings/gimbal_quark.h"
16#include "../meta/types/gimbal_variant.h"
17#include "../core/gimbal_result.h"
20#define GBL_ARRAY_MAP_SIZE(elements) (sizeof(GblArrayMap) + (sizeof(GblArrayMapEntry)*(elements)))
21#define GBL_ARRAY_MAP_BINARY_SEARCH_CUTOFF_SIZE 40
23#define GBL_PSELF GblArrayMap** ppSelf
24#define GBL_PCSELF GblArrayMap*const* ppSelf
31typedef GBL_RESULT (*GblArrayMapDtorFn)(
const GblArrayMap*, uintptr_t key,
void* pEntry);
35
36
37
38
39
40
41
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
74#elif defined(GBL_32BIT)
150
151
152
153
154
155
156
158
159
160
161
162
164
165
166
167
168
169
171
172
173
174
175
176
177
179
180
181
182
183
184
185
187
188
189
190
GblBool GblArrayMap_empty(GblArrayMap *const *ppSelf)
Returns whether the given map is empty.
GBL_RESULT GblArrayMap_destroy(GblArrayMap **ppSelf)
Destroys a GblArrayMap.
uintptr_t GblArrayMap_atValue(GblArrayMap *const *ppSelf, uintptr_t key)
Returns the GblVariant or userdata value associated with the given key, erroring if not found.
size_t GblArrayMap_size(GblArrayMap *const *ppSelf)
Returns the number of entries within the given map.
GblContext * GblArrayMap_context(GblArrayMap *const *ppSelf)
Returns the context associated with the given map.
size_t GblArrayMap_insertUserdata(GblArrayMap **ppSelf, uintptr_t key, uintptr_t value, GblArrayMapDtorFn pDtor)
Attempts to insert a new entry with the given key and userdata, returning the insertion index.
GblVariant * GblArrayMap_getVariant(GblArrayMap *const *ppSelf, uintptr_t key)
Returns the GblVariant associated with the given key.
GblBool GblArrayMap_extractVariant(GblArrayMap **ppSelf, uintptr_t key, GblVariant *pVariant)
Attempts to remove the GblVariant with the given key, moving it into the given pointer if found.
GBL_RESULT GblArrayMap_setUserdata(GblArrayMap **ppSelf, uintptr_t key, uintptr_t value, GblArrayMapDtorFn pDtor)
Inserts or replaces the entry with the given key with a userdata value and optional destructor.
GblBool GblArrayMap_contains(GblArrayMap *const *ppSelf, uintptr_t key)
Returns true if the given map contains the given key.
GblArrayMap * GblArrayMap_create(GblArrayMapCmpFn pFnComp, GblBool binarySearch, GblContext *pCtx)
Pre-creates a GblArrayMap with the given comparator, binary search config, and context.
size_t GblArrayMap_insertVariant(GblArrayMap **ppSelf, uintptr_t key, GblVariant *pVariant)
Attempts to insert a new entry with the given key and GblVariant value, returning insertion index.
GblBool GblArrayMap_extractValue(GblArrayMap **ppSelf, uintptr_t key, uintptr_t *pValue)
Attempts to remove the value with the given key, moving it into the given pointer if found.
GblVariant * GblArrayMap_atVariant(GblArrayMap *const *ppSelf, uintptr_t key)
Returns the GblVariant associated with the given key, erroring if not found.
GblVariant * GblArrayMap_probeVariant(GblArrayMap *const *ppSelf, size_t index)
Returns the GblVariant for the entry at the given index.
size_t GblArrayMap_find(GblArrayMap *const *ppSelf, uintptr_t key)
Returns the index of the entry with the given key.
GBL_RESULT GblArrayMap_setVariant(GblArrayMap **ppSelf, uintptr_t key, GblVariant *pVariant)
Inserts or replaces the entry with the given key with a GblVariant.
uintptr_t GblArrayMap_probeKey(GblArrayMap *const *ppSelf, size_t index)
Returns the key for the entry at the given index.
GblBool GblArrayMap_binarySearches(GblArrayMap *const *ppSelf)
Returns whether the given map is sorted and uses binary searches.
uintptr_t GblArrayMap_probeValue(GblArrayMap *const *ppSelf, size_t index)
Returns the value for the entry at the given index.
GblBool GblArrayMap_containsVariant(GblArrayMap *const *ppSelf, uintptr_t key)
Returns true if the given map contains the given key, associated with a GblVariant value.
void GblArrayMap_clear(GblArrayMap **ppSelf)
Clears all entries within the given map.
int(* GblArrayMapCmpFn)(const GblArrayMap *, uintptr_t key1, uintptr_t key2)
Custom comparator for nontrivial key types.
GblBool GblArrayMap_erase(GblArrayMap **ppSelf, uintptr_t key)
Attempts to erase the value with the given key, returning GBL_FALSE if not found.
GblBool GblArrayMap_containsUserdata(GblArrayMap *const *ppSelf, uintptr_t key)
Returns true if the given map contains the given key, associated with a userdata value.
uintptr_t GblArrayMap_getValue(GblArrayMap *const *ppSelf, uintptr_t key)
Returns the GblVariant or userdata value associated with the given key as a uintptr_t.
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_PRIVATE_BEGIN
#define GBL_PRIVATE_END
Private data structure.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
Represents a single K,V data entry within a GblArrayMap.
GblVariant value
Using value.type == GBL_INVALID_TYPE to signify userdata.
uintptr_t key
Opaque key value.
GblArrayMapDtorFn dtor
Optional custom destructor for userdata types.
Dynamic array-based [K,V] pair associative container.
GblArrayMapCmpFn pFnComparator
Optional custom comparator.
GblContext * pCtx
Optional custom context.
size_t binarySearches
Optionally sort values and use binary searches.
size_t size
Number of elements within the map.