191 |
191 |
192 ```C |
192 ```C |
193 #include <cx/map.h> |
193 #include <cx/map.h> |
194 |
194 |
195 int cxMapPut(CxMap *map, KeyType key, void *value); |
195 int cxMapPut(CxMap *map, KeyType key, void *value); |
196 ``` |
196 |
197 |
197 void *cxMapEmplace(CxMap *map, KeyType key); |
198 The function `cxMapPut()` stores the specified `key` / `value` pair. |
198 ``` |
|
199 |
|
200 The function `cxMapPut()` stores the specified `key` / `value` pair, |
|
201 and returns zero if the element was successfully put into the map and non-zero otherwise. |
199 |
202 |
200 The key is always copied. |
203 The key is always copied. |
201 The behavior for the value is dependent on whether the map is storing pointers. |
204 The behavior for the value is dependent on whether the map is storing pointers. |
202 If it is storing pointers, the `value` pointer is directly stored in the map. |
205 If it is storing pointers, the `value` pointer is directly stored in the map. |
203 Otherwise, the memory pointed to by `value` is copied, using the element size of the collection. |
206 Otherwise, the memory pointed to by `value` is copied, using the element size of the collection. |
204 |
207 |
205 If an element is already associated with the specified key, it is replaced. |
208 The function `cxMapEmplace()` is similar to `cxMapPut()`, but instead of adding an existing value to the map, |
|
209 it returns a pointer to newly allocated memory for the value. |
|
210 The memory is allocated using the allocator of the map. |
|
211 If the map is storing pointers, the allocated memory will only be that for a pointer. |
|
212 Otherwise, the memory is allocated using the known element size. |
|
213 |
|
214 Both functions, if an element is already associated with the specified key, replace the existing element. |
206 If [destructor functions](collection.h.md#destructor-functions) are registered, |
215 If [destructor functions](collection.h.md#destructor-functions) are registered, |
207 they are invoked for the old element before it is replaced. |
216 they are invoked for the old element before it is replaced. |
208 |
|
209 This function returns zero if the element was successfully put into the map and non-zero otherwise. |
|
210 |
217 |
211 ## Access |
218 ## Access |
212 |
219 |
213 ```C |
220 ```C |
214 #include <cx/map.h> |
221 #include <cx/map.h> |