src/cx/linked_list.h

changeset 1180
4c3a69b9723a
parent 1162
e3bb67b72d33
equal deleted inserted replaced
1179:ca4c6f590a08 1180:4c3a69b9723a
59 * @return the created list 59 * @return the created list
60 */ 60 */
61 cx_attr_nodiscard 61 cx_attr_nodiscard
62 cx_attr_malloc 62 cx_attr_malloc
63 cx_attr_dealloc(cxListFree, 1) 63 cx_attr_dealloc(cxListFree, 1)
64 cx_attr_export
64 CxList *cxLinkedListCreate( 65 CxList *cxLinkedListCreate(
65 const CxAllocator *allocator, 66 const CxAllocator *allocator,
66 cx_compare_func comparator, 67 cx_compare_func comparator,
67 size_t elem_size 68 size_t elem_size
68 ); 69 );
101 * @param index the search index 102 * @param index the search index
102 * @return the node found at the specified index 103 * @return the node found at the specified index
103 */ 104 */
104 cx_attr_nonnull 105 cx_attr_nonnull
105 cx_attr_nodiscard 106 cx_attr_nodiscard
107 cx_attr_export
106 void *cx_linked_list_at( 108 void *cx_linked_list_at(
107 const void *start, 109 const void *start,
108 size_t start_index, 110 size_t start_index,
109 ptrdiff_t loc_advance, 111 ptrdiff_t loc_advance,
110 size_t index 112 size_t index
121 * @param found_index an optional pointer where the index of the found node 123 * @param found_index an optional pointer where the index of the found node
122 * (given that @p start has index 0) is stored 124 * (given that @p start has index 0) is stored
123 * @return the index of the element, if found - unspecified if not found 125 * @return the index of the element, if found - unspecified if not found
124 */ 126 */
125 cx_attr_nonnull_arg(1, 4, 5) 127 cx_attr_nonnull_arg(1, 4, 5)
128 cx_attr_export
126 void *cx_linked_list_find( 129 void *cx_linked_list_find(
127 const void *start, 130 const void *start,
128 ptrdiff_t loc_advance, 131 ptrdiff_t loc_advance,
129 ptrdiff_t loc_data, 132 ptrdiff_t loc_data,
130 cx_compare_func cmp_func, 133 cx_compare_func cmp_func,
143 * @param loc_prev the location of the @c prev pointer 146 * @param loc_prev the location of the @c prev pointer
144 * @return a pointer to the first node 147 * @return a pointer to the first node
145 */ 148 */
146 cx_attr_nonnull 149 cx_attr_nonnull
147 cx_attr_returns_nonnull 150 cx_attr_returns_nonnull
151 cx_attr_export
148 void *cx_linked_list_first( 152 void *cx_linked_list_first(
149 const void *node, 153 const void *node,
150 ptrdiff_t loc_prev 154 ptrdiff_t loc_prev
151 ); 155 );
152 156
161 * @param loc_next the location of the @c next pointer 165 * @param loc_next the location of the @c next pointer
162 * @return a pointer to the last node 166 * @return a pointer to the last node
163 */ 167 */
164 cx_attr_nonnull 168 cx_attr_nonnull
165 cx_attr_returns_nonnull 169 cx_attr_returns_nonnull
170 cx_attr_export
166 void *cx_linked_list_last( 171 void *cx_linked_list_last(
167 const void *node, 172 const void *node,
168 ptrdiff_t loc_next 173 ptrdiff_t loc_next
169 ); 174 );
170 175
177 * @param loc_next the location of the @c next pointer 182 * @param loc_next the location of the @c next pointer
178 * @param node the successor of the node to find 183 * @param node the successor of the node to find
179 * @return the node or @c NULL if @p node has no predecessor 184 * @return the node or @c NULL if @p node has no predecessor
180 */ 185 */
181 cx_attr_nonnull 186 cx_attr_nonnull
187 cx_attr_export
182 void *cx_linked_list_prev( 188 void *cx_linked_list_prev(
183 const void *begin, 189 const void *begin,
184 ptrdiff_t loc_next, 190 ptrdiff_t loc_next,
185 const void *node 191 const void *node
186 ); 192 );
196 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) 202 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
197 * @param loc_next the location of a @c next pointer within your node struct (required) 203 * @param loc_next the location of a @c next pointer within your node struct (required)
198 * @param new_node a pointer to the node that shall be appended 204 * @param new_node a pointer to the node that shall be appended
199 */ 205 */
200 cx_attr_nonnull_arg(5) 206 cx_attr_nonnull_arg(5)
207 cx_attr_export
201 void cx_linked_list_add( 208 void cx_linked_list_add(
202 void **begin, 209 void **begin,
203 void **end, 210 void **end,
204 ptrdiff_t loc_prev, 211 ptrdiff_t loc_prev,
205 ptrdiff_t loc_next, 212 ptrdiff_t loc_next,
217 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) 224 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
218 * @param loc_next the location of a @c next pointer within your node struct (required) 225 * @param loc_next the location of a @c next pointer within your node struct (required)
219 * @param new_node a pointer to the node that shall be prepended 226 * @param new_node a pointer to the node that shall be prepended
220 */ 227 */
221 cx_attr_nonnull_arg(5) 228 cx_attr_nonnull_arg(5)
229 cx_attr_export
222 void cx_linked_list_prepend( 230 void cx_linked_list_prepend(
223 void **begin, 231 void **begin,
224 void **end, 232 void **end,
225 ptrdiff_t loc_prev, 233 ptrdiff_t loc_prev,
226 ptrdiff_t loc_next, 234 ptrdiff_t loc_next,
234 * @param right the new successor of @p left 242 * @param right the new successor of @p left
235 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) 243 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
236 * @param loc_next the location of a @c next pointer within your node struct (required) 244 * @param loc_next the location of a @c next pointer within your node struct (required)
237 */ 245 */
238 cx_attr_nonnull 246 cx_attr_nonnull
247 cx_attr_export
239 void cx_linked_list_link( 248 void cx_linked_list_link(
240 void *left, 249 void *left,
241 void *right, 250 void *right,
242 ptrdiff_t loc_prev, 251 ptrdiff_t loc_prev,
243 ptrdiff_t loc_next 252 ptrdiff_t loc_next
252 * @param right the successor of @p left 261 * @param right the successor of @p left
253 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) 262 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
254 * @param loc_next the location of a @c next pointer within your node struct (required) 263 * @param loc_next the location of a @c next pointer within your node struct (required)
255 */ 264 */
256 cx_attr_nonnull 265 cx_attr_nonnull
266 cx_attr_export
257 void cx_linked_list_unlink( 267 void cx_linked_list_unlink(
258 void *left, 268 void *left,
259 void *right, 269 void *right,
260 ptrdiff_t loc_prev, 270 ptrdiff_t loc_prev,
261 ptrdiff_t loc_next 271 ptrdiff_t loc_next
274 * @param loc_next the location of a @c next pointer within your node struct (required) 284 * @param loc_next the location of a @c next pointer within your node struct (required)
275 * @param node the node after which to insert (@c NULL if you want to prepend the node to the list) 285 * @param node the node after which to insert (@c NULL if you want to prepend the node to the list)
276 * @param new_node a pointer to the node that shall be inserted 286 * @param new_node a pointer to the node that shall be inserted
277 */ 287 */
278 cx_attr_nonnull_arg(6) 288 cx_attr_nonnull_arg(6)
289 cx_attr_export
279 void cx_linked_list_insert( 290 void cx_linked_list_insert(
280 void **begin, 291 void **begin,
281 void **end, 292 void **end,
282 ptrdiff_t loc_prev, 293 ptrdiff_t loc_prev,
283 ptrdiff_t loc_next, 294 ptrdiff_t loc_next,
304 * @param node the node after which to insert (@c NULL to prepend the chain to the list) 315 * @param node the node after which to insert (@c NULL to prepend the chain to the list)
305 * @param insert_begin a pointer to the first node of the chain that shall be inserted 316 * @param insert_begin a pointer to the first node of the chain that shall be inserted
306 * @param insert_end a pointer to the last node of the chain (or NULL if the last node shall be determined) 317 * @param insert_end a pointer to the last node of the chain (or NULL if the last node shall be determined)
307 */ 318 */
308 cx_attr_nonnull_arg(6) 319 cx_attr_nonnull_arg(6)
320 cx_attr_export
309 void cx_linked_list_insert_chain( 321 void cx_linked_list_insert_chain(
310 void **begin, 322 void **begin,
311 void **end, 323 void **end,
312 ptrdiff_t loc_prev, 324 ptrdiff_t loc_prev,
313 ptrdiff_t loc_next, 325 ptrdiff_t loc_next,
329 * @param loc_next the location of a @c next pointer within your node struct (required) 341 * @param loc_next the location of a @c next pointer within your node struct (required)
330 * @param new_node a pointer to the node that shall be inserted 342 * @param new_node a pointer to the node that shall be inserted
331 * @param cmp_func a compare function that will receive the node pointers 343 * @param cmp_func a compare function that will receive the node pointers
332 */ 344 */
333 cx_attr_nonnull_arg(1, 5, 6) 345 cx_attr_nonnull_arg(1, 5, 6)
346 cx_attr_export
334 void cx_linked_list_insert_sorted( 347 void cx_linked_list_insert_sorted(
335 void **begin, 348 void **begin,
336 void **end, 349 void **end,
337 ptrdiff_t loc_prev, 350 ptrdiff_t loc_prev,
338 ptrdiff_t loc_next, 351 ptrdiff_t loc_next,
358 * @param loc_next the location of a @c next pointer within your node struct (required) 371 * @param loc_next the location of a @c next pointer within your node struct (required)
359 * @param insert_begin a pointer to the first node of the chain that shall be inserted 372 * @param insert_begin a pointer to the first node of the chain that shall be inserted
360 * @param cmp_func a compare function that will receive the node pointers 373 * @param cmp_func a compare function that will receive the node pointers
361 */ 374 */
362 cx_attr_nonnull_arg(1, 5, 6) 375 cx_attr_nonnull_arg(1, 5, 6)
376 cx_attr_export
363 void cx_linked_list_insert_sorted_chain( 377 void cx_linked_list_insert_sorted_chain(
364 void **begin, 378 void **begin,
365 void **end, 379 void **end,
366 ptrdiff_t loc_prev, 380 ptrdiff_t loc_prev,
367 ptrdiff_t loc_next, 381 ptrdiff_t loc_next,
389 * @param node the start node of the chain 403 * @param node the start node of the chain
390 * @param num the number of nodes to remove 404 * @param num the number of nodes to remove
391 * @return the actual number of nodes that were removed (can be less when the list did not have enough nodes) 405 * @return the actual number of nodes that were removed (can be less when the list did not have enough nodes)
392 */ 406 */
393 cx_attr_nonnull_arg(5) 407 cx_attr_nonnull_arg(5)
408 cx_attr_export
394 size_t cx_linked_list_remove_chain( 409 size_t cx_linked_list_remove_chain(
395 void **begin, 410 void **begin,
396 void **end, 411 void **end,
397 ptrdiff_t loc_prev, 412 ptrdiff_t loc_prev,
398 ptrdiff_t loc_next, 413 ptrdiff_t loc_next,
435 * 450 *
436 * @param node the first node 451 * @param node the first node
437 * @param loc_next the location of the @c next pointer within the node struct 452 * @param loc_next the location of the @c next pointer within the node struct
438 * @return the size of the list or zero if @p node is @c NULL 453 * @return the size of the list or zero if @p node is @c NULL
439 */ 454 */
455 cx_attr_nodiscard
456 cx_attr_export
440 size_t cx_linked_list_size( 457 size_t cx_linked_list_size(
441 const void *node, 458 const void *node,
442 ptrdiff_t loc_next 459 ptrdiff_t loc_next
443 ); 460 );
444 461
463 * @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)
464 * @param loc_data the location of the @c data pointer within your node struct 481 * @param loc_data the location of the @c data pointer within your node struct
465 * @param cmp_func the compare function defining the sort order 482 * @param cmp_func the compare function defining the sort order
466 */ 483 */
467 cx_attr_nonnull_arg(1, 6) 484 cx_attr_nonnull_arg(1, 6)
485 cx_attr_export
468 void cx_linked_list_sort( 486 void cx_linked_list_sort(
469 void **begin, 487 void **begin,
470 void **end, 488 void **end,
471 ptrdiff_t loc_prev, 489 ptrdiff_t loc_prev,
472 ptrdiff_t loc_next, 490 ptrdiff_t loc_next,
487 * @param cmp_func the function to compare the elements 505 * @param cmp_func the function to compare the elements
488 * @return the first non-zero result of invoking @p cmp_func or: negative if the left list is smaller than the 506 * @return the first non-zero result of invoking @p cmp_func or: negative if the left list is smaller than the
489 * right list, positive if the left list is larger than the right list, zero if both lists are equal. 507 * right list, positive if the left list is larger than the right list, zero if both lists are equal.
490 */ 508 */
491 cx_attr_nonnull_arg(5) 509 cx_attr_nonnull_arg(5)
510 cx_attr_export
492 int cx_linked_list_compare( 511 int cx_linked_list_compare(
493 const void *begin_left, 512 const void *begin_left,
494 const void *begin_right, 513 const void *begin_right,
495 ptrdiff_t loc_advance, 514 ptrdiff_t loc_advance,
496 ptrdiff_t loc_data, 515 ptrdiff_t loc_data,
504 * @param end a pointer to the end node pointer (optional) 523 * @param end a pointer to the end node pointer (optional)
505 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) 524 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
506 * @param loc_next the location of a @c next pointer within your node struct (required) 525 * @param loc_next the location of a @c next pointer within your node struct (required)
507 */ 526 */
508 cx_attr_nonnull_arg(1) 527 cx_attr_nonnull_arg(1)
528 cx_attr_export
509 void cx_linked_list_reverse( 529 void cx_linked_list_reverse(
510 void **begin, 530 void **begin,
511 void **end, 531 void **end,
512 ptrdiff_t loc_prev, 532 ptrdiff_t loc_prev,
513 ptrdiff_t loc_next 533 ptrdiff_t loc_next

mercurial