cf_map_set¶
Category: map
GitHub: cute_map.h
Adds or updates a {key, item} pair in the map.
| 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, so you can use pointers as keys. |
v |
The item to place in the map. |
Code Example¶
Set and get a few elements from a map.
CF_MAP(int) table = NULL;
map_set(table, 0, 5);
map_set(table, 1, 12);
CF_ASSERT(map_get(table, 0) == 5);
CF_ASSERT(map_get(table, 1) == 12);
map_free(table);
Remarks¶
If the key already exists, the value is overwritten. The map may reallocate internally, invalidating all pointers to elements within the map. Therefore, items may not store pointers to themselves or other items in the same map. Indices, however, are stable.
Related Pages¶
CF_MAP
cf_map_get
cf_map_get_ptr
cf_map_has
cf_map_del
cf_map_clear
cf_map_keys
cf_map_items
cf_map_swap
cf_map_size
cf_map_free