cf_map_get_ptr¶
Category: map
GitHub: cute_map.h
Fetches a pointer to the item that k maps to.
| Parameters | Description |
|---|---|
m |
The map. Can be NULL. Must be declared with CF_MAP(T). |
k |
The key for lookups. Keys are always typecast to uint64_t. |
Return Value¶
Returns a pointer to the item, or NULL if not found.
Code Example¶
Get a pointer to an element in a map.
CF_MAP(CF_V2) table = NULL;
map_set(table, 10, cf_v2(-1, 1));
CF_V2* v = map_get_ptr(table, 10);
CF_ASSERT(v);
CF_ASSERT(v->x == -1);
CF_ASSERT(v->y == 1);
map_free(table);
Remarks¶
If you want to fetch an item by value, use map_get. The returned pointer is not stable across
insertions -- adding new items may cause reallocation and invalidate all pointers.
Related Pages¶
CF_MAP
cf_map_set
cf_map_get
cf_map_has
cf_map_del
cf_map_clear
cf_map_keys
cf_map_items
cf_map_swap
cf_map_size
cf_map_free