docs/Writerside/topics/map.h.md

changeset 1447
aaf85b3e9601
parent 1445
e8089a590b71
equal deleted inserted replaced
1446:5732947cbcc2 1447:aaf85b3e9601
298 298
299 int cxMapClone(CxMap *dst, const CxMap *src, 299 int cxMapClone(CxMap *dst, const CxMap *src,
300 cx_clone_func clone_func, 300 cx_clone_func clone_func,
301 const CxAllocator *clone_allocator, 301 const CxAllocator *clone_allocator,
302 void *data); 302 void *data);
303
304 int cxMapDifference(CxMap *dst,
305 const CxMap *minuend, const CxMap *subtrahend,
306 cx_clone_func clone_func,
307 const CxAllocator *clone_allocator,
308 void *data);
309
310 int cxMapListDifference(CxMap *dst,
311 const CxMap *src, const CxList *keys,
312 cx_clone_func clone_func,
313 const CxAllocator *clone_allocator,
314 void *data);
303 ``` 315 ```
304 316
305 With `cxMapClone()` you can create deep copies of the values in one map and insert them into another map. 317 With `cxMapClone()` you can create deep copies of the values in one map and insert them into another map.
306 The destination map does not need to be empty. 318 The destination map does not need to be empty.
307 But when a key already exists in the destination map, the value is overwritten with the clone from the source map. 319 But when a key already exists in the destination map, the value is overwritten with the clone from the source map.
308 If the destination map has destructors defined, they are called for the replaced element. 320 If the destination map has destructors defined, they are called for the replaced element.
309 321
322 The functions `cxMapDifference()` and `cxMapListDifference()` are similar to `cxMapClone()`
323 except that they only clone an element from the source map, when the key is _not_ contained in the
324 other map (or list, respectively).
325 This is equivalent to computing the set difference for the set of keys.
326
310 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it. 327 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it.
311 328
312 The function returns zero if and only if all clone operations were successful. 329 The functions return zero if and only if all clone operations were successful.
313 330
314 > It is perfectly possible to clone items into a map of a different type. 331 > It is perfectly possible to clone items into a map of a different type.
315 > For example, you can clone entries from a map that is just storing pointers (`CX_STORE_POINTERS`) to a map that 332 > For example, you can clone entries from a map that is just storing pointers (`CX_STORE_POINTERS`) to a map that
316 > allocates the memory for the objects (and vice versa). 333 > allocates the memory for the objects (and vice versa).
317 334

mercurial