ucx
UAP Common Extensions
Loading...
Searching...
No Matches
linked_list.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
36#ifndef UCX_LINKED_LIST_H
37#define UCX_LINKED_LIST_H
38
39#include "common.h"
40#include "list.h"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
66 const CxAllocator *allocator,
67 cx_compare_func comparator,
68 size_t elem_size
69);
70
85#define cxLinkedListCreateSimple(elem_size) \
86 cxLinkedListCreate(NULL, NULL, elem_size)
87
109 const void *start,
110 size_t start_index,
111 ptrdiff_t loc_advance,
112 size_t index
113);
114
127cx_attr_nonnull_arg(1, 4, 5)
130 const void *start,
131 ptrdiff_t loc_advance,
132 ptrdiff_t loc_data,
133 cx_compare_func cmp_func,
134 const void *elem,
135 size_t *found_index
136);
137
153 const void *node,
154 ptrdiff_t loc_prev
155);
156
172 const void *node,
173 ptrdiff_t loc_next
174);
175
189 const void *begin,
190 ptrdiff_t loc_next,
191 const void *node
192);
193
209 void **begin,
210 void **end,
211 ptrdiff_t loc_prev,
212 ptrdiff_t loc_next,
213 void *new_node
214);
215
231 void **begin,
232 void **end,
233 ptrdiff_t loc_prev,
234 ptrdiff_t loc_next,
235 void *new_node
236);
237
249 void *left,
250 void *right,
251 ptrdiff_t loc_prev,
252 ptrdiff_t loc_next
253);
254
268 void *left,
269 void *right,
270 ptrdiff_t loc_prev,
271 ptrdiff_t loc_next
272);
273
291 void **begin,
292 void **end,
293 ptrdiff_t loc_prev,
294 ptrdiff_t loc_next,
295 void *node,
296 void *new_node
297);
298
322 void **begin,
323 void **end,
324 ptrdiff_t loc_prev,
325 ptrdiff_t loc_next,
326 void *node,
327 void *insert_begin,
328 void *insert_end
329);
330
345cx_attr_nonnull_arg(1, 5, 6)
348 void **begin,
349 void **end,
350 ptrdiff_t loc_prev,
351 ptrdiff_t loc_next,
352 void *new_node,
353 cx_compare_func cmp_func
354);
355
375cx_attr_nonnull_arg(1, 5, 6)
378 void **begin,
379 void **end,
380 ptrdiff_t loc_prev,
381 ptrdiff_t loc_next,
382 void *insert_begin,
383 cx_compare_func cmp_func
384);
385
410 void **begin,
411 void **end,
412 ptrdiff_t loc_prev,
413 ptrdiff_t loc_next,
414 void *node,
415 size_t num
416);
417
438static inline void cx_linked_list_remove(
439 void **begin,
440 void **end,
441 ptrdiff_t loc_prev,
442 ptrdiff_t loc_next,
443 void *node
444) {
445 cx_linked_list_remove_chain(begin, end, loc_prev, loc_next, node, 1);
446}
447
458 const void *node,
459 ptrdiff_t loc_next
460);
461
487 void **begin,
488 void **end,
489 ptrdiff_t loc_prev,
490 ptrdiff_t loc_next,
491 ptrdiff_t loc_data,
492 cx_compare_func cmp_func
493);
494
495
512 const void *begin_left,
513 const void *begin_right,
514 ptrdiff_t loc_advance,
515 ptrdiff_t loc_data,
516 cx_compare_func cmp_func
517);
518
530 void **begin,
531 void **end,
532 ptrdiff_t loc_prev,
533 ptrdiff_t loc_next
534);
535
536#ifdef __cplusplus
537} // extern "C"
538#endif
539
540#endif // UCX_LINKED_LIST_H
Common definitions and feature checks.
#define cx_attr_export
Only used for building Windows DLLs.
Definition common.h:285
#define cx_attr_returns_nonnull
The returned value is guaranteed to be non-NULL.
Definition common.h:146
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:136
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:265
#define cx_attr_malloc
The attributed function always returns freshly allocated memory.
Definition common.h:151
#define cx_attr_nonnull_arg(...)
The specified pointer arguments must be non-NULL.
Definition common.h:141
#define cx_attr_dealloc(...)
Not supported in clang.
Definition common.h:167
int(* cx_compare_func)(const void *left, const void *right)
A comparator function comparing two arbitrary values.
Definition compare.h:60
size_t cx_linked_list_remove_chain(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, size_t num)
Removes a chain of nodes from the linked list.
void cx_linked_list_prepend(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node)
Prepends a new node to a linked list.
void * cx_linked_list_first(const void *node, ptrdiff_t loc_prev)
Finds the first node in a linked list.
void cx_linked_list_insert_sorted_chain(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func)
Inserts a chain of nodes into a sorted linked list.
void cx_linked_list_reverse(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Reverses the order of the nodes in a linked list.
void cx_linked_list_sort(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, cx_compare_func cmp_func)
Sorts a linked list based on a comparison function.
void * cx_linked_list_last(const void *node, ptrdiff_t loc_next)
Finds the last node in a linked list.
void cx_linked_list_unlink(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Unlinks two nodes.
CxList * cxLinkedListCreate(const CxAllocator *allocator, cx_compare_func comparator, size_t elem_size)
Allocates a linked list for storing elements with elem_size bytes each.
static void cx_linked_list_remove(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node)
Removes a node from the linked list.
Definition linked_list.h:438
int cx_linked_list_compare(const void *begin_left, const void *begin_right, ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func cmp_func)
Compares two lists element wise.
size_t cx_linked_list_size(const void *node, ptrdiff_t loc_next)
Determines the size of a linked list starting with node.
void cx_linked_list_insert_sorted(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func cmp_func)
Inserts a node into a sorted linked list.
void * cx_linked_list_prev(const void *begin, ptrdiff_t loc_next, const void *node)
Finds the predecessor of a node in case it is not linked.
void cx_linked_list_insert_chain(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *insert_begin, void *insert_end)
Inserts a chain of nodes after a given node of a linked list.
void * cx_linked_list_at(const void *start, size_t start_index, ptrdiff_t loc_advance, size_t index)
Finds the node at a certain index.
void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node)
Adds a new node to a linked list.
void * cx_linked_list_find(const void *start, ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func cmp_func, const void *elem, size_t *found_index)
Finds the node containing an element within a linked list.
void cx_linked_list_link(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Links two nodes.
void cx_linked_list_insert(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *new_node)
Inserts a new node after a given node of a linked list.
Interface for list implementations.
void cxListFree(CxList *list)
Deallocates the memory of the specified list structure.
Structure holding the data for an allocator.
Definition allocator.h:84
Structure for holding the base data of a list.
Definition list.h:54