| 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 cxMapCloneSimple(CxMap *dst, const CxMap *src); |
| 303 |
305 |
| 304 int cxMapDifference(CxMap *dst, |
306 int cxMapDifference(CxMap *dst, |
| 305 const CxMap *minuend, const CxMap *subtrahend, |
307 const CxMap *minuend, const CxMap *subtrahend, |
| 306 cx_clone_func clone_func, |
308 cx_clone_func clone_func, |
| 307 const CxAllocator *clone_allocator, |
309 const CxAllocator *clone_allocator, |
| 308 void *data); |
310 void *data); |
| 309 |
311 |
| |
312 int cxMapDifferenceSimple(CxMap *dst, |
| |
313 const CxMap *minuend, const CxMap *subtrahend); |
| |
314 |
| 310 int cxMapListDifference(CxMap *dst, |
315 int cxMapListDifference(CxMap *dst, |
| 311 const CxMap *src, const CxList *keys, |
316 const CxMap *src, const CxList *keys, |
| 312 cx_clone_func clone_func, |
317 cx_clone_func clone_func, |
| 313 const CxAllocator *clone_allocator, |
318 const CxAllocator *clone_allocator, |
| 314 void *data); |
319 void *data); |
| 315 |
320 |
| |
321 int cxMapListDifferenceSimple(CxMap *dst, |
| |
322 const CxMap *src, const CxList *keys); |
| |
323 |
| 316 int cxMapIntersection(CxMap *dst, |
324 int cxMapIntersection(CxMap *dst, |
| 317 const CxMap *src, const CxMap *other, |
325 const CxMap *src, const CxMap *other, |
| 318 cx_clone_func clone_func, |
326 cx_clone_func clone_func, |
| 319 const CxAllocator *clone_allocator, |
327 const CxAllocator *clone_allocator, |
| 320 void *data); |
328 void *data); |
| 321 |
329 |
| |
330 int cxMapIntersectionSimple(CxMap *dst, |
| |
331 const CxMap *src, const CxMap *other); |
| |
332 |
| 322 int cxMapListIntersection(CxMap *dst, |
333 int cxMapListIntersection(CxMap *dst, |
| 323 const CxMap *src, const CxList *keys, |
334 const CxMap *src, const CxList *keys, |
| 324 cx_clone_func clone_func, |
335 cx_clone_func clone_func, |
| 325 const CxAllocator *clone_allocator, |
336 const CxAllocator *clone_allocator, |
| 326 void *data); |
337 void *data); |
| 327 |
338 |
| |
339 int cxMapListIntersectionSimple(CxMap *dst, |
| |
340 const CxMap *src, const CxList *keys); |
| |
341 |
| 328 int cxMapUnion(CxMap *dst, const CxMap *src, |
342 int cxMapUnion(CxMap *dst, const CxMap *src, |
| 329 cx_clone_func clone_func, |
343 cx_clone_func clone_func, |
| 330 const CxAllocator *clone_allocator, |
344 const CxAllocator *clone_allocator, |
| 331 void *data); |
345 void *data); |
| |
346 |
| |
347 int cxMapUnionSimple(CxMap *dst, const CxMap *src); |
| 332 ``` |
348 ``` |
| 333 |
349 |
| 334 With `cxMapClone()` you can create deep copies of the values in one map and insert them into another map. |
350 With `cxMapClone()` you can create deep copies of the values in one map and insert them into another map. |
| 335 The destination map does not need to be empty. |
351 The destination map does not need to be empty. |
| 336 But when a key already exists in the destination map, the value is overwritten with the clone from the source map. |
352 But when a key already exists in the destination map, the value is overwritten with the clone from the source map. |
| 347 > The function `cxMapUnion()` does not operate on three maps for the sake of simplicity. |
363 > 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()` |
364 > 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()`. |
365 > to clone the first map into a new, empty, map, and then use `cxMapUnion()`. |
| 350 |
366 |
| 351 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it. |
367 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it. |
| |
368 |
| |
369 The _simple_ versions of the above functions use an internal shallow clone function |
| |
370 which uses `memcpy()` to copy the values. |
| |
371 If the destination map is storing pointers, this internal clone function uses the current default allocator to allocate the memory. |
| 352 |
372 |
| 353 The functions return zero if and only if all clone operations were successful. |
373 The functions return zero if and only if all clone operations were successful. |
| 354 |
374 |
| 355 > It is perfectly possible to clone items into a map of a different type. |
375 > It is perfectly possible to clone items into a map of a different type. |
| 356 > For example, you can clone entries from a map that is just storing pointers (`CX_STORE_POINTERS`) to a map that |
376 > For example, you can clone entries from a map that is just storing pointers (`CX_STORE_POINTERS`) to a map that |