57 |
57 |
58 Starting with the `begin` node, the function checks if the next node is exactly the `node` (by pointer-comparison). |
58 Starting with the `begin` node, the function checks if the next node is exactly the `node` (by pointer-comparison). |
59 If true, the function terminates and returns the current node. |
59 If true, the function terminates and returns the current node. |
60 Otherwise, it moves on with the search. |
60 Otherwise, it moves on with the search. |
61 If `begin` is already the searched `node`, this function immediately returns `NULL` as there is no predecessor. |
61 If `begin` is already the searched `node`, this function immediately returns `NULL` as there is no predecessor. |
62 Note carefully, that the behavior of this function is not defined when `node` is not contained in the list that starts with `begin`. |
62 Note carefully that the behavior of this function is not defined when `node` is not contained in the list that starts with `begin`. |
63 |
63 |
64 > It is advisable to use the low-level functions inside own custom functions that you define particularly for your lists. |
64 > It is advisable to use the low-level functions inside own custom functions that you define particularly for your lists. |
65 > Otherwise you will get a lot of boilerplate code when specifying the offsets to the pointers in your node structure in every call |
65 > Otherwise you will get a lot of boilerplate code when specifying the offsets to the pointers in your node structure in every call |
66 > across your entire program. |
66 > across your entire program. |
67 |
67 |
206 size_t cx_linked_list_remove_chain(void **begin, void **end, |
206 size_t cx_linked_list_remove_chain(void **begin, void **end, |
207 ptrdiff_t loc_prev, ptrdiff_t loc_next, |
207 ptrdiff_t loc_prev, ptrdiff_t loc_next, |
208 void *node, size_t num); |
208 void *node, size_t num); |
209 ``` |
209 ``` |
210 |
210 |
211 You can either remove a single element or a specified number of subsequent elements from list. |
211 You can either remove a single element or a specified number of subsequent elements from the list. |
212 |
212 |
213 The function `cx_linked_list_remove()` is equivalent to `cx_linked_list_remove_chain()` where `num` is set to one. |
213 The function `cx_linked_list_remove()` is equivalent to `cx_linked_list_remove_chain()` where `num` is set to one. |
214 |
214 |
215 The function `cx_linked_list_remove_chain()` removes up to `num` number of nodes from the list where `node` is contained, including `node` itself. |
215 The function `cx_linked_list_remove_chain()` removes up to `num` number of nodes from the list where `node` is contained, including `node` itself. |
216 It returns the actual number of removed elements, which might be smaller when the list does not contain at least `num` elements. |
216 It returns the actual number of removed elements, which might be smaller when the list does not contain at least `num` elements. |
270 In the natural case, `begin_left` and `begin_right` point to the first node of either list, |
270 In the natural case, `begin_left` and `begin_right` point to the first node of either list, |
271 and `loc_advance` is the offset of the `next` pointer. |
271 and `loc_advance` is the offset of the `next` pointer. |
272 But it is also possible to start with the _last_ node of both lists and use the `prev` pointer to compare them backwards. |
272 But it is also possible to start with the _last_ node of both lists and use the `prev` pointer to compare them backwards. |
273 |
273 |
274 The `loc_data` offset is used to calculate the pointer that is passed to the `cmp_fnc`. |
274 The `loc_data` offset is used to calculate the pointer that is passed to the `cmp_fnc`. |
275 This can either be the offset of a specific field in the struct, or simply zero in which case the pointers to the nodes themselves are passed to the compare function. |
275 This can either be the offset of a specific field in the struct or simply zero, in which case the pointers to the nodes themselves are passed to the compare function. |
276 |
276 |
277 <seealso> |
277 <seealso> |
278 <category ref="apidoc"> |
278 <category ref="apidoc"> |
279 <a href="https://ucx.sourceforge.io/api/linked__list_8h.html">linked_list.h</a> |
279 <a href="https://ucx.sourceforge.io/api/linked__list_8h.html">linked_list.h</a> |
280 </category> |
280 </category> |