elpekenin/utils/map.h
¶
Map strings (names) to values.
Note
Convenience wrapper on top of two dynamic arrays (elpekenin/utils/dyn_array.h).
-
new_map(type, name)¶
[source] Create a new map variable.
- Parameters:
type – Of the values being stored.
name – Of the map variable to be created.
-
map_init(map, size, allocator)¶
[source] Initialize a
map
created bynew_map
. With a starting size and an allocator.
-
map_set(map, key, value)¶
[source] Insert an element into a map.
- Parameters:
map – Where to operate.
key – Name of the element being added.
value – Element added.
Attention
Does not overwrite existing elements
Does not handle errors when (if)
array_append
fails. Which, on the other hand, is very unlikely: no space left to allocate.
-
map_get(map, key, ret)¶
[source] Find an element by its key in a map.
- Parameters:
map – Where to operate.
key – Name of the element being searched.
ret – Whether operation was successful. See elpekenin/errno.h for details.
- Returns:
The element identified by
key
.
Danger
You must check
ret
before using the return value. If it was not found, you will just get the last element in the internal data structure.