Cthulhu
0.2.10
Cthulhu compiler collection
|
Hash map. More...
Data Structures | |
struct | map_t |
an unordered hash map More... | |
struct | map_entry_t |
a key-value pair in a map More... | |
struct | map_iter_t |
a map iterator handle More... | |
Macros | |
#define | CTU_MAP_NEXT(iter, key, value) map_next_pair(iter, (const void **)(key), (void **)(value)) |
get the next key-value pair from a map iterator More... | |
Functions | |
CT_STD_API void | map_init (OUT_NOTNULL map_t *map, size_t size, hash_info_t info, arena_t *arena) |
initialize a map More... | |
CT_NODISCARD CT_STD_API map_t | map_make (size_t size, hash_info_t info, arena_t *arena) |
create a new map on the stack More... | |
CT_NODISCARD CT_STD_API map_t * | map_new (size_t size, hash_info_t info, arena_t *arena) |
create a new map on the heap More... | |
CT_NODISCARD CT_STD_API map_t * | map_optimal (size_t size, hash_info_t info, arena_t *arena) |
create a new map with an optimal size More... | |
CT_STD_API void | map_set (map_t *map, const void *key, void *value) |
set a key-value pair in a map More... | |
CT_NODISCARD CT_PUREFN CT_STD_API void * | map_get (const map_t *map, const void *key) |
get a value from a map More... | |
CT_NODISCARD CT_PUREFN CT_STD_API void * | map_get_default (const map_t *map, const void *key, void *other) |
get a value from a map or a default value More... | |
CT_NODISCARD CT_PUREFN CT_STD_API bool | map_contains (const map_t *map, const void *key) |
check if a map contains a key More... | |
CT_STD_API bool | map_delete (map_t *map, const void *key) |
delete a key-value pair from a map More... | |
CT_NODISCARD CT_STD_API vector_t * | map_values (map_t *map) |
collect all the values from a map into a vector More... | |
CT_NODISCARD CT_STD_API typevec_t * | map_entries (map_t *map) |
collect all key-value pairs in a map into a vector returns a typevec_t<map_entry_t> More... | |
CT_NODISCARD CT_PUREFN CT_STD_API size_t | map_count (const map_t *map) |
get the number of key-value pairs in a map More... | |
CT_STD_API void | map_reset (map_t *map) |
clear all key-value pairs from a map More... | |
CT_NODISCARD CT_PUREFN CT_STD_API map_iter_t | map_iter (const map_t *map) |
create a new map iterator More... | |
CT_NODISCARD CT_NOALIAS CT_STD_API map_entry_t | map_next (map_iter_t *iter) |
get the next key-value pair from a map iterator More... | |
CT_NODISCARD CT_PUREFN CT_STD_API bool | map_has_next (const map_iter_t *iter) |
check if a map iterator has more elements More... | |
CT_NODISCARD CT_STD_API bool | map_next_pair (map_iter_t *iter, const void **key, void **value) |
get the next key-value pair from a map iterator returns the values via out parameters for ease of use this also returns false if the iterator has no more elements this is intended to be used via CTU_MAP_NEXT for more idiomatic usage More... | |
Variables | |
CT_STD_API const map_t | kEmptyMap |
an empty map More... | |
Hash map.
the map makes some assumptions about keys and values
the map interface provides a map_new and a map_optimal function for performance reasons. its recommended to use map_optimal if you have an estimate of the number of elements in the map.
#define CTU_MAP_NEXT | ( | iter, | |
key, | |||
value | |||
) | map_next_pair(iter, (const void **)(key), (void **)(value)) |
get the next key-value pair from a map iterator
intended to be used as such:
iter | the iterator to get the next key-value pair from |
key | the key of the next key-value pair |
value | the value of the next key-value pair |
true | the iterator has more elements |
CT_NODISCARD CT_PUREFN CT_STD_API bool map_contains | ( | const map_t * | map, |
const void * | key | ||
) |
CT_NODISCARD CT_PUREFN CT_STD_API size_t map_count | ( | const map_t * | map | ) |
CT_STD_API bool map_delete | ( | map_t * | map, |
const void * | key | ||
) |
CT_NODISCARD CT_STD_API typevec_t* map_entries | ( | map_t * | map | ) |
CT_NODISCARD CT_PUREFN CT_STD_API void* map_get | ( | const map_t * | map, |
const void * | key | ||
) |
CT_NODISCARD CT_PUREFN CT_STD_API void* map_get_default | ( | const map_t * | map, |
const void * | key, | ||
void * | other | ||
) |
CT_NODISCARD CT_PUREFN CT_STD_API bool map_has_next | ( | const map_iter_t * | iter | ) |
CT_STD_API void map_init | ( | OUT_NOTNULL map_t * | map, |
size_t | size, | ||
hash_info_t | info, | ||
arena_t * | arena | ||
) |
initialize a map
map | the map to initialize |
size | the initial size of the map |
info | the type info for the key type |
arena | the arena to allocate from |
CT_NODISCARD CT_PUREFN CT_STD_API map_iter_t map_iter | ( | const map_t * | map | ) |
CT_NODISCARD CT_STD_API map_t map_make | ( | size_t | size, |
hash_info_t | info, | ||
arena_t * | arena | ||
) |
CT_NODISCARD CT_STD_API map_t* map_new | ( | size_t | size, |
hash_info_t | info, | ||
arena_t * | arena | ||
) |
CT_NODISCARD CT_NOALIAS CT_STD_API map_entry_t map_next | ( | map_iter_t * | iter | ) |
CT_NODISCARD CT_STD_API bool map_next_pair | ( | map_iter_t * | iter, |
const void ** | key, | ||
void ** | value | ||
) |
get the next key-value pair from a map iterator returns the values via out parameters for ease of use this also returns false if the iterator has no more elements this is intended to be used via CTU_MAP_NEXT for more idiomatic usage
iter | the iterator to get the next key-value pair from |
key | the key of the next key-value pair |
value | the value of the next key-value pair |
true | the iterator has more elements |
CT_NODISCARD CT_STD_API map_t* map_optimal | ( | size_t | size, |
hash_info_t | info, | ||
arena_t * | arena | ||
) |
CT_STD_API void map_reset | ( | map_t * | map | ) |
CT_STD_API void map_set | ( | map_t * | map, |
const void * | key, | ||
void * | value | ||
) |
CT_NODISCARD CT_STD_API vector_t* map_values | ( | map_t * | map | ) |