docs/Writerside/topics/map.h.md

changeset 1474
84de0ba791af
parent 1465
dc886f1a6155
equal deleted inserted replaced
1473:944f02992369 1474:84de0ba791af
322 int cxMapListIntersection(CxMap *dst, 322 int cxMapListIntersection(CxMap *dst,
323 const CxMap *src, const CxList *keys, 323 const CxMap *src, const CxList *keys,
324 cx_clone_func clone_func, 324 cx_clone_func clone_func,
325 const CxAllocator *clone_allocator, 325 const CxAllocator *clone_allocator,
326 void *data); 326 void *data);
327
328 int cxMapUnion(CxMap *dst, const CxMap *src,
329 cx_clone_func clone_func,
330 const CxAllocator *clone_allocator,
331 void *data);
327 ``` 332 ```
328 333
329 With `cxMapClone()` you can create deep copies of the values in one map and insert them into another map. 334 With `cxMapClone()` you can create deep copies of the values in one map and insert them into another map.
330 The destination map does not need to be empty. 335 The destination map does not need to be empty.
331 But when a key already exists in the destination map, the value is overwritten with the clone from the source map. 336 But when a key already exists in the destination map, the value is overwritten with the clone from the source map.
335 except that they only clone an element from the source map, when the key is _not_ contained in the 340 except that they only clone an element from the source map, when the key is _not_ contained in the
336 other map (or list, respectively). 341 other map (or list, respectively).
337 This is equivalent to computing the set difference for the set of keys. 342 This is equivalent to computing the set difference for the set of keys.
338 Likewise, `cxMapIntersection()` and `cxMapListIntersection()` only clone an element from the source map, 343 Likewise, `cxMapIntersection()` and `cxMapListIntersection()` only clone an element from the source map,
339 when the key is contained in _both_ collections. 344 when the key is contained in _both_ collections.
345 The function `cxMapUnion()` only clones elements from `src` to `dst` when their key is not present in `dst`.
346
347 > The function `cxMapUnion()` does not operate on three maps for the sake of simplicity.
348 > If you want to combine two maps without modifying either of them, you can first use `cxMapClone()`
349 > to clone the first map into a new, empty, map, and then use `cxMapUnion()`.
340 350
341 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it. 351 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it.
342 352
343 The functions return zero if and only if all clone operations were successful. 353 The functions return zero if and only if all clone operations were successful.
344 354

mercurial