C Collections

cbstmap · Section 3

cbmap_get

cbmap_get - get value by key (type-inferred, returns value)

C Collections (libccollections, -lccollections)

#include <ccollections/cbstmap.h>
 
value = cbmap_get(hm_name, key);

Type-inferred wrapper for cbstmap_get_elem_ref() that returns the value
itself. It calls ccol__fatal_err() when the key is not in the map and also
when the two sizes don't match.
 
The lookup key is converted through the DECLARED key type of the tree,
just as cbmap_insert(3) converts it, so a key stored through that
conversion is found again only by a lookup that makes the same
conversion. Both a literal and a computed expression are accepted.

hm_name  BST map to search
key      Key to look up

The value of that key.

The macro returns the value, not a pointer to it; for a string that is the
char* itself.
 
It stops the program when the key is not in the map, when key is a NULL
character pointer (which is not a string, so the error is
ccol_invalid_args), and when the size of the stored value doesn't match
the size of the declared value type.
 
The search takes O(log n) time.

cbmap_get_ptr(3), cbmap_insert(3)