src/cx/linked_list.h

Sun, 28 Dec 2025 17:31:20 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 28 Dec 2025 17:31:20 +0100
changeset 1675
36c0fb2b60b2
parent 1624
aab23807d562
permissions
-rw-r--r--

overhaul all attributes

398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
28 /**
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
29 * @file linked_list.h
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
30 * @brief Linked list implementation.
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
31 * @author Mike Becker
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
32 * @author Olaf Wintermann
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
33 * @copyright 2-Clause BSD License
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
34 */
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 #ifndef UCX_LINKED_LIST_H
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 #define UCX_LINKED_LIST_H
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38
484
9e6900b1cf9d add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents: 481
diff changeset
39 #include "common.h"
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 #include "list.h"
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
42 /**
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
43 * Metadata for a linked list.
1367
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
44 */
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
45 typedef struct cx_linked_list_s {
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
46 /** Base members. */
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
47 struct cx_list_s base;
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
48 /**
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
49 * Location of the prev pointer (mandatory).
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
50 */
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
51 off_t loc_prev;
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
52 /**
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
53 * Location of the next pointer (mandatory).
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
54 */
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
55 off_t loc_next;
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
56 /**
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
57 * Location of the payload (mandatory).
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
58 */
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
59 off_t loc_data;
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
60 /**
1532
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
61 * Location of extra data (optional).
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
62 * Negative when no extra data is requested.
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
63 * @see cx_linked_list_extra_data()
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
64 */
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
65 off_t loc_extra;
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
66 /**
1367
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
67 * Additional bytes to allocate @em behind the payload (e.g. for metadata).
1532
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
68 * @see cx_linked_list_extra_data()
1367
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
69 */
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
70 size_t extra_data_len;
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
71 /**
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
72 * Pointer to the first node.
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
73 */
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
74 void *begin;
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
75 /**
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
76 * Pointer to the last node.
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
77 */
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
78 void *end;
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
79 } cx_linked_list;
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
80
6b3d52dd176e change linked_list.c to allow custom data in nodes + implement cx_kv_list_set_key()
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
81 /**
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
82 * Allocates a linked list for storing elements with @p elem_size bytes each.
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
83 *
1111
78eeeb950883 remove API for changing the store_pointer property after list creation
Mike Becker <universe@uap-core.de>
parents: 1100
diff changeset
84 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
85 * copies of the added elements, and the compare function will be automatically set
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1532
diff changeset
86 * to cx_cmp_ptr().
669
dce9b8450656 add docs for CX_STORE_POINTERS and remove cxHashMapCreateForPointers()
Mike Becker <universe@uap-core.de>
parents: 662
diff changeset
87 *
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
88 * @param allocator the allocator for allocating the list nodes
1318
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1241
diff changeset
89 * (if @c NULL, the cxDefaultAllocator will be used)
855
35bcb3216c0d fix inconsistent use of item_size and elem_size
Mike Becker <universe@uap-core.de>
parents: 807
diff changeset
90 * @param elem_size the size of each element in bytes
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
91 * @return the created list
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
92 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
93 CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxListFree, 1)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
94 CxList *cxLinkedListCreate(const CxAllocator *allocator,
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1532
diff changeset
95 size_t elem_size);
662
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 653
diff changeset
96
d0d95740071b add simple functions for creating lists
Mike Becker <universe@uap-core.de>
parents: 653
diff changeset
97 /**
1532
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
98 * Instructs the linked list to reserve extra data in each node.
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
99 *
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
100 * The extra data will be aligned and placed behind the element data.
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
101 * The exact location in the node is stored in the @c loc_extra field
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
102 * of the linked list.
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
103 *
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
104 * You should usually not use this function except when you are creating an
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
105 * own linked-list implementation that is based on the UCX linked list and
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
106 * needs to store extra data in each node.
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
107 *
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
108 * @param list the list (must be a linked list)
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
109 * @param len the length of the extra data
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
110 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
111 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
112 void cx_linked_list_extra_data(cx_linked_list *list, size_t len);
1532
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
113
313fd460d264 fix missing memory alignment for linked list node extra data
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
114 /**
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
115 * Finds the node at a certain index.
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
116 *
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
117 * This function can be used to start at an arbitrary position within the list.
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
118 * If the search index is larger than the start index, @p loc_advance must denote
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
119 * the location of a @c next pointer (i.e., a pointer to the next node).
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
120 * But it is also possible that the search index is smaller than the start index
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
121 * (e.g., in cases where traversing a list backwards is faster).
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
122 * In that case @p loc_advance must denote the location of a @c prev pointer
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
123 * (i.e., a pointer to the previous node).
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
124 *
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
125 * @param start a pointer to the start node
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
126 * @param start_index the start index
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
127 * @param loc_advance the location of the pointer to advance
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
128 * @param index the search index
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
129 * @return the node found at the specified index
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
130 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
131 CX_EXTERN CX_NONNULL CX_NODISCARD
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
132 void *cx_linked_list_at(const void *start,size_t start_index,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
133 ptrdiff_t loc_advance, size_t index);
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 416
diff changeset
134
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
135 /**
1162
e3bb67b72d33 remove dependency to ssize_t - fixes #552
Mike Becker <universe@uap-core.de>
parents: 1113
diff changeset
136 * Finds the node containing an element within a linked list.
480
e3be53a3354f add cx_linked_list_find()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
137 *
e3be53a3354f add cx_linked_list_find()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
138 * @param start a pointer to the start node
e3be53a3354f add cx_linked_list_find()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
139 * @param loc_advance the location of the pointer to advance
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
140 * @param loc_data the location of the @c data pointer within your node struct
480
e3be53a3354f add cx_linked_list_find()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
141 * @param elem a pointer to the element to find
1162
e3bb67b72d33 remove dependency to ssize_t - fixes #552
Mike Becker <universe@uap-core.de>
parents: 1113
diff changeset
142 * @param found_index an optional pointer where the index of the found node
e3bb67b72d33 remove dependency to ssize_t - fixes #552
Mike Becker <universe@uap-core.de>
parents: 1113
diff changeset
143 * (given that @p start has index 0) is stored
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
144 * @param cmp_func a compare function to compare @p elem against the node data
1374
4dceda670b05 fix documentation of return value of cx_linked_list_find()
Mike Becker <universe@uap-core.de>
parents: 1367
diff changeset
145 * @return a pointer to the found node or @c NULL if no matching node was found
480
e3be53a3354f add cx_linked_list_find()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
146 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
147 CX_EXTERN CX_NONNULL_ARG(1, 4, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
148 void *cx_linked_list_find(const void *start, ptrdiff_t loc_advance,
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
149 ptrdiff_t loc_data, const void *elem, size_t *found_index,
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
150 cx_compare_func cmp_func);
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
151
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
152 /**
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
153 * Finds the node containing an element within a linked list.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
154 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
155 * @param start a pointer to the start node
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
156 * @param loc_advance the location of the pointer to advance
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
157 * @param loc_data the location of the @c data pointer within your node struct
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
158 * @param elem a pointer to the element to find
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
159 * @param found_index an optional pointer where the index of the found node
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
160 * (given that @p start has index 0) is stored
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
161 * @param cmp_func a compare function to compare @p elem against the node data
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
162 * @param context additional context for the compare function
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
163 * @return a pointer to the found node or @c NULL if no matching node was found
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
164 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
165 CX_EXTERN CX_NONNULL_ARG(1, 4, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
166 void *cx_linked_list_find_c(const void *start, ptrdiff_t loc_advance,
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
167 ptrdiff_t loc_data, const void *elem, size_t *found_index,
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
168 cx_compare_func2 cmp_func, void *context);
764
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
169
ccbdbd088455 add cxListFindRemove and cx_linked_list_find_node
Mike Becker <universe@uap-core.de>
parents: 763
diff changeset
170 /**
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
171 * Finds the first node in a linked list.
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
172 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
173 * The function starts with the pointer denoted by @p node and traverses the list
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
174 * along a prev pointer whose location within the node struct is
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
175 * denoted by @p loc_prev.
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
176 *
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
177 * @param node a pointer to a node in the list
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
178 * @param loc_prev the location of the @c prev pointer
485
6a86ad3d8c03 use same doxygen style in all files
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
179 * @return a pointer to the first node
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
180 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
181 CX_EXTERN CX_NONNULL CX_RETURNS_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
182 void *cx_linked_list_first(const void *node, ptrdiff_t loc_prev);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
183
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
184 /**
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
185 * Finds the last node in a linked list.
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
186 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
187 * The function starts with the pointer denoted by @p node and traverses the list
456
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
188 * along a next pointer whose location within the node struct is
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
189 * denoted by @p loc_next.
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
190 *
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
191 * @param node a pointer to a node in the list
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
192 * @param loc_next the location of the @c next pointer
478
599770bb6314 add more nonnull attributes
Mike Becker <universe@uap-core.de>
parents: 477
diff changeset
193 * @return a pointer to the last node
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
194 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
195 CX_EXTERN CX_NONNULL CX_RETURNS_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
196 void *cx_linked_list_last(const void *node, ptrdiff_t loc_next);
398
8d506ed6c1c0 adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
198 /**
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
199 * Finds the predecessor of a node in case it is not linked.
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
200 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
201 * @remark If @p node is not contained in the list starting with @p begin, the behavior is undefined.
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
202 *
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
203 * @param begin the node where to start the search
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
204 * @param loc_next the location of the @c next pointer
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
205 * @param node the successor of the node to find
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
206 * @return the node or @c NULL if @p node has no predecessor
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
207 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
208 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
209 void *cx_linked_list_prev(const void *begin, ptrdiff_t loc_next, const void *node);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
210
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
211 /**
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
212 * Adds a new node to a linked list.
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
213 * The node must not be part of any list yet.
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
214 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
215 * @remark One of the pointers @p begin or @p end may be @c NULL, but not both.
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
216 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
217 * @param begin a pointer to the beginning node pointer (if your list has one)
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
218 * @param end a pointer to the end node pointer (if your list has one)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
219 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
220 * @param loc_next the location of a @c next pointer within your node struct (required)
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
221 * @param new_node a pointer to the node that shall be appended
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 438
diff changeset
222 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
223 CX_EXTERN CX_NONNULL_ARG(5)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
224 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node);
406
9cbea761fbf7 adds cxLinkedListWrap and cxLinkedListRecalculateSize
Mike Becker <universe@uap-core.de>
parents: 402
diff changeset
225
469
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
226 /**
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
227 * Prepends a new node to a linked list.
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
228 * The node must not be part of any list yet.
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
229 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
230 * @remark One of the pointers @p begin or @p end may be @c NULL, but not both.
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
231 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
232 * @param begin a pointer to the beginning node pointer (if your list has one)
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
233 * @param end a pointer to the end node pointer (if your list has one)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
234 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
235 * @param loc_next the location of a @c next pointer within your node struct (required)
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
236 * @param new_node a pointer to the node that shall be prepended
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
237 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
238 CX_EXTERN CX_NONNULL_ARG(5)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
239 void cx_linked_list_prepend(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node);
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
240
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
241 /**
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
242 * Links two nodes.
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
243 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
244 * @param left the new predecessor of @p right
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
245 * @param right the new successor of @p left
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
246 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
247 * @param loc_next the location of a @c next pointer within your node struct (required)
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
248 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
249 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
250 void cx_linked_list_link(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next);
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
251
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
252 /**
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
253 * Unlinks two nodes.
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
254 *
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
255 * If right is not the successor of left, the behavior is undefined.
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
256 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
257 * @param left the predecessor of @p right
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
258 * @param right the successor of @p left
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
259 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
260 * @param loc_next the location of a @c next pointer within your node struct (required)
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
261 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
262 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
263 void cx_linked_list_unlink(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next);
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
264
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
265 /**
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
266 * Inserts a new node after a given node of a linked list.
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
267 * The new node must not be part of any list yet.
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
268 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
269 * @note If you specify @c NULL as the @p node to insert after, this function needs either the @p begin or
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
270 * the @p end pointer to determine the start of the list. Then the new node will be prepended to the list.
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
271 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
272 * @param begin a pointer to the beginning node pointer (if your list has one)
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
273 * @param end a pointer to the end node pointer (if your list has one)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
274 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
275 * @param loc_next the location of a @c next pointer within your node struct (required)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
276 * @param node the node after which to insert (@c NULL if you want to prepend the node to the list)
878
1c1ee61c01f9 fix typo in documentation
Mike Becker <universe@uap-core.de>
parents: 855
diff changeset
277 * @param new_node a pointer to the node that shall be inserted
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
278 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
279 CX_EXTERN CX_NONNULL_ARG(6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
280 void cx_linked_list_insert(void **begin, void **end,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
281 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *new_node);
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
282
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
283 /**
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
284 * Inserts a chain of nodes after a given node of a linked list.
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
285 * The chain must not be part of any list yet.
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
286 *
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
287 * If you do not explicitly specify the end of the chain, it will be determined by traversing
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
288 * the @c next pointer.
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
289 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
290 * @note If you specify @c NULL as the @p node to insert after, this function needs either the @p begin or
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
291 * the @p end pointer to determine the start of the list. If only the @p end pointer is specified, you also need
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
292 * to provide a valid @p loc_prev location.
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
293 * Then the chain will be prepended to the list.
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
294 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
295 * @param begin a pointer to the beginning node pointer (if your list has one)
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
296 * @param end a pointer to the end node pointer (if your list has one)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
297 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
298 * @param loc_next the location of a @c next pointer within your node struct (required)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
299 * @param node the node after which to insert (@c NULL to prepend the chain to the list)
481
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
300 * @param insert_begin a pointer to the first node of the chain that shall be inserted
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
301 * @param insert_end a pointer to the last node of the chain (or NULL if the last node shall be determined)
eef025d82a34 add several new linked list functions
Mike Becker <universe@uap-core.de>
parents: 480
diff changeset
302 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
303 CX_EXTERN CX_NONNULL_ARG(6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
304 void cx_linked_list_insert_chain(void **begin, void **end,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
305 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *insert_begin, void *insert_end);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
306
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 473
diff changeset
307 /**
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
308 * Inserts a node into a sorted linked list.
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
309 * The new node must not be part of any list yet.
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
310 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
311 * If the list starting with the node pointed to by @p begin is not sorted
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
312 * already, the behavior is undefined.
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
313 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
314 * @param begin a pointer to the beginning node pointer (required)
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
315 * @param end a pointer to the end node pointer (if your list has one)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
316 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
317 * @param loc_next the location of a @c next pointer within your node struct (required)
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
318 * @param new_node a pointer to the node that shall be inserted
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
319 * @param cmp_func a compare function that will receive the node pointers
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
320 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
321 CX_EXTERN CX_NONNULL_ARG(1, 5, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
322 void cx_linked_list_insert_sorted(void **begin, void **end,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
323 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func cmp_func);
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
324
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
325 /**
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
326 * Inserts a chain of nodes into a sorted linked list.
1419
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
327 * The chain must not be part of any list yet.
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
328 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
329 * If either the list starting with the node pointed to by @p begin or the list
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
330 * starting with @p insert_begin is not sorted, the behavior is undefined.
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
331 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
332 * @attention In contrast to cx_linked_list_insert_chain(), the source chain
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
333 * will be broken and inserted into the target list so that the resulting list
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
334 * will be sorted according to @p cmp_func. That means each node in the source
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
335 * chain may be re-linked with nodes from the target list.
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
336 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
337 * @param begin a pointer to the beginning node pointer (required)
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
338 * @param end a pointer to the end node pointer (if your list has one)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
339 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
340 * @param loc_next the location of a @c next pointer within your node struct (required)
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
341 * @param insert_begin a pointer to the first node of the chain that shall be inserted
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
342 * @param cmp_func a compare function that will receive the node pointers
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
343 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
344 CX_EXTERN CX_NONNULL_ARG(1, 5, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
345 void cx_linked_list_insert_sorted_chain(void **begin, void **end,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
346 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func);
879
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
347
9c24a4eb5ac9 implement optimized sorted insert for linked lists - resolves #415
Mike Becker <universe@uap-core.de>
parents: 878
diff changeset
348 /**
1419
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
349 * Inserts a node into a sorted linked list if no other node with the same value already exists.
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
350 * The new node must not be part of any list yet.
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
351 *
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
352 * If the list starting with the node pointed to by @p begin is not sorted
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
353 * already, the behavior is undefined.
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
354 *
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
355 * @param begin a pointer to the beginning node pointer (required)
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
356 * @param end a pointer to the end node pointer (if your list has one)
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
357 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
358 * @param loc_next the location of a @c next pointer within your node struct (required)
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
359 * @param new_node a pointer to the node that shall be inserted
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
360 * @param cmp_func a compare function that will receive the node pointers
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
361 * @retval zero when the node was inserted
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
362 * @retval non-zero when a node with the same value already exists
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
363 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
364 CX_EXTERN CX_NONNULL_ARG(1, 5, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
365 int cx_linked_list_insert_unique(void **begin, void **end,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
366 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func cmp_func);
1419
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
367
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
368 /**
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
369 * Inserts a chain of nodes into a sorted linked list, avoiding duplicates.
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
370 * The chain must not be part of any list yet.
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
371 *
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
372 * If either the list starting with the node pointed to by @p begin or the list
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
373 * starting with @p insert_begin is not sorted, the behavior is undefined.
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
374 *
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
375 * @attention In contrast to cx_linked_list_insert_sorted(), not all nodes of the
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
376 * chain might be added. This function returns a new chain consisting of all the duplicates.
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
377 *
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
378 * @param begin a pointer to the beginning node pointer (required)
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
379 * @param end a pointer to the end node pointer (if your list has one)
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
380 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
381 * @param loc_next the location of a @c next pointer within your node struct (required)
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
382 * @param insert_begin a pointer to the first node of the chain that shall be inserted
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
383 * @param cmp_func a compare function that will receive the node pointers
1423
9a72258446cd fixes various bugs related to skipping duplicates in insert_unique - relates to #557
Mike Becker <universe@uap-core.de>
parents: 1419
diff changeset
384 * @return a pointer to a new chain with all duplicates that were not inserted (or @c NULL when there were no duplicates)
1419
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
385 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
386 CX_EXTERN CX_NONNULL_ARG(1, 5, 6) CX_NODISCARD
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
387 void *cx_linked_list_insert_unique_chain(void **begin, void **end,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
388 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func);
1419
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
389
e46406fd1b3c add functions to insert elements into lists/arrays without duplicates - resolves #557
Mike Becker <universe@uap-core.de>
parents: 1374
diff changeset
390 /**
1624
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
391 * Inserts a node into a sorted linked list.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
392 * The new node must not be part of any list yet.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
393 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
394 * If the list starting with the node pointed to by @p begin is not sorted
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
395 * already, the behavior is undefined.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
396 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
397 * @param begin a pointer to the beginning node pointer (required)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
398 * @param end a pointer to the end node pointer (if your list has one)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
399 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
400 * @param loc_next the location of a @c next pointer within your node struct (required)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
401 * @param new_node a pointer to the node that shall be inserted
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
402 * @param cmp_func a compare function that will receive the node pointers
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
403 * @param context context for the compare function
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
404 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
405 CX_EXTERN CX_NONNULL_ARG(1, 5, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
406 void cx_linked_list_insert_sorted_c(void **begin, void **end,
1624
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
407 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func2 cmp_func, void *context);
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
408
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
409 /**
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
410 * Inserts a chain of nodes into a sorted linked list.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
411 * The chain must not be part of any list yet.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
412 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
413 * If either the list starting with the node pointed to by @p begin or the list
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
414 * starting with @p insert_begin is not sorted, the behavior is undefined.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
415 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
416 * @attention In contrast to cx_linked_list_insert_chain(), the source chain
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
417 * will be broken and inserted into the target list so that the resulting list
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
418 * will be sorted according to @p cmp_func. That means each node in the source
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
419 * chain may be re-linked with nodes from the target list.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
420 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
421 * @param begin a pointer to the beginning node pointer (required)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
422 * @param end a pointer to the end node pointer (if your list has one)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
423 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
424 * @param loc_next the location of a @c next pointer within your node struct (required)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
425 * @param insert_begin a pointer to the first node of the chain that shall be inserted
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
426 * @param cmp_func a compare function that will receive the node pointers
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
427 * @param context context for the compare function
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
428 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
429 CX_EXTERN CX_NONNULL_ARG(1, 5, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
430 void cx_linked_list_insert_sorted_chain_c(void **begin, void **end,
1624
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
431 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func2 cmp_func, void *context);
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
432
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
433 /**
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
434 * Inserts a node into a sorted linked list if no other node with the same value already exists.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
435 * The new node must not be part of any list yet.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
436 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
437 * If the list starting with the node pointed to by @p begin is not sorted
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
438 * already, the behavior is undefined.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
439 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
440 * @param begin a pointer to the beginning node pointer (required)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
441 * @param end a pointer to the end node pointer (if your list has one)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
442 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
443 * @param loc_next the location of a @c next pointer within your node struct (required)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
444 * @param new_node a pointer to the node that shall be inserted
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
445 * @param cmp_func a compare function that will receive the node pointers
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
446 * @retval zero when the node was inserted
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
447 * @retval non-zero when a node with the same value already exists
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
448 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
449 CX_EXTERN CX_NONNULL_ARG(1, 5, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
450 int cx_linked_list_insert_unique_c(void **begin, void **end,
1624
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
451 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func2 cmp_func, void *context);
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
452
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
453 /**
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
454 * Inserts a chain of nodes into a sorted linked list, avoiding duplicates.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
455 * The chain must not be part of any list yet.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
456 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
457 * If either the list starting with the node pointed to by @p begin or the list
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
458 * starting with @p insert_begin is not sorted, the behavior is undefined.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
459 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
460 * @attention In contrast to cx_linked_list_insert_sorted(), not all nodes of the
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
461 * chain might be added. This function returns a new chain consisting of all the duplicates.
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
462 *
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
463 * @param begin a pointer to the beginning node pointer (required)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
464 * @param end a pointer to the end node pointer (if your list has one)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
465 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
466 * @param loc_next the location of a @c next pointer within your node struct (required)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
467 * @param insert_begin a pointer to the first node of the chain that shall be inserted
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
468 * @param cmp_func a compare function that will receive the node pointers
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
469 * @param context context for the compare function
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
470 * @return a pointer to a new chain with all duplicates that were not inserted (or @c NULL when there were no duplicates)
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
471 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
472 CX_EXTERN CX_NONNULL_ARG(1, 5, 6) CX_NODISCARD
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
473 void *cx_linked_list_insert_unique_chain_c(void **begin, void **end,
1624
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
474 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func2 cmp_func, void *context);
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
475
aab23807d562 add missing _c variants for some linked-list functions - relates to #622
Mike Becker <universe@uap-core.de>
parents: 1618
diff changeset
476 /**
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
477 * Removes a chain of nodes from the linked list.
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
478 *
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
479 * If one of the nodes to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end)
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
480 * addresses are provided, the pointers are adjusted accordingly.
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
481 *
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
482 * The following combinations of arguments are valid (more arguments are optional):
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
483 * @li @p loc_next and @p loc_prev (ancestor node is determined by using the prev pointer, overall O(1) performance)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
484 * @li @p loc_next and @p begin (ancestor node is determined by list traversal, overall O(n) performance)
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
485 *
1241
ebcc08023c33 complete linked_list.h docu
Mike Becker <universe@uap-core.de>
parents: 1239
diff changeset
486 * @remark The @c next and @c prev pointers of the removed chain are not cleared by this function and may still be used
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
487 * to traverse to a former adjacent node in the list, or within the chain.
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
488 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
489 * @param begin a pointer to the beginning node pointer (optional)
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
490 * @param end a pointer to the end node pointer (optional)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
491 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
492 * @param loc_next the location of a @c next pointer within your node struct (required)
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
493 * @param node the start node of the chain
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
494 * @param num the number of nodes to remove
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
495 * @return the actual number of nodes that were removed (can be less when the list did not have enough nodes)
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
496 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
497 CX_EXTERN CX_NONNULL_ARG(5)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
498 size_t cx_linked_list_remove_chain(void **begin, void **end,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
499 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, size_t num);
919
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
500
75da57d4634e add possibility to remove arrays of data and retrieve removed data
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
501 /**
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
502 * Removes a node from the linked list.
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
503 *
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
504 * If the node to remove is the beginning (resp. end) node of the list, and if @p begin (resp. @p end)
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
505 * addresses are provided, the pointers are adjusted accordingly.
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
506 *
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
507 * The following combinations of arguments are valid (more arguments are optional):
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
508 * @li @p loc_next and @p loc_prev (ancestor node is determined by using the prev pointer, overall O(1) performance)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
509 * @li @p loc_next and @p begin (ancestor node is determined by list traversal, overall O(n) performance)
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
510 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
511 * @remark The @c next and @c prev pointers of the removed node are not cleared by this function and may still be used
476
60ff4561dc04 change contract of cx_linked_list_remove()
Mike Becker <universe@uap-core.de>
parents: 475
diff changeset
512 * to traverse to a former adjacent node in the list.
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
513 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
514 * @param begin a pointer to the beginning node pointer (optional)
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
515 * @param end a pointer to the end node pointer (optional)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
516 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
517 * @param loc_next the location of a @c next pointer within your node struct (required)
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
518 * @param node the node to remove
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
519 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
520 CX_EXTERN CX_NONNULL_ARG(5)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
521 void cx_linked_list_remove(void **begin, void **end,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
522 ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
523
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
524 /**
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
525 * Determines the size of a linked list starting with @p node.
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
526 *
469
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
527 * @param node the first node
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
528 * @param loc_next the location of the @c next pointer within the node struct
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
529 * @return the size of the list or zero if @p node is @c NULL
469
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
530 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
531 CX_EXTERN CX_NODISCARD
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
532 size_t cx_linked_list_size(const void *node, ptrdiff_t loc_next);
469
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
533
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
534 /**
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
535 * Sorts a linked list based on a comparison function.
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
536 *
476
60ff4561dc04 change contract of cx_linked_list_remove()
Mike Becker <universe@uap-core.de>
parents: 475
diff changeset
537 * @note This is a recursive function with at most logarithmic recursion depth.
60ff4561dc04 change contract of cx_linked_list_remove()
Mike Becker <universe@uap-core.de>
parents: 475
diff changeset
538 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
539 * @param begin a pointer to the beginning node pointer (required)
469
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
540 * @param end a pointer to the end node pointer (optional)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
541 * @param loc_prev the location of a @c prev pointer within your node struct (negative if not present)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
542 * @param loc_next the location of a @c next pointer within your node struct (required)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
543 * @param loc_data the location of the @c data pointer within your node struct
469
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
544 * @param cmp_func the compare function defining the sort order
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 467
diff changeset
545 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
546 CX_EXTERN CX_NONNULL_ARG(1, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
547 void cx_linked_list_sort(void **begin, void **end,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
548 ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, cx_compare_func cmp_func);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
549
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
550 /**
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
551 * Sorts a linked list based on a comparison function.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
552 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
553 * @note This is a recursive function with at most logarithmic recursion depth.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
554 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
555 * @param begin a pointer to the beginning node pointer (required)
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
556 * @param end a pointer to the end node pointer (optional)
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
557 * @param loc_prev the location of a @c prev pointer within your node struct (negative if not present)
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
558 * @param loc_next the location of a @c next pointer within your node struct (required)
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
559 * @param loc_data the location of the @c data pointer within your node struct
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
560 * @param cmp_func the compare function defining the sort order
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
561 * @param context additional context for the compare function
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
562 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
563 CX_EXTERN CX_NONNULL_ARG(1, 6)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
564 void cx_linked_list_sort_c(void **begin, void **end,
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
565 ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, cx_compare_func2 cmp_func, void *context);
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
566
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 485
diff changeset
567 /**
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 485
diff changeset
568 * Compares two lists element wise.
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 485
diff changeset
569 *
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1423
diff changeset
570 * @attention Both lists must have the same structure.
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
571 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
572 * @param begin_left the beginning of the left list (@c NULL denotes an empty list)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
573 * @param begin_right the beginning of the right list (@c NULL denotes an empty list)
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 485
diff changeset
574 * @param loc_advance the location of the pointer to advance
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
575 * @param loc_data the location of the @c data pointer within your node struct
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 485
diff changeset
576 * @param cmp_func the function to compare the elements
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
577 * @return the first non-zero result of invoking @p cmp_func or: negative if the left list is smaller than the
552
4373c2a90066 #178 fix that lists of different kind cannot be compared
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
578 * right list, positive if the left list is larger than the right list, zero if both lists are equal.
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 485
diff changeset
579 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
580 CX_EXTERN CX_NONNULL_ARG(5)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
581 int cx_linked_list_compare(const void *begin_left, const void *begin_right,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
582 ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func cmp_func);
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 485
diff changeset
583
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
584 /**
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
585 * Compares two lists element wise.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
586 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
587 * @attention Both lists must have the same structure.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
588 *
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
589 * @param begin_left the beginning of the left list (@c NULL denotes an empty list)
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
590 * @param begin_right the beginning of the right list (@c NULL denotes an empty list)
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
591 * @param loc_advance the location of the pointer to advance
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
592 * @param loc_data the location of the @c data pointer within your node struct
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
593 * @param cmp_func the function to compare the elements
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
594 * @return the first non-zero result of invoking @p cmp_func or: negative if the left list is smaller than the
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
595 * right list, positive if the left list is larger than the right list, zero if both lists are equal.
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
596 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
597 CX_EXTERN CX_NONNULL_ARG(5)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
598 int cx_linked_list_compare_c(const void *begin_left, const void *begin_right,
1618
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
599 ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func2 cmp_func, void *context);
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
600
ef7cab6eb131 huge refactoring of collections to add support for 3-arg compare functions
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
601 /**
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
602 * Reverses the order of the nodes in a linked list.
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
603 *
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
604 * @param begin a pointer to the beginning node pointer (required)
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
605 * @param end a pointer to the end node pointer (optional)
1100
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
606 * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one)
2ca6fa71e55e refine docs for linked_list.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
607 * @param loc_next the location of a @c next pointer within your node struct (required)
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
608 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
609 CX_EXTERN CX_NONNULL_ARG(1)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1624
diff changeset
610 void cx_linked_list_reverse(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next);
416
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 412
diff changeset
611
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 552
diff changeset
612 #endif // UCX_LINKED_LIST_H

mercurial