63 * functions will not work) |
63 * functions will not work) |
64 * @param elem_size the size of each element in bytes |
64 * @param elem_size the size of each element in bytes |
65 * @return the created list |
65 * @return the created list |
66 */ |
66 */ |
67 CxList *cxLinkedListCreate( |
67 CxList *cxLinkedListCreate( |
68 CxAllocator const *allocator, |
68 const CxAllocator *allocator, |
69 cx_compare_func comparator, |
69 cx_compare_func comparator, |
70 size_t elem_size |
70 size_t elem_size |
71 ); |
71 ); |
72 |
72 |
73 /** |
73 /** |
103 * @param loc_advance the location of the pointer to advance |
103 * @param loc_advance the location of the pointer to advance |
104 * @param index the search index |
104 * @param index the search index |
105 * @return the node found at the specified index |
105 * @return the node found at the specified index |
106 */ |
106 */ |
107 void *cx_linked_list_at( |
107 void *cx_linked_list_at( |
108 void const *start, |
108 const void *start, |
109 size_t start_index, |
109 size_t start_index, |
110 ptrdiff_t loc_advance, |
110 ptrdiff_t loc_advance, |
111 size_t index |
111 size_t index |
112 ) __attribute__((__nonnull__)); |
112 ) __attribute__((__nonnull__)); |
113 |
113 |
120 * @param cmp_func a compare function to compare \p elem against the node data |
120 * @param cmp_func a compare function to compare \p elem against the node data |
121 * @param elem a pointer to the element to find |
121 * @param elem a pointer to the element to find |
122 * @return the index of the element or a negative value if it could not be found |
122 * @return the index of the element or a negative value if it could not be found |
123 */ |
123 */ |
124 ssize_t cx_linked_list_find( |
124 ssize_t cx_linked_list_find( |
125 void const *start, |
125 const void *start, |
126 ptrdiff_t loc_advance, |
126 ptrdiff_t loc_advance, |
127 ptrdiff_t loc_data, |
127 ptrdiff_t loc_data, |
128 cx_compare_func cmp_func, |
128 cx_compare_func cmp_func, |
129 void const *elem |
129 const void *elem |
130 ) __attribute__((__nonnull__)); |
130 ) __attribute__((__nonnull__)); |
131 |
131 |
132 /** |
132 /** |
133 * Finds the node containing an element within a linked list. |
133 * Finds the node containing an element within a linked list. |
134 * |
134 * |
141 * @param elem a pointer to the element to find |
141 * @param elem a pointer to the element to find |
142 * @return the index of the element or a negative value if it could not be found |
142 * @return the index of the element or a negative value if it could not be found |
143 */ |
143 */ |
144 ssize_t cx_linked_list_find_node( |
144 ssize_t cx_linked_list_find_node( |
145 void **result, |
145 void **result, |
146 void const *start, |
146 const void *start, |
147 ptrdiff_t loc_advance, |
147 ptrdiff_t loc_advance, |
148 ptrdiff_t loc_data, |
148 ptrdiff_t loc_data, |
149 cx_compare_func cmp_func, |
149 cx_compare_func cmp_func, |
150 void const *elem |
150 const void *elem |
151 ) __attribute__((__nonnull__)); |
151 ) __attribute__((__nonnull__)); |
152 |
152 |
153 /** |
153 /** |
154 * Finds the first node in a linked list. |
154 * Finds the first node in a linked list. |
155 * |
155 * |
160 * @param node a pointer to a node in the list |
160 * @param node a pointer to a node in the list |
161 * @param loc_prev the location of the \c prev pointer |
161 * @param loc_prev the location of the \c prev pointer |
162 * @return a pointer to the first node |
162 * @return a pointer to the first node |
163 */ |
163 */ |
164 void *cx_linked_list_first( |
164 void *cx_linked_list_first( |
165 void const *node, |
165 const void *node, |
166 ptrdiff_t loc_prev |
166 ptrdiff_t loc_prev |
167 ) __attribute__((__nonnull__)); |
167 ) __attribute__((__nonnull__)); |
168 |
168 |
169 /** |
169 /** |
170 * Finds the last node in a linked list. |
170 * Finds the last node in a linked list. |
176 * @param node a pointer to a node in the list |
176 * @param node a pointer to a node in the list |
177 * @param loc_next the location of the \c next pointer |
177 * @param loc_next the location of the \c next pointer |
178 * @return a pointer to the last node |
178 * @return a pointer to the last node |
179 */ |
179 */ |
180 void *cx_linked_list_last( |
180 void *cx_linked_list_last( |
181 void const *node, |
181 const void *node, |
182 ptrdiff_t loc_next |
182 ptrdiff_t loc_next |
183 ) __attribute__((__nonnull__)); |
183 ) __attribute__((__nonnull__)); |
184 |
184 |
185 /** |
185 /** |
186 * Finds the predecessor of a node in case it is not linked. |
186 * Finds the predecessor of a node in case it is not linked. |
191 * @param loc_next the location of the \c next pointer |
191 * @param loc_next the location of the \c next pointer |
192 * @param node the successor of the node to find |
192 * @param node the successor of the node to find |
193 * @return the node or \c NULL if \p node has no predecessor |
193 * @return the node or \c NULL if \p node has no predecessor |
194 */ |
194 */ |
195 void *cx_linked_list_prev( |
195 void *cx_linked_list_prev( |
196 void const *begin, |
196 const void *begin, |
197 ptrdiff_t loc_next, |
197 ptrdiff_t loc_next, |
198 void const *node |
198 const void *node |
199 ) __attribute__((__nonnull__)); |
199 ) __attribute__((__nonnull__)); |
200 |
200 |
201 /** |
201 /** |
202 * Adds a new node to a linked list. |
202 * Adds a new node to a linked list. |
203 * The node must not be part of any list already. |
203 * The node must not be part of any list already. |
407 * @param node the first node |
407 * @param node the first node |
408 * @param loc_next the location of the \c next pointer within the node struct |
408 * @param loc_next the location of the \c next pointer within the node struct |
409 * @return the size of the list or zero if \p node is \c NULL |
409 * @return the size of the list or zero if \p node is \c NULL |
410 */ |
410 */ |
411 size_t cx_linked_list_size( |
411 size_t cx_linked_list_size( |
412 void const *node, |
412 const void *node, |
413 ptrdiff_t loc_next |
413 ptrdiff_t loc_next |
414 ); |
414 ); |
415 |
415 |
416 /** |
416 /** |
417 * Sorts a linked list based on a comparison function. |
417 * Sorts a linked list based on a comparison function. |
457 * @param cmp_func the function to compare the elements |
457 * @param cmp_func the function to compare the elements |
458 * @return the first non-zero result of invoking \p cmp_func or: negative if the left list is smaller than the |
458 * @return the first non-zero result of invoking \p cmp_func or: negative if the left list is smaller than the |
459 * right list, positive if the left list is larger than the right list, zero if both lists are equal. |
459 * right list, positive if the left list is larger than the right list, zero if both lists are equal. |
460 */ |
460 */ |
461 int cx_linked_list_compare( |
461 int cx_linked_list_compare( |
462 void const *begin_left, |
462 const void *begin_left, |
463 void const *begin_right, |
463 const void *begin_right, |
464 ptrdiff_t loc_advance, |
464 ptrdiff_t loc_advance, |
465 ptrdiff_t loc_data, |
465 ptrdiff_t loc_data, |
466 cx_compare_func cmp_func |
466 cx_compare_func cmp_func |
467 ) __attribute__((__nonnull__(5))); |
467 ) __attribute__((__nonnull__(5))); |
468 |
468 |