A sorted array based implementation of as_map
.
To use the map, you can either initialize a stack allocated map, using as_orderedmap_init()
:
AS_EXTERN as_orderedmap * as_orderedmap_init(as_orderedmap *map, uint32_t capacity)
Or you can create a new heap allocated map using as_orderedmap_new()
:
AS_EXTERN as_orderedmap * as_orderedmap_new(uint32_t capacity)
When you are finished using the map, then you should release the map and associated resources, using as_orderedmap_destroy()
:
AS_EXTERN void as_orderedmap_destroy(as_orderedmap *map)
The as_orderedmap
is a subtype of as_map
. This allows you to alternatively use as_map
functions, by typecasting as_orderedmap
to as_map
.
static int as_stringmap_set_int64(as_map *m, const char *k, int64_t v)
static void as_map_destroy(as_map *map)
The as_stringmap
functions are simplified functions for using string key.
Each of the as_map
functions proxy to the as_orderedmap
functions. So, calling as_map_destroy()
is equivalent to calling as_orderedmap_destroy()
.
Notes:
This orderedmap implementation is NOT threadsafe.
Internally, the orderedmap stores keys' and values' pointers - it does NOT copy the keys or values, so the caller must ensure these keys and values are not destroyed while the orderedmap is still in use.
Further, the orderedmap does not increment ref-counts of the keys or values. However when an element is removed from the orderedmap, the orderedmap will call as_val_destroy() on both the key and value. And when the orderedmap is cleared or destroyed, as_val_destroy() will be called for all keys and values. Therefore if the caller inserts keys and values in the orderedmap without extra ref-counts, the caller is effectively handing off ownership of these objects to the orderedmap.
Definition at line 106 of file as_orderedmap.h.