map.h
Exposes functions to handle the Map data structure.
- Author: Edward Jones
- Date: 2021-09-17
dest_map
Destroy a map.
- Param
map
: Pointer to the map to destroy - Param
ved
: Value destructor
void dest_map(Map* map, Destructor ved);
dest_map_iter
Destroy a map iterator.
- Param
iter
: Pointer to the iterator to destroy
void dest_map_iter(MapIter* iter);
get_map
Get a value from a map.
- Param
mo
: Return value populated with the value if present - Param
map
: Pointer to the map to retrieve the value from - Param
key
: Key to use
void get_map(Maybe* mo, Map* map, void* key);
iter_map
Iterate once over key-value pairs using a specified iterator.
- Param
p
: Pointer to the return pair - Param
iter
: Pointer to the iterator to use
Returns: true
if iteration was successful, otherwise false
as iteration has finished
bool iter_map(Pair** p, MapIter* iter);
iter_map_keys
Iterate once over the keys in a map using a given iterator.
- Param
k
: Pointer to the key to return - Param
iter
: Pointer to the iterator to use
Returns: true
iff iteration was successful, otherwise false
as iteration has finished
bool iter_map_keys(void** k, MapIter* iter);
iter_map_values
Iterate over the values in a map using a given iterator.
- Param
v
: Pointer to the value to return - Param
iter
: Pointer to the iterator to use
Returns: true
iff iteration was successful, otherwise false
as iteration has finished
bool iter_map_values(void** v, MapIter* iter);
make_map
Make a map.
- Param
map
: Pointer to the map to create - Param
hash
: Hash function to use on keys - Param
kcmp
: Comparator to use on keys - Param
ked
: Destructor to use on keys
Returns: true
iff sufficient memory could be allocated to the map, false
otherwise
bool make_map(Map* map, Hasher hash, Comparator kcmp, Destructor ked);
make_map_from_list
Make a map from a list of key-value Pairs.
- Param
map
: Pointer to the map to create - Param
list
: Pointer to the list of key-value Pairs - Param
hash
: Hash function to use on keys - Param
kcmp
: Comparison function to use on keys - Param
ked
: Destructor for the keys
Returns: true
iff enough memory could be allocated to create the map, false
otherwise
bool make_map_from_list(Map* map, List* list, Hasher hash, Comparator kcmp, Destructor ked);
make_map_iter
Make an iterator over the map.
- Param
iter
: Pointer to the iterator to make - Param
map
: Pointer to the map to iterate over
void make_map_iter(MapIter* iter, Map* map);
push_map
Push a value into a map.
- Param
oldval
: Pointer to a maybe type to be populated with the old value at a given key, if present - Param
m
: Pointer to the map to populate - Param
k
: Key to push - Param
v
: Value to push
Returns: true
iff sufficient memory was available during pushing and (if necessary) resizing, otherwise false
bool push_map(Maybe* oldval, Map* m, void* k, void* v);