docs/Writerside/topics/list.h.md

changeset 1477
9170a7dff573
parent 1465
dc886f1a6155
child 1478
bba2e5efdca0
equal deleted inserted replaced
1476:79d4c281a63b 1477:9170a7dff573
378 int cxListIntersection(CxList *dst, 378 int cxListIntersection(CxList *dst,
379 const CxList *src, const CxList *other, 379 const CxList *src, const CxList *other,
380 cx_clone_func clone_func, 380 cx_clone_func clone_func,
381 const CxAllocator *clone_allocator, 381 const CxAllocator *clone_allocator,
382 void *data); 382 void *data);
383
384 int cxListUnion(CxList *dst,
385 const CxList *src, const CxList *other,
386 cx_clone_func clone_func,
387 const CxAllocator *clone_allocator,
388 void *data);
383 ``` 389 ```
384 390
385 With `cxListClone()` you can create deep copies of the elements in a list and insert them into another list. 391 With `cxListClone()` you can create deep copies of the elements in a list and insert them into another list.
386 The destination list does not need to be empty, in which case the elements will be appended. 392 The destination list does not need to be empty, in which case the elements will be appended.
387 Depending on the concrete list implementation, `cxListClone()` tries to allocate enough memory up-front, before trying 393 Depending on the concrete list implementation, `cxListClone()` tries to allocate enough memory up-front, before trying
388 to insert anything. 394 to insert anything.
389 395
390 The function `cxListDifference()` is similar to `cxListClone()`, 396 The function `cxListDifference()` clones elements from the `minuend` that are _not_ contained in the `subtrahend`,
391 except that it only clones elements from the minuend that are _not_ contained in the subtrahend, 397 while `cxListIntersection()` only clones elements from the `src` that are _also_ contained in the `other` list.
392 while `cxListIntersection()` only clones elements that _are_ contained in both lists. 398 And `cxListUnion()` clones elements from `src` first, and from `other` only when they are _not_ contained in `src`.
393 Both functions are optimized for sorted lists, in which case they will take linear time instead of quadratic time for the operation. 399
400 All three functions, for union, difference, and intersection, are optimized for sorted lists.
401 In that case they will take linear time instead of quadratic time for the operation.
402 Also, `cxListUnion()` makes sure that the elements from `src` and `other` are cloned interleaving,
403 so that the result of the union is still sorted.
404
405 However, when the `dst` list already contains elements, all functions will only append the result of the operation to that list.
406 That means, the `dst` list is only guaranteed to be sorted, when it was empty and the input lists are all sorted.
394 407
395 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it. 408 Refer to the documentation of the [clone-function callback](allocator.h.md#clone-function) to learn how to implement it.
396 409
397 The functions return zero if and only if all clone operations were successful. 410 The functions return zero if and only if all clone operations were successful.
398 411

mercurial