| 366 |
366 |
| 367 int cxListClone(CxList *dst, const CxList *src, |
367 int cxListClone(CxList *dst, const CxList *src, |
| 368 cx_clone_func clone_func, |
368 cx_clone_func clone_func, |
| 369 const CxAllocator *clone_allocator, |
369 const CxAllocator *clone_allocator, |
| 370 void *data); |
370 void *data); |
| |
371 |
| |
372 int cxListDifference(CxList *dst, |
| |
373 const CxList *minuend, const CxList *subtrahend, |
| |
374 cx_clone_func clone_func, |
| |
375 const CxAllocator *clone_allocator, |
| |
376 void *data); |
| 371 ``` |
377 ``` |
| 372 |
378 |
| 373 With `cxListClone()` you can create deep copies of the elements in a list and insert them into another list. |
379 With `cxListClone()` you can create deep copies of the elements in a list and insert them into another list. |
| 374 The destination list does not need to be empty, in which case the elements will be appended. |
380 The destination list does not need to be empty, in which case the elements will be appended. |
| 375 Depending on the concrete list implementation, `cxListClone()` tries to allocate enough memory up-front, before trying |
381 Depending on the concrete list implementation, `cxListClone()` tries to allocate enough memory up-front, before trying |
| 376 to insert anything. |
382 to insert anything. |
| 377 |
383 |
| |
384 The function `cxListDifference()` is similar to `cxListClone()`, |
| |
385 except that it only clones elements from the minuend that are _not_ contained in the subtrahend. |
| |
386 It is optimized for sorted lists, in which case it will take linear time instead of quadratic time for the operation. |
| |
387 |
| 378 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it. |
388 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it. |
| 379 |
389 |
| 380 The function returns zero if and only if all clone operations were successful. |
390 The functions return zero if and only if all clone operations were successful. |
| 381 |
391 |
| 382 > It is perfectly possible to clone items into a list of a different type. |
392 > It is perfectly possible to clone items into a list of a different type. |
| 383 > For example, you can clone elements from a list that is just storing pointers (`CX_STORE_POINTERS`) to a list that |
393 > For example, you can clone elements from a list that is just storing pointers (`CX_STORE_POINTERS`) to a list that |
| 384 > allocates the memory for the objects (and vice versa). |
394 > allocates the memory for the objects (and vice versa). |
| 385 |
395 |