src/cx/linked_list.h

changeset 1624
aab23807d562
parent 1618
ef7cab6eb131
equal deleted inserted replaced
1623:592aae491264 1624:aab23807d562
390 cx_attr_nonnull_arg(1, 5, 6) cx_attr_nodiscard 390 cx_attr_nonnull_arg(1, 5, 6) cx_attr_nodiscard
391 CX_EXPORT void *cx_linked_list_insert_unique_chain(void **begin, void **end, 391 CX_EXPORT void *cx_linked_list_insert_unique_chain(void **begin, void **end,
392 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func); 392 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func);
393 393
394 /** 394 /**
395 * Inserts a node into a sorted linked list.
396 * The new node must not be part of any list yet.
397 *
398 * If the list starting with the node pointed to by @p begin is not sorted
399 * already, the behavior is undefined.
400 *
401 * @param begin a pointer to the beginning node pointer (required)
402 * @param end a pointer to the end node pointer (if your list has one)
403 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
404 * @param loc_next the location of a @c next pointer within your node struct (required)
405 * @param new_node a pointer to the node that shall be inserted
406 * @param cmp_func a compare function that will receive the node pointers
407 * @param context context for the compare function
408 */
409 cx_attr_nonnull_arg(1, 5, 6)
410 CX_EXPORT void cx_linked_list_insert_sorted_c(void **begin, void **end,
411 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func2 cmp_func, void *context);
412
413 /**
414 * Inserts a chain of nodes into a sorted linked list.
415 * The chain must not be part of any list yet.
416 *
417 * If either the list starting with the node pointed to by @p begin or the list
418 * starting with @p insert_begin is not sorted, the behavior is undefined.
419 *
420 * @attention In contrast to cx_linked_list_insert_chain(), the source chain
421 * will be broken and inserted into the target list so that the resulting list
422 * will be sorted according to @p cmp_func. That means each node in the source
423 * chain may be re-linked with nodes from the target list.
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 insert_begin a pointer to the first node of the chain that shall be inserted
430 * @param cmp_func a compare function that will receive the node pointers
431 * @param context context for the compare function
432 */
433 cx_attr_nonnull_arg(1, 5, 6)
434 CX_EXPORT void cx_linked_list_insert_sorted_chain_c(void **begin, void **end,
435 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func2 cmp_func, void *context);
436
437 /**
438 * Inserts a node into a sorted linked list if no other node with the same value already exists.
439 * The new node must not be part of any list yet.
440 *
441 * If the list starting with the node pointed to by @p begin is not sorted
442 * already, the behavior is undefined.
443 *
444 * @param begin a pointer to the beginning node pointer (required)
445 * @param end a pointer to the end node pointer (if your list has one)
446 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
447 * @param loc_next the location of a @c next pointer within your node struct (required)
448 * @param new_node a pointer to the node that shall be inserted
449 * @param cmp_func a compare function that will receive the node pointers
450 * @retval zero when the node was inserted
451 * @retval non-zero when a node with the same value already exists
452 */
453 cx_attr_nonnull_arg(1, 5, 6)
454 CX_EXPORT int cx_linked_list_insert_unique_c(void **begin, void **end,
455 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func2 cmp_func, void *context);
456
457 /**
458 * Inserts a chain of nodes into a sorted linked list, avoiding duplicates.
459 * The chain must not be part of any list yet.
460 *
461 * If either the list starting with the node pointed to by @p begin or the list
462 * starting with @p insert_begin is not sorted, the behavior is undefined.
463 *
464 * @attention In contrast to cx_linked_list_insert_sorted(), not all nodes of the
465 * chain might be added. This function returns a new chain consisting of all the duplicates.
466 *
467 * @param begin a pointer to the beginning node pointer (required)
468 * @param end a pointer to the end node pointer (if your list has one)
469 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
470 * @param loc_next the location of a @c next pointer within your node struct (required)
471 * @param insert_begin a pointer to the first node of the chain that shall be inserted
472 * @param cmp_func a compare function that will receive the node pointers
473 * @param context context for the compare function
474 * @return a pointer to a new chain with all duplicates that were not inserted (or @c NULL when there were no duplicates)
475 */
476 cx_attr_nonnull_arg(1, 5, 6) cx_attr_nodiscard
477 CX_EXPORT void *cx_linked_list_insert_unique_chain_c(void **begin, void **end,
478 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func2 cmp_func, void *context);
479
480 /**
395 * Removes a chain of nodes from the linked list. 481 * Removes a chain of nodes from the linked list.
396 * 482 *
397 * If one of the nodes to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end) 483 * If one of the nodes to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end)
398 * addresses are provided, the pointers are adjusted accordingly. 484 * addresses are provided, the pointers are adjusted accordingly.
399 * 485 *

mercurial