77 |
77 |
78 /** |
78 /** |
79 * Allocates a linked list for storing elements with @p elem_size bytes each. |
79 * Allocates a linked list for storing elements with @p elem_size bytes each. |
80 * |
80 * |
81 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
81 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
82 * copies of the added elements and the compare function will be automatically set |
82 * copies of the added elements, and the compare function will be automatically set |
83 * to cx_cmp_ptr(), if none is given. |
83 * to cx_cmp_ptr() if none is given. |
84 * |
84 * |
85 * @param allocator the allocator for allocating the list nodes |
85 * @param allocator the allocator for allocating the list nodes |
86 * (if @c NULL, the cxDefaultAllocator will be used) |
86 * (if @c NULL, the cxDefaultAllocator will be used) |
87 * @param comparator the comparator for the elements |
87 * @param comparator the comparator for the elements |
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 |
106 * The list will use cxDefaultAllocator and no comparator function. If you want |
106 * The list will use cxDefaultAllocator and no comparator function. If you want |
107 * to call functions that need a comparator, you must either set one immediately |
107 * to call functions that need a comparator, you must either set one immediately |
108 * after list creation or use cxLinkedListCreate(). |
108 * after list creation or use cxLinkedListCreate(). |
109 * |
109 * |
110 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
110 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
111 * copies of the added elements and the compare function will be automatically set |
111 * copies of the added elements, and the compare function will be automatically set |
112 * to cx_cmp_ptr(). |
112 * to cx_cmp_ptr(). |
113 * |
113 * |
114 * @param elem_size (@c size_t) the size of each element in bytes |
114 * @param elem_size (@c size_t) the size of each element in bytes |
115 * @return (@c CxList*) the created list |
115 * @return (@c CxList*) the created list |
116 */ |
116 */ |
119 |
119 |
120 /** |
120 /** |
121 * Finds the node at a certain index. |
121 * Finds the node at a certain index. |
122 * |
122 * |
123 * This function can be used to start at an arbitrary position within the list. |
123 * This function can be used to start at an arbitrary position within the list. |
124 * If the search index is large than the start index, @p loc_advance must denote |
124 * If the search index is larger than the start index, @p loc_advance must denote |
125 * the location of some sort of @c next pointer (i.e. a pointer to the next node). |
125 * the location of a @c next pointer (i.e., a pointer to the next node). |
126 * But it is also possible that the search index is smaller than the start index |
126 * But it is also possible that the search index is smaller than the start index |
127 * (e.g. in cases where traversing a list backwards is faster) in which case |
127 * (e.g., in cases where traversing a list backwards is faster). |
128 * @p loc_advance must denote the location of some sort of @c prev pointer |
128 * In that case @p loc_advance must denote the location of a @c prev pointer |
129 * (i.e. a pointer to the previous node). |
129 * (i.e., a pointer to the previous node). |
130 * |
130 * |
131 * @param start a pointer to the start node |
131 * @param start a pointer to the start node |
132 * @param start_index the start index |
132 * @param start_index the start index |
133 * @param loc_advance the location of the pointer to advance |
133 * @param loc_advance the location of the pointer to advance |
134 * @param index the search index |
134 * @param index the search index |
223 const void *node |
223 const void *node |
224 ); |
224 ); |
225 |
225 |
226 /** |
226 /** |
227 * Adds a new node to a linked list. |
227 * Adds a new node to a linked list. |
228 * The node must not be part of any list already. |
228 * The node must not be part of any list yet. |
229 * |
229 * |
230 * @remark One of the pointers @p begin or @p end may be @c NULL, but not both. |
230 * @remark One of the pointers @p begin or @p end may be @c NULL, but not both. |
231 * |
231 * |
232 * @param begin a pointer to the beginning node pointer (if your list has one) |
232 * @param begin a pointer to the beginning node pointer (if your list has one) |
233 * @param end a pointer to the end node pointer (if your list has one) |
233 * @param end a pointer to the end node pointer (if your list has one) |
245 void *new_node |
245 void *new_node |
246 ); |
246 ); |
247 |
247 |
248 /** |
248 /** |
249 * Prepends a new node to a linked list. |
249 * Prepends a new node to a linked list. |
250 * The node must not be part of any list already. |
250 * The node must not be part of any list yet. |
251 * |
251 * |
252 * @remark One of the pointers @p begin or @p end may be @c NULL, but not both. |
252 * @remark One of the pointers @p begin or @p end may be @c NULL, but not both. |
253 * |
253 * |
254 * @param begin a pointer to the beginning node pointer (if your list has one) |
254 * @param begin a pointer to the beginning node pointer (if your list has one) |
255 * @param end a pointer to the end node pointer (if your list has one) |
255 * @param end a pointer to the end node pointer (if your list has one) |
303 ptrdiff_t loc_next |
303 ptrdiff_t loc_next |
304 ); |
304 ); |
305 |
305 |
306 /** |
306 /** |
307 * Inserts a new node after a given node of a linked list. |
307 * Inserts a new node after a given node of a linked list. |
308 * The new node must not be part of any list already. |
308 * The new node must not be part of any list yet. |
309 * |
309 * |
310 * @note If you specify @c NULL as the @p node to insert after, this function needs either the @p begin or |
310 * @note If you specify @c NULL as the @p node to insert after, this function needs either the @p begin or |
311 * the @p end pointer to determine the start of the list. Then the new node will be prepended to the list. |
311 * the @p end pointer to determine the start of the list. Then the new node will be prepended to the list. |
312 * |
312 * |
313 * @param begin a pointer to the beginning node pointer (if your list has one) |
313 * @param begin a pointer to the beginning node pointer (if your list has one) |
328 void *new_node |
328 void *new_node |
329 ); |
329 ); |
330 |
330 |
331 /** |
331 /** |
332 * Inserts a chain of nodes after a given node of a linked list. |
332 * Inserts a chain of nodes after a given node of a linked list. |
333 * The chain must not be part of any list already. |
333 * The chain must not be part of any list yet. |
334 * |
334 * |
335 * If you do not explicitly specify the end of the chain, it will be determined by traversing |
335 * If you do not explicitly specify the end of the chain, it will be determined by traversing |
336 * the @c next pointer. |
336 * the @c next pointer. |
337 * |
337 * |
338 * @note If you specify @c NULL as the @p node to insert after, this function needs either the @p begin or |
338 * @note If you specify @c NULL as the @p node to insert after, this function needs either the @p begin or |
360 void *insert_end |
360 void *insert_end |
361 ); |
361 ); |
362 |
362 |
363 /** |
363 /** |
364 * Inserts a node into a sorted linked list. |
364 * Inserts a node into a sorted linked list. |
365 * The new node must not be part of any list already. |
365 * The new node must not be part of any list yet. |
366 * |
366 * |
367 * If the list starting with the node pointed to by @p begin is not sorted |
367 * If the list starting with the node pointed to by @p begin is not sorted |
368 * already, the behavior is undefined. |
368 * already, the behavior is undefined. |
369 * |
369 * |
370 * @param begin a pointer to the beginning node pointer (required) |
370 * @param begin a pointer to the beginning node pointer (required) |
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 |
396 * will be broken and inserted into the target list so that the resulting list |
396 * will be broken and inserted into the target list so that the resulting list |
397 * will be sorted according to @p cmp_func. That means, each node in the source |
397 * will be sorted according to @p cmp_func. That means each node in the source |
398 * chain may be re-linked with nodes from the target list. |
398 * chain may be re-linked with nodes from the target list. |
399 * |
399 * |
400 * @param begin a pointer to the beginning node pointer (required) |
400 * @param begin a pointer to the beginning node pointer (required) |
401 * @param end a pointer to the end node pointer (if your list has one) |
401 * @param end a pointer to the end node pointer (if your list has one) |
402 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
402 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) |
473 ); |
473 ); |
474 |
474 |
475 /** |
475 /** |
476 * Removes a chain of nodes from the linked list. |
476 * Removes a chain of nodes from the linked list. |
477 * |
477 * |
478 * If one of the nodes to remove is the beginning (resp. end) node of the list and if @p begin (resp. @p end) |
478 * If one of the nodes to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end) |
479 * addresses are provided, the pointers are adjusted accordingly. |
479 * addresses are provided, the pointers are adjusted accordingly. |
480 * |
480 * |
481 * The following combinations of arguments are valid (more arguments are optional): |
481 * The following combinations of arguments are valid (more arguments are optional): |
482 * @li @p loc_next and @p loc_prev (ancestor node is determined by using the prev pointer, overall O(1) performance) |
482 * @li @p loc_next and @p loc_prev (ancestor node is determined by using the prev pointer, overall O(1) performance) |
483 * @li @p loc_next and @p begin (ancestor node is determined by list traversal, overall O(n) performance) |
483 * @li @p loc_next and @p begin (ancestor node is determined by list traversal, overall O(n) performance) |
505 ); |
505 ); |
506 |
506 |
507 /** |
507 /** |
508 * Removes a node from the linked list. |
508 * Removes a node from the linked list. |
509 * |
509 * |
510 * If the node to remove is the beginning (resp. end) node of the list and if @p begin (resp. @p end) |
510 * If the node to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end) |
511 * addresses are provided, the pointers are adjusted accordingly. |
511 * addresses are provided, the pointers are adjusted accordingly. |
512 * |
512 * |
513 * The following combinations of arguments are valid (more arguments are optional): |
513 * The following combinations of arguments are valid (more arguments are optional): |
514 * @li @p loc_next and @p loc_prev (ancestor node is determined by using the prev pointer, overall O(1) performance) |
514 * @li @p loc_next and @p loc_prev (ancestor node is determined by using the prev pointer, overall O(1) performance) |
515 * @li @p loc_next and @p begin (ancestor node is determined by list traversal, overall O(n) performance) |
515 * @li @p loc_next and @p begin (ancestor node is determined by list traversal, overall O(n) performance) |
583 |
583 |
584 |
584 |
585 /** |
585 /** |
586 * Compares two lists element wise. |
586 * Compares two lists element wise. |
587 * |
587 * |
588 * @attention Both list must have the same structure. |
588 * @attention Both lists must have the same structure. |
589 * |
589 * |
590 * @param begin_left the beginning of the left list (@c NULL denotes an empty list) |
590 * @param begin_left the beginning of the left list (@c NULL denotes an empty list) |
591 * @param begin_right the beginning of the right list (@c NULL denotes an empty list) |
591 * @param begin_right the beginning of the right list (@c NULL denotes an empty list) |
592 * @param loc_advance the location of the pointer to advance |
592 * @param loc_advance the location of the pointer to advance |
593 * @param loc_data the location of the @c data pointer within your node struct |
593 * @param loc_data the location of the @c data pointer within your node struct |