88 * (if @c NULL, and the list is not storing pointers, sort and find |
88 * (if @c NULL, and the list is not storing pointers, sort and find |
89 * functions will not work) |
89 * functions will not work) |
90 * @param elem_size the size of each element in bytes |
90 * @param elem_size the size of each element in bytes |
91 * @return the created list |
91 * @return the created list |
92 */ |
92 */ |
93 cx_attr_nodiscard |
93 cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxListFree, 1) |
94 cx_attr_malloc |
94 CX_EXPORT CxList *cxLinkedListCreate(const CxAllocator *allocator, |
95 cx_attr_dealloc(cxListFree, 1) |
95 cx_compare_func comparator, size_t elem_size); |
96 cx_attr_export |
|
97 CxList *cxLinkedListCreate( |
|
98 const CxAllocator *allocator, |
|
99 cx_compare_func comparator, |
|
100 size_t elem_size |
|
101 ); |
|
102 |
96 |
103 /** |
97 /** |
104 * Allocates a linked list for storing elements with @p elem_size bytes each. |
98 * Allocates a linked list for storing elements with @p elem_size bytes each. |
105 * |
99 * |
106 * The list will use cxDefaultAllocator and no comparator function. If you want |
100 * The list will use cxDefaultAllocator and no comparator function. If you want |
113 * |
107 * |
114 * @param elem_size (@c size_t) the size of each element in bytes |
108 * @param elem_size (@c size_t) the size of each element in bytes |
115 * @return (@c CxList*) the created list |
109 * @return (@c CxList*) the created list |
116 */ |
110 */ |
117 #define cxLinkedListCreateSimple(elem_size) \ |
111 #define cxLinkedListCreateSimple(elem_size) \ |
118 cxLinkedListCreate(NULL, NULL, elem_size) |
112 cxLinkedListCreate(NULL, NULL, elem_size) |
119 |
113 |
120 /** |
114 /** |
121 * Finds the node at a certain index. |
115 * Finds the node at a certain index. |
122 * |
116 * |
123 * This function can be used to start at an arbitrary position within the list. |
117 * This function can be used to start at an arbitrary position within the list. |
132 * @param start_index the start index |
126 * @param start_index the start index |
133 * @param loc_advance the location of the pointer to advance |
127 * @param loc_advance the location of the pointer to advance |
134 * @param index the search index |
128 * @param index the search index |
135 * @return the node found at the specified index |
129 * @return the node found at the specified index |
136 */ |
130 */ |
137 cx_attr_nonnull |
131 cx_attr_nonnull cx_attr_nodiscard |
138 cx_attr_nodiscard |
132 CX_EXPORT void *cx_linked_list_at(const void *start,size_t start_index, |
139 cx_attr_export |
133 ptrdiff_t loc_advance, size_t index); |
140 void *cx_linked_list_at( |
|
141 const void *start, |
|
142 size_t start_index, |
|
143 ptrdiff_t loc_advance, |
|
144 size_t index |
|
145 ); |
|
146 |
134 |
147 /** |
135 /** |
148 * Finds the node containing an element within a linked list. |
136 * Finds the node containing an element within a linked list. |
149 * |
137 * |
150 * @param start a pointer to the start node |
138 * @param start a pointer to the start node |
155 * @param found_index an optional pointer where the index of the found node |
143 * @param found_index an optional pointer where the index of the found node |
156 * (given that @p start has index 0) is stored |
144 * (given that @p start has index 0) is stored |
157 * @return a pointer to the found node or @c NULL if no matching node was found |
145 * @return a pointer to the found node or @c NULL if no matching node was found |
158 */ |
146 */ |
159 cx_attr_nonnull_arg(1, 4, 5) |
147 cx_attr_nonnull_arg(1, 4, 5) |
160 cx_attr_export |
148 CX_EXPORT void *cx_linked_list_find(const void *start, ptrdiff_t loc_advance, |
161 void *cx_linked_list_find( |
149 ptrdiff_t loc_data, cx_compare_func cmp_func, const void *elem, |
162 const void *start, |
150 size_t *found_index); |
163 ptrdiff_t loc_advance, |
|
164 ptrdiff_t loc_data, |
|
165 cx_compare_func cmp_func, |
|
166 const void *elem, |
|
167 size_t *found_index |
|
168 ); |
|
169 |
151 |
170 /** |
152 /** |
171 * Finds the first node in a linked list. |
153 * Finds the first node in a linked list. |
172 * |
154 * |
173 * The function starts with the pointer denoted by @p node and traverses the list |
155 * The function starts with the pointer denoted by @p node and traverses the list |
176 * |
158 * |
177 * @param node a pointer to a node in the list |
159 * @param node a pointer to a node in the list |
178 * @param loc_prev the location of the @c prev pointer |
160 * @param loc_prev the location of the @c prev pointer |
179 * @return a pointer to the first node |
161 * @return a pointer to the first node |
180 */ |
162 */ |
181 cx_attr_nonnull |
163 cx_attr_nonnull cx_attr_returns_nonnull |
182 cx_attr_returns_nonnull |
164 CX_EXPORT void *cx_linked_list_first(const void *node, ptrdiff_t loc_prev); |
183 cx_attr_export |
|
184 void *cx_linked_list_first( |
|
185 const void *node, |
|
186 ptrdiff_t loc_prev |
|
187 ); |
|
188 |
165 |
189 /** |
166 /** |
190 * Finds the last node in a linked list. |
167 * Finds the last node in a linked list. |
191 * |
168 * |
192 * The function starts with the pointer denoted by @p node and traverses the list |
169 * The function starts with the pointer denoted by @p node and traverses the list |
195 * |
172 * |
196 * @param node a pointer to a node in the list |
173 * @param node a pointer to a node in the list |
197 * @param loc_next the location of the @c next pointer |
174 * @param loc_next the location of the @c next pointer |
198 * @return a pointer to the last node |
175 * @return a pointer to the last node |
199 */ |
176 */ |
200 cx_attr_nonnull |
177 cx_attr_nonnull cx_attr_returns_nonnull |
201 cx_attr_returns_nonnull |
178 CX_EXPORT void *cx_linked_list_last(const void *node, ptrdiff_t loc_next); |
202 cx_attr_export |
|
203 void *cx_linked_list_last( |
|
204 const void *node, |
|
205 ptrdiff_t loc_next |
|
206 ); |
|
207 |
179 |
208 /** |
180 /** |
209 * Finds the predecessor of a node in case it is not linked. |
181 * Finds the predecessor of a node in case it is not linked. |
210 * |
182 * |
211 * @remark If @p node is not contained in the list starting with @p begin, the behavior is undefined. |
183 * @remark If @p node is not contained in the list starting with @p begin, the behavior is undefined. |
214 * @param loc_next the location of the @c next pointer |
186 * @param loc_next the location of the @c next pointer |
215 * @param node the successor of the node to find |
187 * @param node the successor of the node to find |
216 * @return the node or @c NULL if @p node has no predecessor |
188 * @return the node or @c NULL if @p node has no predecessor |
217 */ |
189 */ |
218 cx_attr_nonnull |
190 cx_attr_nonnull |
219 cx_attr_export |
191 CX_EXPORT void *cx_linked_list_prev(const void *begin, ptrdiff_t loc_next, const void *node); |
220 void *cx_linked_list_prev( |
|
221 const void *begin, |
|
222 ptrdiff_t loc_next, |
|
223 const void *node |
|
224 ); |
|
225 |
192 |
226 /** |
193 /** |
227 * Adds a new node to a linked list. |
194 * Adds a new node to a linked list. |
228 * The node must not be part of any list yet. |
195 * The node must not be part of any list yet. |
229 * |
196 * |
234 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
201 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
235 * @param loc_next the location of a @c next pointer within your node struct (required) |
202 * @param loc_next the location of a @c next pointer within your node struct (required) |
236 * @param new_node a pointer to the node that shall be appended |
203 * @param new_node a pointer to the node that shall be appended |
237 */ |
204 */ |
238 cx_attr_nonnull_arg(5) |
205 cx_attr_nonnull_arg(5) |
239 cx_attr_export |
206 CX_EXPORT void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); |
240 void cx_linked_list_add( |
|
241 void **begin, |
|
242 void **end, |
|
243 ptrdiff_t loc_prev, |
|
244 ptrdiff_t loc_next, |
|
245 void *new_node |
|
246 ); |
|
247 |
207 |
248 /** |
208 /** |
249 * Prepends a new node to a linked list. |
209 * Prepends a new node to a linked list. |
250 * The node must not be part of any list yet. |
210 * The node must not be part of any list yet. |
251 * |
211 * |
256 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
216 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
257 * @param loc_next the location of a @c next pointer within your node struct (required) |
217 * @param loc_next the location of a @c next pointer within your node struct (required) |
258 * @param new_node a pointer to the node that shall be prepended |
218 * @param new_node a pointer to the node that shall be prepended |
259 */ |
219 */ |
260 cx_attr_nonnull_arg(5) |
220 cx_attr_nonnull_arg(5) |
261 cx_attr_export |
221 CX_EXPORT void cx_linked_list_prepend(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); |
262 void cx_linked_list_prepend( |
|
263 void **begin, |
|
264 void **end, |
|
265 ptrdiff_t loc_prev, |
|
266 ptrdiff_t loc_next, |
|
267 void *new_node |
|
268 ); |
|
269 |
222 |
270 /** |
223 /** |
271 * Links two nodes. |
224 * Links two nodes. |
272 * |
225 * |
273 * @param left the new predecessor of @p right |
226 * @param left the new predecessor of @p right |
274 * @param right the new successor of @p left |
227 * @param right the new successor of @p left |
275 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
228 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
276 * @param loc_next the location of a @c next pointer within your node struct (required) |
229 * @param loc_next the location of a @c next pointer within your node struct (required) |
277 */ |
230 */ |
278 cx_attr_nonnull |
231 cx_attr_nonnull |
279 cx_attr_export |
232 CX_EXPORT void cx_linked_list_link(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next); |
280 void cx_linked_list_link( |
|
281 void *left, |
|
282 void *right, |
|
283 ptrdiff_t loc_prev, |
|
284 ptrdiff_t loc_next |
|
285 ); |
|
286 |
233 |
287 /** |
234 /** |
288 * Unlinks two nodes. |
235 * Unlinks two nodes. |
289 * |
236 * |
290 * If right is not the successor of left, the behavior is undefined. |
237 * If right is not the successor of left, the behavior is undefined. |
293 * @param right the successor of @p left |
240 * @param right the successor of @p left |
294 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
241 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
295 * @param loc_next the location of a @c next pointer within your node struct (required) |
242 * @param loc_next the location of a @c next pointer within your node struct (required) |
296 */ |
243 */ |
297 cx_attr_nonnull |
244 cx_attr_nonnull |
298 cx_attr_export |
245 CX_EXPORT void cx_linked_list_unlink(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next); |
299 void cx_linked_list_unlink( |
|
300 void *left, |
|
301 void *right, |
|
302 ptrdiff_t loc_prev, |
|
303 ptrdiff_t loc_next |
|
304 ); |
|
305 |
246 |
306 /** |
247 /** |
307 * Inserts a new node after a given node of a linked list. |
248 * Inserts a new node after a given node of a linked list. |
308 * The new node must not be part of any list yet. |
249 * The new node must not be part of any list yet. |
309 * |
250 * |
316 * @param loc_next the location of a @c next pointer within your node struct (required) |
257 * @param loc_next the location of a @c next pointer within your node struct (required) |
317 * @param node the node after which to insert (@c NULL if you want to prepend the node to the list) |
258 * @param node the node after which to insert (@c NULL if you want to prepend the node to the list) |
318 * @param new_node a pointer to the node that shall be inserted |
259 * @param new_node a pointer to the node that shall be inserted |
319 */ |
260 */ |
320 cx_attr_nonnull_arg(6) |
261 cx_attr_nonnull_arg(6) |
321 cx_attr_export |
262 CX_EXPORT void cx_linked_list_insert(void **begin, void **end, |
322 void cx_linked_list_insert( |
263 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *new_node); |
323 void **begin, |
|
324 void **end, |
|
325 ptrdiff_t loc_prev, |
|
326 ptrdiff_t loc_next, |
|
327 void *node, |
|
328 void *new_node |
|
329 ); |
|
330 |
264 |
331 /** |
265 /** |
332 * Inserts a chain of nodes after a given node of a linked list. |
266 * Inserts a chain of nodes after a given node of a linked list. |
333 * The chain must not be part of any list yet. |
267 * The chain must not be part of any list yet. |
334 * |
268 * |
347 * @param node the node after which to insert (@c NULL to prepend the chain to the list) |
281 * @param node the node after which to insert (@c NULL to prepend the chain to the list) |
348 * @param insert_begin a pointer to the first node of the chain that shall be inserted |
282 * @param insert_begin a pointer to the first node of the chain that shall be inserted |
349 * @param insert_end a pointer to the last node of the chain (or NULL if the last node shall be determined) |
283 * @param insert_end a pointer to the last node of the chain (or NULL if the last node shall be determined) |
350 */ |
284 */ |
351 cx_attr_nonnull_arg(6) |
285 cx_attr_nonnull_arg(6) |
352 cx_attr_export |
286 CX_EXPORT void cx_linked_list_insert_chain(void **begin, void **end, |
353 void cx_linked_list_insert_chain( |
287 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *insert_begin, void *insert_end); |
354 void **begin, |
|
355 void **end, |
|
356 ptrdiff_t loc_prev, |
|
357 ptrdiff_t loc_next, |
|
358 void *node, |
|
359 void *insert_begin, |
|
360 void *insert_end |
|
361 ); |
|
362 |
288 |
363 /** |
289 /** |
364 * Inserts a node into a sorted linked list. |
290 * Inserts a node into a sorted linked list. |
365 * The new node must not be part of any list yet. |
291 * The new node must not be part of any list yet. |
366 * |
292 * |
373 * @param loc_next the location of a @c next pointer within your node struct (required) |
299 * @param loc_next the location of a @c next pointer within your node struct (required) |
374 * @param new_node a pointer to the node that shall be inserted |
300 * @param new_node a pointer to the node that shall be inserted |
375 * @param cmp_func a compare function that will receive the node pointers |
301 * @param cmp_func a compare function that will receive the node pointers |
376 */ |
302 */ |
377 cx_attr_nonnull_arg(1, 5, 6) |
303 cx_attr_nonnull_arg(1, 5, 6) |
378 cx_attr_export |
304 CX_EXPORT void cx_linked_list_insert_sorted(void **begin, void **end, |
379 void cx_linked_list_insert_sorted( |
305 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func cmp_func); |
380 void **begin, |
|
381 void **end, |
|
382 ptrdiff_t loc_prev, |
|
383 ptrdiff_t loc_next, |
|
384 void *new_node, |
|
385 cx_compare_func cmp_func |
|
386 ); |
|
387 |
306 |
388 /** |
307 /** |
389 * Inserts a chain of nodes into a sorted linked list. |
308 * Inserts a chain of nodes into a sorted linked list. |
390 * The chain must not be part of any list yet. |
309 * The chain must not be part of any list yet. |
391 * |
310 * |
403 * @param loc_next the location of a @c next pointer within your node struct (required) |
322 * @param loc_next the location of a @c next pointer within your node struct (required) |
404 * @param insert_begin a pointer to the first node of the chain that shall be inserted |
323 * @param insert_begin a pointer to the first node of the chain that shall be inserted |
405 * @param cmp_func a compare function that will receive the node pointers |
324 * @param cmp_func a compare function that will receive the node pointers |
406 */ |
325 */ |
407 cx_attr_nonnull_arg(1, 5, 6) |
326 cx_attr_nonnull_arg(1, 5, 6) |
408 cx_attr_export |
327 CX_EXPORT void cx_linked_list_insert_sorted_chain(void **begin, void **end, |
409 void cx_linked_list_insert_sorted_chain( |
328 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func); |
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 |
329 |
418 /** |
330 /** |
419 * Inserts a node into a sorted linked list if no other node with the same value already exists. |
331 * 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. |
332 * The new node must not be part of any list yet. |
421 * |
333 * |
430 * @param cmp_func a compare function that will receive the node pointers |
342 * @param cmp_func a compare function that will receive the node pointers |
431 * @retval zero when the node was inserted |
343 * @retval zero when the node was inserted |
432 * @retval non-zero when a node with the same value already exists |
344 * @retval non-zero when a node with the same value already exists |
433 */ |
345 */ |
434 cx_attr_nonnull_arg(1, 5, 6) |
346 cx_attr_nonnull_arg(1, 5, 6) |
435 cx_attr_export |
347 CX_EXPORT int cx_linked_list_insert_unique(void **begin, void **end, |
436 int cx_linked_list_insert_unique( |
348 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func cmp_func); |
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 |
349 |
445 /** |
350 /** |
446 * Inserts a chain of nodes into a sorted linked list, avoiding duplicates. |
351 * Inserts a chain of nodes into a sorted linked list, avoiding duplicates. |
447 * The chain must not be part of any list yet. |
352 * The chain must not be part of any list yet. |
448 * |
353 * |
458 * @param loc_next the location of a @c next pointer within your node struct (required) |
363 * @param loc_next the location of a @c next pointer within your node struct (required) |
459 * @param insert_begin a pointer to the first node of the chain that shall be inserted |
364 * @param insert_begin a pointer to the first node of the chain that shall be inserted |
460 * @param cmp_func a compare function that will receive the node pointers |
365 * @param cmp_func a compare function that will receive the node pointers |
461 * @return a pointer to a new chain with all duplicates that were not inserted (or @c NULL when there were no duplicates) |
366 * @return a pointer to a new chain with all duplicates that were not inserted (or @c NULL when there were no duplicates) |
462 */ |
367 */ |
463 cx_attr_nonnull_arg(1, 5, 6) |
368 cx_attr_nonnull_arg(1, 5, 6) cx_attr_nodiscard |
464 cx_attr_nodiscard |
369 CX_EXPORT void *cx_linked_list_insert_unique_chain(void **begin, void **end, |
465 cx_attr_export |
370 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func); |
466 void *cx_linked_list_insert_unique_chain( |
|
467 void **begin, |
|
468 void **end, |
|
469 ptrdiff_t loc_prev, |
|
470 ptrdiff_t loc_next, |
|
471 void *insert_begin, |
|
472 cx_compare_func cmp_func |
|
473 ); |
|
474 |
371 |
475 /** |
372 /** |
476 * Removes a chain of nodes from the linked list. |
373 * Removes a chain of nodes from the linked list. |
477 * |
374 * |
478 * If one of the nodes to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end) |
375 * If one of the nodes to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end) |
492 * @param node the start node of the chain |
389 * @param node the start node of the chain |
493 * @param num the number of nodes to remove |
390 * @param num the number of nodes to remove |
494 * @return the actual number of nodes that were removed (can be less when the list did not have enough nodes) |
391 * @return the actual number of nodes that were removed (can be less when the list did not have enough nodes) |
495 */ |
392 */ |
496 cx_attr_nonnull_arg(5) |
393 cx_attr_nonnull_arg(5) |
497 cx_attr_export |
394 CX_EXPORT size_t cx_linked_list_remove_chain(void **begin, void **end, |
498 size_t cx_linked_list_remove_chain( |
395 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, size_t num); |
499 void **begin, |
|
500 void **end, |
|
501 ptrdiff_t loc_prev, |
|
502 ptrdiff_t loc_next, |
|
503 void *node, |
|
504 size_t num |
|
505 ); |
|
506 |
396 |
507 /** |
397 /** |
508 * Removes a node from the linked list. |
398 * Removes a node from the linked list. |
509 * |
399 * |
510 * If the node to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end) |
400 * If the node to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end) |
522 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
412 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
523 * @param loc_next the location of a @c next pointer within your node struct (required) |
413 * @param loc_next the location of a @c next pointer within your node struct (required) |
524 * @param node the node to remove |
414 * @param node the node to remove |
525 */ |
415 */ |
526 cx_attr_nonnull_arg(5) |
416 cx_attr_nonnull_arg(5) |
527 static inline void cx_linked_list_remove( |
417 CX_EXPORT void cx_linked_list_remove(void **begin, void **end, |
528 void **begin, |
418 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node); |
529 void **end, |
|
530 ptrdiff_t loc_prev, |
|
531 ptrdiff_t loc_next, |
|
532 void *node |
|
533 ) { |
|
534 cx_linked_list_remove_chain(begin, end, loc_prev, loc_next, node, 1); |
|
535 } |
|
536 |
419 |
537 /** |
420 /** |
538 * Determines the size of a linked list starting with @p node. |
421 * Determines the size of a linked list starting with @p node. |
539 * |
422 * |
540 * @param node the first node |
423 * @param node the first node |
541 * @param loc_next the location of the @c next pointer within the node struct |
424 * @param loc_next the location of the @c next pointer within the node struct |
542 * @return the size of the list or zero if @p node is @c NULL |
425 * @return the size of the list or zero if @p node is @c NULL |
543 */ |
426 */ |
544 cx_attr_nodiscard |
427 cx_attr_nodiscard |
545 cx_attr_export |
428 CX_EXPORT size_t cx_linked_list_size(const void *node, ptrdiff_t loc_next); |
546 size_t cx_linked_list_size( |
|
547 const void *node, |
|
548 ptrdiff_t loc_next |
|
549 ); |
|
550 |
429 |
551 /** |
430 /** |
552 * Sorts a linked list based on a comparison function. |
431 * Sorts a linked list based on a comparison function. |
553 * |
432 * |
554 * This function can work with linked lists of the following structure: |
433 * This function can work with linked lists of the following structure: |
569 * @param loc_next the location of a @c next pointer within your node struct (required) |
448 * @param loc_next the location of a @c next pointer within your node struct (required) |
570 * @param loc_data the location of the @c data pointer within your node struct |
449 * @param loc_data the location of the @c data pointer within your node struct |
571 * @param cmp_func the compare function defining the sort order |
450 * @param cmp_func the compare function defining the sort order |
572 */ |
451 */ |
573 cx_attr_nonnull_arg(1, 6) |
452 cx_attr_nonnull_arg(1, 6) |
574 cx_attr_export |
453 CX_EXPORT void cx_linked_list_sort(void **begin, void **end, |
575 void cx_linked_list_sort( |
454 ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, cx_compare_func cmp_func); |
576 void **begin, |
|
577 void **end, |
|
578 ptrdiff_t loc_prev, |
|
579 ptrdiff_t loc_next, |
|
580 ptrdiff_t loc_data, |
|
581 cx_compare_func cmp_func |
|
582 ); |
|
583 |
455 |
584 |
456 |
585 /** |
457 /** |
586 * Compares two lists element wise. |
458 * Compares two lists element wise. |
587 * |
459 * |
594 * @param cmp_func the function to compare the elements |
466 * @param cmp_func the function to compare the elements |
595 * @return the first non-zero result of invoking @p cmp_func or: negative if the left list is smaller than the |
467 * @return the first non-zero result of invoking @p cmp_func or: negative if the left list is smaller than the |
596 * right list, positive if the left list is larger than the right list, zero if both lists are equal. |
468 * right list, positive if the left list is larger than the right list, zero if both lists are equal. |
597 */ |
469 */ |
598 cx_attr_nonnull_arg(5) |
470 cx_attr_nonnull_arg(5) |
599 cx_attr_export |
471 CX_EXPORT int cx_linked_list_compare(const void *begin_left, const void *begin_right, |
600 int cx_linked_list_compare( |
472 ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func cmp_func); |
601 const void *begin_left, |
|
602 const void *begin_right, |
|
603 ptrdiff_t loc_advance, |
|
604 ptrdiff_t loc_data, |
|
605 cx_compare_func cmp_func |
|
606 ); |
|
607 |
473 |
608 /** |
474 /** |
609 * Reverses the order of the nodes in a linked list. |
475 * Reverses the order of the nodes in a linked list. |
610 * |
476 * |
611 * @param begin a pointer to the beginning node pointer (required) |
477 * @param begin a pointer to the beginning node pointer (required) |
612 * @param end a pointer to the end node pointer (optional) |
478 * @param end a pointer to the end node pointer (optional) |
613 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
479 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
614 * @param loc_next the location of a @c next pointer within your node struct (required) |
480 * @param loc_next the location of a @c next pointer within your node struct (required) |
615 */ |
481 */ |
616 cx_attr_nonnull_arg(1) |
482 cx_attr_nonnull_arg(1) |
617 cx_attr_export |
483 CX_EXPORT void cx_linked_list_reverse(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next); |
618 void cx_linked_list_reverse( |
|
619 void **begin, |
|
620 void **end, |
|
621 ptrdiff_t loc_prev, |
|
622 ptrdiff_t loc_next |
|
623 ); |
|
624 |
484 |
625 #ifdef __cplusplus |
485 #ifdef __cplusplus |
626 } // extern "C" |
486 } // extern "C" |
627 #endif |
487 #endif |
628 |
488 |