108 * @return a pointer to the last node or \c NULL if \p begin is \c NULL |
108 * @return a pointer to the last node or \c NULL if \p begin is \c NULL |
109 */ |
109 */ |
110 void *cx_linked_list_last(void *begin, ptrdiff_t loc_next); |
110 void *cx_linked_list_last(void *begin, ptrdiff_t loc_next); |
111 |
111 |
112 /** |
112 /** |
|
113 * Finds the predecessor of a node in case it is not linked. |
|
114 * |
|
115 * \remark If \p node is not contained in the list starting with \p begin, the behavior is undefined. |
|
116 * |
|
117 * @param begin the node where to start the search |
|
118 * @param loc_next the location of the \c next pointer |
|
119 * @param node the successor of the node to find |
|
120 * @return the node or \c NULL if \p node has no predecessor |
|
121 */ |
|
122 void *cx_linked_list_prev(void *begin, ptrdiff_t loc_next, void *node); |
|
123 |
|
124 /** |
113 * Adds a new node to a linked list. |
125 * Adds a new node to a linked list. |
114 * |
126 * |
115 * \remark One of the pointers \p begin and \p end may be \c NULL, but not both. |
127 * \remark One of the pointers \p begin and \p end may be \c NULL, but not both. |
116 * |
128 * |
117 * @param begin a pointer to the begin node pointer (if your list has one) |
129 * @param begin a pointer to the begin node pointer (if your list has one) |
118 * @param end a pointer to the end node pointer (if your list has one) |
130 * @param end a pointer to the end node pointer (if your list has one) |
119 * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) |
131 * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) |
120 * @param loc_next the location of a \c next pointer within your node struct (negative if your struct does not have one) |
132 * @param loc_next the location of a \c next pointer within your node struct (required) |
121 * @param new_node a pointer to the node that shall be appended |
133 * @param new_node a pointer to the node that shall be appended |
122 */ |
134 */ |
123 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); |
135 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); |
|
136 |
|
137 /** |
|
138 * Removes a node from the linked list. |
|
139 * |
|
140 * If the node to remove is the begin (resp. end) node of the list and if \p begin (resp. \p end) |
|
141 * addresses are provided, the pointers are adjusted accordingly. |
|
142 * |
|
143 * The following combinations of arguments are valid (more arguments are optional): |
|
144 * \li \p loc_next and \p loc_prev |
|
145 * \li \p loc_next and \p begin |
|
146 * |
|
147 * This function returns an adjacent node according to the following rules: |
|
148 * \li if the node has only one adjacent node, that one is returned |
|
149 * \li otherwise, the former \c prev node is returned |
|
150 * |
|
151 * \remark The \c next and \c prev pointers of the removed node are cleared by this function. |
|
152 * |
|
153 * @param begin a pointer to the begin node pointer (optional) |
|
154 * @param end a pointer to the end node pointer (optional) |
|
155 * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) |
|
156 * @param loc_next the location of a \c next pointer within your node struct (required) |
|
157 * @param node the node to remove |
|
158 * @return an adjacent node or \c NULL, if this was the last node |
|
159 */ |
|
160 void *cx_linked_list_remove(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node); |
|
161 |
124 |
162 |
125 /** |
163 /** |
126 * Determines the size of a linked list starting with \p node. |
164 * Determines the size of a linked list starting with \p node. |
127 * @param node the first node |
165 * @param node the first node |
128 * @param loc_next the location of the \c next pointer within the node struct |
166 * @param loc_next the location of the \c next pointer within the node struct |
160 * @param cmp_func the compare function defining the sort order |
198 * @param cmp_func the compare function defining the sort order |
161 */ |
199 */ |
162 void cx_linked_list_sort(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, |
200 void cx_linked_list_sort(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, |
163 ptrdiff_t loc_data, int follow_ptr, CxListComparator cmp_func); |
201 ptrdiff_t loc_data, int follow_ptr, CxListComparator cmp_func); |
164 |
202 |
|
203 |
|
204 /** |
|
205 * Reverses the order of the nodes in a linked list. |
|
206 * |
|
207 * @param begin a pointer to the begin node pointer (required) |
|
208 * @param end a pointer to the end node pointer (optional) |
|
209 * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) |
|
210 * @param loc_next the location of a \c next pointer within your node struct (required) |
|
211 */ |
|
212 void cx_linked_list_reverse(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next); |
|
213 |
165 #ifdef __cplusplus |
214 #ifdef __cplusplus |
166 } /* extern "C" */ |
215 } /* extern "C" */ |
167 #endif |
216 #endif |
168 |
217 |
169 #endif /* UCX_LINKED_LIST_H */ |
218 #endif /* UCX_LINKED_LIST_H */ |