385 cx_compare_func cmp_func |
385 cx_compare_func cmp_func |
386 ); |
386 ); |
387 |
387 |
388 /** |
388 /** |
389 * Inserts a chain of nodes into a sorted linked list. |
389 * Inserts a chain of nodes into a sorted linked list. |
390 * The chain must not be part of any list already. |
390 * The chain must not be part of any list yet. |
391 * |
391 * |
392 * If either the list starting with the node pointed to by @p begin or the list |
392 * If either the list starting with the node pointed to by @p begin or the list |
393 * starting with @p insert_begin is not sorted, the behavior is undefined. |
393 * starting with @p insert_begin is not sorted, the behavior is undefined. |
394 * |
394 * |
395 * @attention In contrast to cx_linked_list_insert_chain(), the source chain |
395 * @attention In contrast to cx_linked_list_insert_chain(), the source chain |
405 * @param cmp_func a compare function that will receive the node pointers |
405 * @param cmp_func a compare function that will receive the node pointers |
406 */ |
406 */ |
407 cx_attr_nonnull_arg(1, 5, 6) |
407 cx_attr_nonnull_arg(1, 5, 6) |
408 cx_attr_export |
408 cx_attr_export |
409 void cx_linked_list_insert_sorted_chain( |
409 void cx_linked_list_insert_sorted_chain( |
|
410 void **begin, |
|
411 void **end, |
|
412 ptrdiff_t loc_prev, |
|
413 ptrdiff_t loc_next, |
|
414 void *insert_begin, |
|
415 cx_compare_func cmp_func |
|
416 ); |
|
417 |
|
418 /** |
|
419 * Inserts a node into a sorted linked list if no other node with the same value already exists. |
|
420 * The new node must not be part of any list yet. |
|
421 * |
|
422 * If the list starting with the node pointed to by @p begin is not sorted |
|
423 * already, the behavior is undefined. |
|
424 * |
|
425 * @param begin a pointer to the beginning node pointer (required) |
|
426 * @param end a pointer to the end node pointer (if your list has one) |
|
427 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
|
428 * @param loc_next the location of a @c next pointer within your node struct (required) |
|
429 * @param new_node a pointer to the node that shall be inserted |
|
430 * @param cmp_func a compare function that will receive the node pointers |
|
431 * @retval zero when the node was inserted |
|
432 * @retval non-zero when a node with the same value already exists |
|
433 */ |
|
434 cx_attr_nonnull_arg(1, 5, 6) |
|
435 cx_attr_export |
|
436 int cx_linked_list_insert_unique( |
|
437 void **begin, |
|
438 void **end, |
|
439 ptrdiff_t loc_prev, |
|
440 ptrdiff_t loc_next, |
|
441 void *new_node, |
|
442 cx_compare_func cmp_func |
|
443 ); |
|
444 |
|
445 /** |
|
446 * Inserts a chain of nodes into a sorted linked list, avoiding duplicates. |
|
447 * The chain must not be part of any list yet. |
|
448 * |
|
449 * If either the list starting with the node pointed to by @p begin or the list |
|
450 * starting with @p insert_begin is not sorted, the behavior is undefined. |
|
451 * Also, the chain to be inserted must not contain duplicates within itself. |
|
452 * |
|
453 * @attention In contrast to cx_linked_list_insert_sorted(), not all nodes of the |
|
454 * chain might be added. This function returns a new chain consisting of all the duplicates. |
|
455 * |
|
456 * @param begin a pointer to the beginning node pointer (required) |
|
457 * @param end a pointer to the end node pointer (if your list has one) |
|
458 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
|
459 * @param loc_next the location of a @c next pointer within your node struct (required) |
|
460 * @param insert_begin a pointer to the first node of the chain that shall be inserted |
|
461 * @param cmp_func a compare function that will receive the node pointers |
|
462 * @return a pointer to a new chain with all duplicates which were not inserted (or @c NULL when there were no duplicates) |
|
463 */ |
|
464 cx_attr_nonnull_arg(1, 5, 6) |
|
465 cx_attr_nodiscard |
|
466 cx_attr_export |
|
467 void *cx_linked_list_insert_unique_chain( |
410 void **begin, |
468 void **begin, |
411 void **end, |
469 void **end, |
412 ptrdiff_t loc_prev, |
470 ptrdiff_t loc_prev, |
413 ptrdiff_t loc_next, |
471 ptrdiff_t loc_next, |
414 void *insert_begin, |
472 void *insert_begin, |