Sun, 30 Nov 2025 18:25:55 +0100
update ucx to version 3.2
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 579 | 29 | * @file list.h |
| 30 | * @brief Interface for list implementations. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #ifndef UCX_LIST_H |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #define UCX_LIST_H |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "common.h" |
| 490 | 40 | #include "collection.h" |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #ifdef __cplusplus |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | extern "C" { |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #endif |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | * List class type. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | typedef struct cx_list_class_s cx_list_class; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | * Structure for holding the base data of a list. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | struct cx_list_s { |
| 579 | 55 | /** |
| 56 | * Common members for collections. | |
| 57 | */ | |
| 58 | CX_COLLECTION_BASE; | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | * The list class definition. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | */ |
| 579 | 62 | const cx_list_class *cl; |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | /** |
| 490 | 64 | * The actual implementation in case the list class is delegating. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | */ |
| 579 | 66 | const cx_list_class *climpl; |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | }; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | * The class definition for arbitrary lists. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | struct cx_list_class_s { |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | * Destructor function. |
| 504 | 75 | * |
| 76 | * Implementations SHALL invoke the content destructor functions if provided | |
| 579 | 77 | * and SHALL deallocate the entire list memory. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | */ |
| 579 | 79 | void (*deallocate)(struct cx_list_s *list); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | /** |
| 504 | 82 | * Member function for inserting a single element. |
| 621 | 83 | * The data pointer may be @c NULL, in which case the function shall only allocate memory. |
| 84 | * Returns a pointer to the allocated memory or @c NULL if allocation fails. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | */ |
| 621 | 86 | void *(*insert_element)(struct cx_list_s *list, size_t index, const void *data); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | /** |
| 490 | 89 | * Member function for inserting multiple elements. |
| 579 | 90 | * |
| 621 | 91 | * The data pointer may be @c NULL, in which case the function shall only allocate memory. |
| 92 | * Returns the number of successfully inserted or allocated elements. | |
| 93 | * | |
| 579 | 94 | * @see cx_list_default_insert_array() |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
95 | */ |
| 621 | 96 | size_t (*insert_array)(struct cx_list_s *list, size_t index, const void *data, size_t n); |
| 579 | 97 | |
| 98 | /** | |
| 99 | * Member function for inserting sorted elements into a sorted list. | |
| 621 | 100 | * Returns the number of successfully inserted elements. |
| 579 | 101 | * |
| 102 | * @see cx_list_default_insert_sorted() | |
| 103 | */ | |
| 621 | 104 | size_t (*insert_sorted)(struct cx_list_s *list, const void *sorted_data, size_t n); |
| 105 | ||
| 106 | /** | |
| 107 | * Member function for inserting multiple elements if they do not exist. | |
| 108 | * Implementations shall return the number of successfully processed elements | |
| 109 | * (including those which were not added because they are already contained). | |
| 110 | * @see cx_list_default_insert_unique() | |
| 111 | */ | |
| 112 | size_t (*insert_unique)(struct cx_list_s *list, const void *sorted_data, size_t n); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | * Member function for inserting an element relative to an iterator position. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | */ |
| 621 | 117 | int (*insert_iter)(struct cx_iterator_s *iter, const void *elem, int prepend); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | /** |
| 579 | 120 | * Member function for removing elements. |
| 121 | * | |
| 122 | * Implementations SHALL check if @p targetbuf is set and copy the elements | |
| 123 | * to the buffer without invoking any destructor. | |
| 124 | * When @p targetbuf is not set, the destructors SHALL be invoked. | |
| 125 | * | |
| 126 | * The function SHALL return the actual number of elements removed, which | |
| 127 | * might be lower than @p num when going out of bounds. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | */ |
| 621 | 129 | size_t (*remove)(struct cx_list_s *list, size_t index, size_t num, void *targetbuf); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | /** |
| 490 | 132 | * Member function for removing all elements. |
| 133 | */ | |
| 134 | void (*clear)(struct cx_list_s *list); | |
| 135 | ||
| 136 | /** | |
| 137 | * Member function for swapping two elements. | |
| 579 | 138 | * |
| 139 | * @see cx_list_default_swap() | |
| 490 | 140 | */ |
| 621 | 141 | int (*swap)(struct cx_list_s *list, size_t i, size_t j); |
| 490 | 142 | |
| 143 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | * Member function for element lookup. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | */ |
| 621 | 146 | void *(*at)(const struct cx_list_s *list, size_t index); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | /** |
| 579 | 149 | * Member function for finding and optionally removing an element. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | */ |
| 621 | 151 | size_t (*find_remove)(struct cx_list_s *list, const void *elem, bool remove); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | /** |
| 579 | 154 | * Member function for sorting the list. |
| 155 | * | |
| 156 | * @see cx_list_default_sort() | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | void (*sort)(struct cx_list_s *list); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | /** |
| 579 | 161 | * Optional member function for comparing this list |
| 162 | * to another list of the same type. | |
| 621 | 163 | * If set to @c NULL, the comparison won't be optimized. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | */ |
| 621 | 165 | int (*compare)(const struct cx_list_s *list, const struct cx_list_s *other); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | * Member function for reversing the order of the items. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | void (*reverse)(struct cx_list_s *list); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | /** |
|
645
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
173 | * Optional member function for changing the capacity. |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
174 | * If the list does not support overallocation, this can be set to @c NULL. |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
175 | */ |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
176 | int (*change_capacity)(struct cx_list_s *list, size_t new_capacity); |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
177 | |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
178 | /** |
| 490 | 179 | * Member function for returning an iterator pointing to the specified index. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | */ |
| 621 | 181 | struct cx_iterator_s (*iterator)(const struct cx_list_s *list, size_t index, bool backward); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | }; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | /** |
| 582 | 185 | * Common type for all list implementations. |
| 186 | */ | |
| 187 | typedef struct cx_list_s CxList; | |
| 188 | ||
| 189 | /** | |
| 190 | * A shared instance of an empty list. | |
| 191 | * | |
| 192 | * Writing to that list is not allowed. | |
| 193 | * | |
| 621 | 194 | * You can use this as a placeholder for initializing CxList pointers |
| 582 | 195 | * for which you do not want to reserve memory right from the beginning. |
| 196 | */ | |
| 621 | 197 | CX_EXPORT extern CxList *const cxEmptyList; |
| 582 | 198 | |
| 199 | /** | |
| 579 | 200 | * Default implementation of an array insert. |
| 201 | * | |
| 202 | * This function uses the element insert function for each element of the array. | |
| 203 | * | |
| 204 | * Use this in your own list class if you do not want to implement an optimized | |
| 205 | * version for your list. | |
| 206 | * | |
| 207 | * @param list the list | |
| 208 | * @param index the index where to insert the data | |
| 209 | * @param data a pointer to the array of data to insert | |
| 210 | * @param n the number of elements to insert | |
| 211 | * @return the number of elements actually inserted | |
| 212 | */ | |
| 213 | cx_attr_nonnull | |
| 621 | 214 | CX_EXPORT size_t cx_list_default_insert_array(struct cx_list_s *list, |
| 215 | size_t index, const void *data, size_t n); | |
| 579 | 216 | |
| 217 | /** | |
| 218 | * Default implementation of a sorted insert. | |
| 219 | * | |
| 220 | * This function uses the array insert function to insert consecutive groups | |
| 221 | * of sorted data. | |
| 222 | * | |
| 223 | * The source data @em must already be sorted wrt. the list's compare function. | |
| 224 | * | |
| 225 | * Use this in your own list class if you do not want to implement an optimized | |
| 226 | * version for your list. | |
| 227 | * | |
| 228 | * @param list the list | |
| 229 | * @param sorted_data a pointer to the array of pre-sorted data to insert | |
| 230 | * @param n the number of elements to insert | |
| 231 | * @return the number of elements actually inserted | |
| 232 | */ | |
| 233 | cx_attr_nonnull | |
| 621 | 234 | CX_EXPORT size_t cx_list_default_insert_sorted(struct cx_list_s *list, |
| 235 | const void *sorted_data, size_t n); | |
| 236 | ||
| 237 | /** | |
| 238 | * Default implementation of an array insert where only elements are inserted when they don't exist in the list. | |
| 239 | * | |
| 240 | * This function is similar to cx_list_default_insert_sorted(), except it skips elements that are already in the list. | |
| 241 | * | |
| 242 | * @note The return value of this function denotes the number of elements from the @p sorted_data that are definitely | |
| 243 | * contained in the list after completing the call. It is @em not the number of elements that were newly inserted. | |
| 244 | * That means, when no error occurred, the return value should be @p n. | |
| 245 | * | |
| 246 | * Use this in your own list class if you do not want to implement an optimized version for your list. | |
| 247 | * | |
| 248 | * @param list the list | |
| 249 | * @param sorted_data a pointer to the array of pre-sorted data to insert | |
| 250 | * @param n the number of elements to insert | |
| 251 | * @return the number of elements from the @p sorted_data that are definitely present in the list after this call | |
| 252 | */ | |
| 253 | cx_attr_nonnull | |
| 254 | CX_EXPORT size_t cx_list_default_insert_unique(struct cx_list_s *list, | |
| 255 | const void *sorted_data, size_t n); | |
| 579 | 256 | |
| 257 | /** | |
| 258 | * Default unoptimized sort implementation. | |
| 259 | * | |
| 260 | * This function will copy all data to an array, sort the array with standard | |
| 261 | * qsort, and then copy the data back to the list memory. | |
| 262 | * | |
| 263 | * Use this in your own list class if you do not want to implement an optimized | |
| 264 | * version for your list. | |
| 265 | * | |
| 266 | * @param list the list that shall be sorted | |
| 267 | */ | |
| 268 | cx_attr_nonnull | |
| 621 | 269 | CX_EXPORT void cx_list_default_sort(struct cx_list_s *list); |
| 579 | 270 | |
| 271 | /** | |
| 272 | * Default unoptimized swap implementation. | |
| 273 | * | |
| 274 | * Use this in your own list class if you do not want to implement an optimized | |
| 275 | * version for your list. | |
| 276 | * | |
| 277 | * @param list the list in which to swap | |
| 278 | * @param i index of one element | |
| 279 | * @param j index of the other element | |
| 280 | * @retval zero success | |
| 281 | * @retval non-zero when indices are out of bounds or memory | |
| 282 | * allocation for the temporary buffer fails | |
| 283 | */ | |
| 284 | cx_attr_nonnull | |
| 621 | 285 | CX_EXPORT int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j); |
| 579 | 286 | |
| 287 | /** | |
| 288 | * Initializes a list struct. | |
| 289 | * | |
| 290 | * Only use this function if you are creating your own list implementation. | |
| 291 | * The purpose of this function is to be called in the initialization code | |
| 621 | 292 | * of your list to set certain members correctly. |
| 579 | 293 | * |
| 294 | * This is particularly important when you want your list to support | |
| 295 | * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list | |
| 296 | * class accordingly and make sure that you can implement your list as if | |
| 621 | 297 | * it was only storing objects, and the wrapper will automatically enable |
| 579 | 298 | * the feature of storing pointers. |
| 299 | * | |
| 300 | * @par Example | |
| 301 | * | |
| 302 | * @code | |
| 303 | * CxList *myCustomListCreate( | |
| 304 | * const CxAllocator *allocator, | |
| 305 | * cx_compare_func comparator, | |
| 306 | * size_t elem_size | |
| 307 | * ) { | |
| 308 | * if (allocator == NULL) { | |
| 309 | * allocator = cxDefaultAllocator; | |
| 310 | * } | |
| 311 | * | |
| 312 | * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList)); | |
| 313 | * if (list == NULL) return NULL; | |
| 314 | * | |
| 315 | * // initialize | |
| 316 | * cx_list_init((CxList*)list, &my_custom_list_class, | |
| 317 | * allocator, comparator, elem_size); | |
| 318 | * | |
| 319 | * // ... some more custom stuff ... | |
| 320 | * | |
| 321 | * return (CxList *) list; | |
| 322 | * } | |
| 323 | * @endcode | |
| 324 | * | |
| 325 | * @param list the list to initialize | |
| 326 | * @param cl the list class | |
| 327 | * @param allocator the allocator for the elements | |
| 328 | * @param comparator a compare function for the elements | |
| 329 | * @param elem_size the size of one element | |
| 330 | */ | |
| 331 | cx_attr_nonnull_arg(1, 2, 3) | |
| 621 | 332 | CX_EXPORT void cx_list_init(struct cx_list_s *list, |
| 333 | struct cx_list_class_s *cl, const struct cx_allocator_s *allocator, | |
| 334 | cx_compare_func comparator, size_t elem_size); | |
| 579 | 335 | |
| 336 | /** | |
| 490 | 337 | * Returns the number of elements currently stored in the list. |
| 338 | * | |
| 339 | * @param list the list | |
| 340 | * @return the number of currently stored elements | |
| 341 | */ | |
| 579 | 342 | cx_attr_nonnull |
| 621 | 343 | CX_EXPORT size_t cxListSize(const CxList *list); |
| 490 | 344 | |
| 345 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | * Adds an item to the end of the list. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | * @param elem a pointer to the element to add |
| 579 | 350 | * @retval zero success |
| 351 | * @retval non-zero memory allocation failure | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
352 | * @see cxListAddArray() |
| 582 | 353 | * @see cxListEmplace() |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | */ |
| 579 | 355 | cx_attr_nonnull |
| 621 | 356 | CX_EXPORT int cxListAdd(CxList *list, const void *elem); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | /** |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
359 | * Adds multiple items to the end of the list. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
360 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
361 | * This method is more efficient than invoking cxListAdd() multiple times. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
362 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
363 | * If there is not enough memory to add all elements, the returned value is |
| 579 | 364 | * less than @p n. |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
365 | * |
| 621 | 366 | * If this list is storing pointers instead of objects, @p array is expected to |
| 490 | 367 | * be an array of pointers. |
| 368 | * | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
369 | * @param list the list |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
370 | * @param array a pointer to the elements to add |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
371 | * @param n the number of elements to add |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
372 | * @return the number of added elements |
| 621 | 373 | * @see cxListEmplaceArray() |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
374 | */ |
| 579 | 375 | cx_attr_nonnull |
| 621 | 376 | CX_EXPORT size_t cxListAddArray(CxList *list, const void *array, size_t n); |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
377 | |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
378 | /** |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | * Inserts an item at the specified index. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | * |
| 621 | 381 | * If the @p index equals the list @c size, this is effectively cxListAdd(). |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | * @param index the index the element shall have |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | * @param elem a pointer to the element to add |
| 579 | 386 | * @retval zero success |
| 387 | * @retval non-zero memory allocation failure or the index is out of bounds | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | * @see cxListInsertAfter() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | * @see cxListInsertBefore() |
| 582 | 390 | * @see cxListEmplaceAt() |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | */ |
| 579 | 392 | cx_attr_nonnull |
| 621 | 393 | CX_EXPORT int cxListInsert(CxList *list, size_t index, const void *elem); |
| 582 | 394 | |
| 395 | /** | |
| 396 | * Allocates memory for an element at the specified index and returns a pointer to that memory. | |
| 397 | * | |
| 398 | * @remark When the list is storing pointers, this will return a @c void**. | |
| 399 | * | |
| 400 | * @param list the list | |
| 401 | * @param index the index where to emplace the element | |
| 402 | * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds | |
| 403 | * @see cxListEmplace() | |
| 621 | 404 | * @see cxListEmplaceArrayAt() |
| 582 | 405 | * @see cxListInsert() |
| 406 | */ | |
| 407 | cx_attr_nonnull | |
| 621 | 408 | CX_EXPORT void *cxListEmplaceAt(CxList *list, size_t index); |
| 582 | 409 | |
| 410 | /** | |
| 411 | * Allocates memory for an element at the end of the list and returns a pointer to that memory. | |
| 412 | * | |
| 413 | * @remark When the list is storing pointers, this will return a @c void**. | |
| 414 | * | |
| 415 | * @param list the list | |
| 416 | * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds | |
| 417 | * @see cxListEmplaceAt() | |
| 418 | * @see cxListAdd() | |
| 419 | */ | |
| 420 | cx_attr_nonnull | |
| 621 | 421 | CX_EXPORT void *cxListEmplace(CxList *list); |
| 422 | ||
| 423 | /** | |
| 424 | * Allocates memory for multiple elements and returns an iterator. | |
| 425 | * | |
| 426 | * The iterator will only iterate over the successfully allocated elements. | |
| 427 | * The @c elem_count attribute is set to that number, and the @c index attribute | |
| 428 | * will range from zero to @c elem_count minus one. | |
| 429 | * | |
| 430 | * @remark When the list is storing pointers, the iterator will iterate over | |
| 431 | * the @c void** elements. | |
| 432 | * | |
| 433 | * @param list the list | |
| 434 | * @param index the index where to insert the new data | |
| 435 | * @param n the number of elements for which to allocate the memory | |
| 436 | * @return an iterator, iterating over the new memory | |
| 437 | * @see cxListEmplaceAt() | |
| 438 | * @see cxListInsertArray() | |
| 439 | */ | |
| 440 | cx_attr_nonnull | |
| 441 | CX_EXPORT CxIterator cxListEmplaceArrayAt(CxList *list, size_t index, size_t n); | |
| 442 | ||
| 443 | /** | |
| 444 | * Allocates memory for multiple elements and returns an iterator. | |
| 445 | * | |
| 446 | * The iterator will only iterate over the successfully allocated elements. | |
| 447 | * The @c elem_count attribute is set to that number, and the @c index attribute | |
| 448 | * will range from zero to @c elem_count minus one. | |
| 449 | * | |
| 450 | * @remark When the list is storing pointers, the iterator will iterate over | |
| 451 | * the @c void** elements. | |
| 452 | * | |
| 453 | * @param list the list | |
| 454 | * @param n the number of elements for which to allocate the memory | |
| 455 | * @return an iterator, iterating over the new memory | |
| 456 | * @see cxListEmplace() | |
| 457 | * @see cxListAddArray() | |
| 458 | */ | |
| 459 | cx_attr_nonnull | |
| 460 | CX_EXPORT CxIterator cxListEmplaceArray(CxList *list, size_t n); | |
| 490 | 461 | |
| 462 | /** | |
| 579 | 463 | * Inserts an item into a sorted list. |
| 464 | * | |
| 465 | * If the list is not sorted already, the behavior is undefined. | |
| 466 | * | |
| 467 | * @param list the list | |
| 468 | * @param elem a pointer to the element to add | |
| 469 | * @retval zero success | |
| 470 | * @retval non-zero memory allocation failure | |
| 471 | */ | |
| 472 | cx_attr_nonnull | |
| 621 | 473 | CX_EXPORT int cxListInsertSorted(CxList *list, const void *elem); |
| 474 | ||
| 475 | /** | |
| 476 | * Inserts an item into a list if it does not exist. | |
| 477 | * | |
| 478 | * If the list is not sorted already, this function will check all elements | |
| 479 | * and append the new element when it was not found. | |
| 480 | * It is strongly recommended to use this function only on sorted lists, where | |
| 481 | * the element, if it is not contained, is inserted at the correct position. | |
| 482 | * | |
| 483 | * @param list the list | |
| 484 | * @param elem a pointer to the element to add | |
| 485 | * @retval zero success (also when the element was already in the list) | |
| 486 | * @retval non-zero memory allocation failure | |
| 487 | */ | |
| 488 | cx_attr_nonnull | |
| 489 | CX_EXPORT int cxListInsertUnique(CxList *list, const void *elem); | |
| 579 | 490 | |
| 491 | /** | |
| 490 | 492 | * Inserts multiple items to the list at the specified index. |
| 621 | 493 | * If the @p index equals the list size, this is effectively cxListAddArray(). |
| 490 | 494 | * |
| 495 | * This method is usually more efficient than invoking cxListInsert() | |
| 496 | * multiple times. | |
| 497 | * | |
| 498 | * If there is not enough memory to add all elements, the returned value is | |
| 579 | 499 | * less than @p n. |
| 490 | 500 | * |
| 621 | 501 | * If this list is storing pointers instead of objects, @p array is expected to |
| 490 | 502 | * be an array of pointers. |
| 503 | * | |
| 504 | * @param list the list | |
| 505 | * @param index the index where to add the elements | |
| 506 | * @param array a pointer to the elements to add | |
| 507 | * @param n the number of elements to add | |
| 508 | * @return the number of added elements | |
| 621 | 509 | * @see cxListEmplaceArrayAt() |
| 490 | 510 | */ |
| 579 | 511 | cx_attr_nonnull |
| 621 | 512 | CX_EXPORT size_t cxListInsertArray(CxList *list, size_t index, const void *array, size_t n); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514 | /** |
| 579 | 515 | * Inserts a sorted array into a sorted list. |
| 516 | * | |
| 621 | 517 | * This method is usually more efficient than inserting each element separately |
| 579 | 518 | * because consecutive chunks of sorted data are inserted in one pass. |
| 519 | * | |
| 520 | * If there is not enough memory to add all elements, the returned value is | |
| 521 | * less than @p n. | |
| 522 | * | |
| 621 | 523 | * If this list is storing pointers instead of objects, @p array is expected to |
| 579 | 524 | * be an array of pointers. |
| 525 | * | |
| 526 | * If the list is not sorted already, the behavior is undefined. | |
| 527 | * | |
| 528 | * @param list the list | |
| 529 | * @param array a pointer to the elements to add | |
| 530 | * @param n the number of elements to add | |
| 531 | * @return the number of added elements | |
| 532 | */ | |
| 533 | cx_attr_nonnull | |
| 621 | 534 | CX_EXPORT size_t cxListInsertSortedArray(CxList *list, const void *array, size_t n); |
| 535 | ||
| 536 | /** | |
| 537 | * Inserts an array into a list, skipping duplicates. | |
| 538 | * | |
| 539 | * The @p list does not need to be sorted (in contrast to cxListInsertSortedArray()). | |
| 540 | * But it is strongly recommended to use this function only on sorted lists, | |
| 541 | * because otherwise it will fall back to an inefficient algorithm which inserts | |
| 542 | * all elements one by one. | |
| 543 | * If the @p list is not sorted, the @p array also does not need to be sorted. | |
| 544 | * But when the @p list is sorted, the @p array must also be sorted. | |
| 545 | * | |
| 546 | * This method is usually more efficient than inserting each element separately | |
| 547 | * because consecutive chunks of sorted data are inserted in one pass. | |
| 548 | * | |
| 549 | * If there is not enough memory to add all elements, the returned value is | |
| 550 | * less than @p n. | |
| 551 | * | |
| 552 | * @note The return value of this function denotes the number of elements | |
| 553 | * from the @p sorted_data that are definitely contained in the list after | |
| 554 | * completing the call. It is @em not the number of elements that were newly | |
| 555 | * inserted. That means, when no error occurred, the return value should | |
| 556 | * be @p n. | |
| 557 | * | |
| 558 | * If this list is storing pointers instead of objects @p array is expected to | |
| 559 | * be an array of pointers. | |
| 560 | * | |
| 561 | * @param list the list | |
| 562 | * @param array a pointer to the elements to add | |
| 563 | * @param n the number of elements to add | |
| 564 | * @return the number of added elements | |
| 565 | * | |
| 566 | * @return the number of elements from the @p sorted_data that are definitely present in the list after this call | |
| 567 | */ | |
| 568 | cx_attr_nonnull | |
| 569 | CX_EXPORT size_t cxListInsertUniqueArray(CxList *list, const void *array, size_t n); | |
| 579 | 570 | |
| 571 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
572 | * Inserts an element after the current location of the specified iterator. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
573 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
574 | * The used iterator remains operational, but all other active iterators should |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
575 | * be considered invalidated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
576 | * |
| 579 | 577 | * If @p iter is not a list iterator, the behavior is undefined. |
| 578 | * If @p iter is a past-the-end iterator, the new element gets appended to the list. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | * @param iter an iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581 | * @param elem the element to insert |
| 579 | 582 | * @retval zero success |
| 583 | * @retval non-zero memory allocation failure | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584 | * @see cxListInsert() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585 | * @see cxListInsertBefore() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
586 | */ |
| 579 | 587 | cx_attr_nonnull |
| 621 | 588 | CX_EXPORT int cxListInsertAfter(CxIterator *iter, const void *elem); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
590 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
591 | * Inserts an element before the current location of the specified iterator. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
592 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
593 | * The used iterator remains operational, but all other active iterators should |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
594 | * be considered invalidated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
595 | * |
| 579 | 596 | * If @p iter is not a list iterator, the behavior is undefined. |
| 597 | * If @p iter is a past-the-end iterator, the new element gets appended to the list. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
599 | * @param iter an iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
600 | * @param elem the element to insert |
| 579 | 601 | * @retval zero success |
| 602 | * @retval non-zero memory allocation failure | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
603 | * @see cxListInsert() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | * @see cxListInsertAfter() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
605 | */ |
| 579 | 606 | cx_attr_nonnull |
| 621 | 607 | CX_EXPORT int cxListInsertBefore(CxIterator *iter, const void *elem); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
608 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | * Removes the element at the specified index. |
| 490 | 611 | * |
| 612 | * If an element destructor function is specified, it is called before | |
| 613 | * removing the element. | |
| 614 | * | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
615 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
616 | * @param index the index of the element |
| 579 | 617 | * @retval zero success |
| 618 | * @retval non-zero index out of bounds | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
619 | */ |
| 579 | 620 | cx_attr_nonnull |
| 621 | 621 | CX_EXPORT int cxListRemove(CxList *list, size_t index); |
| 579 | 622 | |
| 623 | /** | |
| 624 | * Removes and returns the element at the specified index. | |
| 625 | * | |
| 582 | 626 | * No destructor is called, and instead the element is copied to the |
| 579 | 627 | * @p targetbuf which MUST be large enough to hold the removed element. |
| 582 | 628 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
| 579 | 629 | * |
| 630 | * @param list the list | |
| 631 | * @param index the index of the element | |
| 632 | * @param targetbuf a buffer where to copy the element | |
| 633 | * @retval zero success | |
| 634 | * @retval non-zero index out of bounds | |
| 635 | */ | |
| 621 | 636 | cx_attr_nonnull cx_attr_access_w(3) |
| 637 | CX_EXPORT int cxListRemoveAndGet(CxList *list, size_t index, void *targetbuf); | |
| 579 | 638 | |
| 639 | /** | |
| 582 | 640 | * Removes and returns the first element of the list. |
| 641 | * | |
| 642 | * No destructor is called, and instead the element is copied to the | |
| 643 | * @p targetbuf which MUST be large enough to hold the removed element. | |
| 644 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. | |
| 645 | * | |
| 646 | * @param list the list | |
| 647 | * @param targetbuf a buffer where to copy the element | |
| 648 | * @retval zero success | |
| 621 | 649 | * @retval non-zero the list is empty |
| 582 | 650 | * @see cxListPopFront() |
| 651 | * @see cxListRemoveAndGetLast() | |
| 652 | */ | |
| 621 | 653 | cx_attr_nonnull cx_attr_access_w(2) |
| 654 | CX_EXPORT int cxListRemoveAndGetFirst(CxList *list, void *targetbuf); | |
| 582 | 655 | |
| 656 | /** | |
| 657 | * Removes and returns the first element of the list. | |
| 658 | * | |
| 659 | * Alias for cxListRemoveAndGetFirst(). | |
| 660 | * | |
| 661 | * No destructor is called, and instead the element is copied to the | |
| 662 | * @p targetbuf which MUST be large enough to hold the removed element. | |
| 663 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. | |
| 664 | * | |
| 665 | * @param list (@c CxList*) the list | |
| 666 | * @param targetbuf (@c void*) a buffer where to copy the element | |
| 667 | * @retval zero success | |
| 621 | 668 | * @retval non-zero the list is empty |
| 582 | 669 | * @see cxListRemoveAndGetFirst() |
| 670 | * @see cxListPop() | |
| 671 | */ | |
| 672 | #define cxListPopFront(list, targetbuf) cxListRemoveAndGetFirst((list), (targetbuf)) | |
| 673 | ||
| 674 | ||
| 675 | /** | |
| 676 | * Removes and returns the last element of the list. | |
| 677 | * | |
| 678 | * No destructor is called, and instead the element is copied to the | |
| 679 | * @p targetbuf which MUST be large enough to hold the removed element. | |
| 680 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. | |
| 681 | * | |
| 682 | * @param list the list | |
| 683 | * @param targetbuf a buffer where to copy the element | |
| 684 | * @retval zero success | |
| 621 | 685 | * @retval non-zero the list is empty |
| 582 | 686 | */ |
| 621 | 687 | cx_attr_nonnull cx_attr_access_w(2) |
| 688 | CX_EXPORT int cxListRemoveAndGetLast(CxList *list, void *targetbuf); | |
| 582 | 689 | |
| 690 | /** | |
| 691 | * Removes and returns the last element of the list. | |
| 692 | * | |
| 693 | * Alias for cxListRemoveAndGetLast(). | |
| 694 | * | |
| 695 | * No destructor is called, and instead the element is copied to the | |
| 696 | * @p targetbuf which MUST be large enough to hold the removed element. | |
| 697 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. | |
| 698 | * | |
| 699 | * @param list (@c CxList*) the list | |
| 700 | * @param targetbuf (@c void*) a buffer where to copy the element | |
| 701 | * @retval zero success | |
| 621 | 702 | * @retval non-zero the list is empty |
| 582 | 703 | * @see cxListRemoveAndGetLast() |
| 704 | * @see cxListPopFront() | |
| 705 | */ | |
| 706 | #define cxListPop(list, targetbuf) cxListRemoveAndGetLast((list), (targetbuf)) | |
| 707 | ||
| 708 | /** | |
| 579 | 709 | * Removes multiple element starting at the specified index. |
| 710 | * | |
| 711 | * If an element destructor function is specified, it is called for each | |
| 712 | * element. It is guaranteed that the destructor is called before removing | |
| 582 | 713 | * the element. However, due to possible optimizations, it is neither guaranteed |
| 579 | 714 | * that the destructors are invoked for all elements before starting to remove |
| 715 | * them, nor that the element is removed immediately after the destructor call | |
| 716 | * before proceeding to the next element. | |
| 717 | * | |
| 718 | * @param list the list | |
| 719 | * @param index the index of the element | |
| 720 | * @param num the number of elements to remove | |
| 721 | * @return the actual number of removed elements | |
| 722 | */ | |
| 723 | cx_attr_nonnull | |
| 621 | 724 | CX_EXPORT size_t cxListRemoveArray(CxList *list, size_t index, size_t num); |
| 579 | 725 | |
| 726 | /** | |
| 582 | 727 | * Removes and returns multiple elements starting at the specified index. |
| 579 | 728 | * |
| 582 | 729 | * No destructor is called, and instead the elements are copied to the |
| 579 | 730 | * @p targetbuf which MUST be large enough to hold all removed elements. |
| 582 | 731 | * If the list is storing pointers, @p targetbuf is expected to be an array of pointers. |
| 579 | 732 | * |
| 733 | * @param list the list | |
| 734 | * @param index the index of the element | |
| 735 | * @param num the number of elements to remove | |
| 736 | * @param targetbuf a buffer where to copy the elements | |
| 737 | * @return the actual number of removed elements | |
| 738 | */ | |
| 621 | 739 | cx_attr_nonnull cx_attr_access_w(4) |
| 740 | CX_EXPORT size_t cxListRemoveArrayAndGet(CxList *list, size_t index, size_t num, void *targetbuf); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | /** |
| 490 | 743 | * Removes all elements from this list. |
| 744 | * | |
| 579 | 745 | * If element destructor functions are specified, they are called for each |
| 490 | 746 | * element before removing them. |
| 747 | * | |
| 748 | * @param list the list | |
| 749 | */ | |
| 579 | 750 | cx_attr_nonnull |
| 621 | 751 | CX_EXPORT void cxListClear(CxList *list); |
| 490 | 752 | |
| 753 | /** | |
| 754 | * Swaps two items in the list. | |
| 755 | * | |
| 582 | 756 | * Implementations should only allocate temporary memory for the swap if |
| 490 | 757 | * it is necessary. |
| 758 | * | |
| 759 | * @param list the list | |
| 760 | * @param i the index of the first element | |
| 761 | * @param j the index of the second element | |
| 579 | 762 | * @retval zero success |
| 582 | 763 | * @retval non-zero one of the indices is out of bounds, |
| 764 | * or the swap needed extra memory, but allocation failed | |
| 490 | 765 | */ |
| 579 | 766 | cx_attr_nonnull |
| 621 | 767 | CX_EXPORT int cxListSwap(CxList *list, size_t i, size_t j); |
| 490 | 768 | |
| 769 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | * Returns a pointer to the element at the specified index. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
771 | * |
| 582 | 772 | * If the list is storing pointers, returns the pointer stored at the specified index. |
| 773 | * | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | * @param index the index of the element |
| 579 | 776 | * @return a pointer to the element or @c NULL if the index is out of bounds |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777 | */ |
| 579 | 778 | cx_attr_nonnull |
| 621 | 779 | CX_EXPORT void *cxListAt(const CxList *list, size_t index); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
780 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
781 | /** |
| 582 | 782 | * Returns a pointer to the first element. |
| 783 | * | |
| 784 | * If the list is storing pointers, returns the first pointer stored in the list. | |
| 785 | * | |
| 786 | * @param list the list | |
| 787 | * @return a pointer to the first element or @c NULL if the list is empty | |
| 788 | */ | |
| 789 | cx_attr_nonnull | |
| 621 | 790 | CX_EXPORT void *cxListFirst(const CxList *list); |
| 582 | 791 | |
| 792 | /** | |
| 793 | * Returns a pointer to the last element. | |
| 794 | * | |
| 795 | * If the list is storing pointers, returns the last pointer stored in the list. | |
| 796 | * | |
| 797 | * @param list the list | |
| 798 | * @return a pointer to the last element or @c NULL if the list is empty | |
| 799 | */ | |
| 800 | cx_attr_nonnull | |
| 621 | 801 | CX_EXPORT void *cxListLast(const CxList *list); |
| 582 | 802 | |
| 803 | /** | |
| 621 | 804 | * Sets the element at the specified index in the list. |
| 805 | * | |
| 806 | * This overwrites the element in-place without calling any destructor | |
| 807 | * on the overwritten element. | |
| 582 | 808 | * |
| 809 | * @param list the list to set the element in | |
| 810 | * @param index the index to set the element at | |
| 811 | * @param elem element to set | |
| 812 | * @retval zero on success | |
| 813 | * @retval non-zero when index is out of bounds | |
| 814 | */ | |
| 815 | cx_attr_nonnull | |
| 621 | 816 | CX_EXPORT int cxListSet(CxList *list, size_t index, const void *elem); |
| 582 | 817 | |
| 818 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
819 | * Returns an iterator pointing to the item at the specified index. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
820 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
821 | * The returned iterator is position-aware. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
822 | * |
| 621 | 823 | * If the index is out of range or @p list is @c NULL, a past-the-end iterator will be returned. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
824 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
825 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
826 | * @param index the index where the iterator shall point at |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
827 | * @return a new iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
828 | */ |
| 579 | 829 | cx_attr_nodiscard |
| 621 | 830 | CX_EXPORT CxIterator cxListIteratorAt(const CxList *list, size_t index); |
| 490 | 831 | |
| 832 | /** | |
| 833 | * Returns a backwards iterator pointing to the item at the specified index. | |
| 834 | * | |
| 835 | * The returned iterator is position-aware. | |
| 836 | * | |
| 621 | 837 | * If the index is out of range or @p list is @c NULL, a past-the-end iterator will be returned. |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
838 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
839 | * @param list the list |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
840 | * @param index the index where the iterator shall point at |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
841 | * @return a new iterator |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
842 | */ |
| 579 | 843 | cx_attr_nodiscard |
| 621 | 844 | CX_EXPORT CxIterator cxListBackwardsIteratorAt(const CxList *list, size_t index); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
845 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
846 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
847 | * Returns an iterator pointing to the first item of the list. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
848 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
849 | * The returned iterator is position-aware. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
850 | * |
| 582 | 851 | * If the list is empty or @c NULL, a past-the-end iterator will be returned. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
852 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
853 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
854 | * @return a new iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
855 | */ |
| 579 | 856 | cx_attr_nodiscard |
| 621 | 857 | CX_EXPORT CxIterator cxListIterator(const CxList *list); |
| 490 | 858 | |
| 859 | /** | |
| 860 | * Returns a backwards iterator pointing to the last item of the list. | |
| 861 | * | |
| 862 | * The returned iterator is position-aware. | |
| 863 | * | |
| 582 | 864 | * If the list is empty or @c NULL, a past-the-end iterator will be returned. |
| 490 | 865 | * |
| 866 | * @param list the list | |
| 867 | * @return a new iterator | |
| 868 | */ | |
| 579 | 869 | cx_attr_nodiscard |
| 621 | 870 | CX_EXPORT CxIterator cxListBackwardsIterator(const CxList *list); |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
871 | |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
872 | /** |
| 579 | 873 | * Returns the index of the first element that equals @p elem. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
874 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
875 | * Determining equality is performed by the list's comparator function. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
876 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
877 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
878 | * @param elem the element to find |
| 579 | 879 | * @return the index of the element or the size of the list when the element is not found |
| 880 | * @see cxListIndexValid() | |
| 582 | 881 | * @see cxListContains() |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
882 | */ |
| 621 | 883 | cx_attr_nonnull cx_attr_nodiscard |
| 884 | CX_EXPORT size_t cxListFind(const CxList *list, const void *elem); | |
| 579 | 885 | |
| 886 | /** | |
| 621 | 887 | * Checks if the list contains the specified element. |
| 582 | 888 | * |
| 889 | * The elements are compared with the list's comparator function. | |
| 890 | * | |
| 891 | * @param list the list | |
| 892 | * @param elem the element to find | |
| 893 | * @retval true if the element is contained | |
| 894 | * @retval false if the element is not contained | |
| 895 | * @see cxListFind() | |
| 896 | */ | |
| 621 | 897 | cx_attr_nonnull cx_attr_nodiscard |
| 898 | CX_EXPORT bool cxListContains(const CxList* list, const void* elem); | |
| 582 | 899 | |
| 900 | /** | |
| 579 | 901 | * Checks if the specified index is within bounds. |
| 902 | * | |
| 903 | * @param list the list | |
| 904 | * @param index the index | |
| 905 | * @retval true if the index is within bounds | |
| 906 | * @retval false if the index is out of bounds | |
| 907 | */ | |
| 621 | 908 | cx_attr_nonnull cx_attr_nodiscard |
| 909 | CX_EXPORT bool cxListIndexValid(const CxList *list, size_t index); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
910 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
911 | /** |
| 579 | 912 | * Removes and returns the index of the first element that equals @p elem. |
| 913 | * | |
| 914 | * Determining equality is performed by the list's comparator function. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
915 | * |
| 579 | 916 | * @param list the list |
| 917 | * @param elem the element to find and remove | |
| 918 | * @return the index of the now removed element or the list size | |
| 919 | * when the element is not found or could not be removed | |
| 920 | * @see cxListIndexValid() | |
| 921 | */ | |
| 922 | cx_attr_nonnull | |
| 621 | 923 | CX_EXPORT size_t cxListFindRemove(CxList *list, const void *elem); |
| 579 | 924 | |
| 925 | /** | |
| 926 | * Sorts the list. | |
| 927 | * | |
| 928 | * @remark The underlying sort algorithm is implementation defined. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
929 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
930 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
931 | */ |
| 579 | 932 | cx_attr_nonnull |
| 621 | 933 | CX_EXPORT void cxListSort(CxList *list); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
934 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
935 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
936 | * Reverses the order of the items. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
937 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
938 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
939 | */ |
| 579 | 940 | cx_attr_nonnull |
| 621 | 941 | CX_EXPORT void cxListReverse(CxList *list); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
942 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
943 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
944 | * Compares a list to another list of the same type. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
945 | * |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
946 | * First, the list sizes are compared. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
947 | * If they match, the lists are compared element-wise. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
948 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
949 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
950 | * @param other the list to compare to |
| 579 | 951 | * @retval zero both lists are equal element wise |
| 621 | 952 | * @retval negative the first list is smaller, |
| 579 | 953 | * or the first non-equal element in the first list is smaller |
| 954 | * @retval positive the first list is larger | |
| 955 | * or the first non-equal element in the first list is larger | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
956 | */ |
| 621 | 957 | cx_attr_nonnull cx_attr_nodiscard |
| 958 | CX_EXPORT int cxListCompare(const CxList *list, const CxList *other); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
959 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
960 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
961 | * Deallocates the memory of the specified list structure. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
962 | * |
| 579 | 963 | * Also calls the content destructor functions for each element, if specified. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
964 | * |
| 621 | 965 | * @param list the list that shall be freed |
| 966 | */ | |
| 967 | CX_EXPORT void cxListFree(CxList *list); | |
| 968 | ||
| 969 | ||
| 970 | /** | |
| 971 | * Performs a deep clone of one list into another. | |
| 972 | * | |
| 973 | * If the destination list already contains elements, the cloned elements | |
| 974 | * are appended to that list. | |
| 975 | * | |
| 976 | * @attention If the cloned elements need to be destroyed by a destructor | |
| 977 | * function, you must make sure that the destination list also uses this | |
| 978 | * destructor function. | |
| 979 | * | |
| 980 | * @param dst the destination list | |
| 981 | * @param src the source list | |
| 982 | * @param clone_func the clone function for the elements | |
| 983 | * @param clone_allocator the allocator that is passed to the clone function | |
| 984 | * @param data optional additional data that is passed to the clone function | |
| 985 | * @retval zero when all elements were successfully cloned | |
| 986 | * @retval non-zero when an allocation error occurred | |
| 987 | * @see cxListCloneSimple() | |
| 988 | */ | |
| 989 | cx_attr_nonnull_arg(1, 2, 3) | |
| 990 | CX_EXPORT int cxListClone(CxList *dst, const CxList *src, | |
| 991 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 992 | ||
| 993 | /** | |
| 994 | * Clones elements from a list only if they are not present in another list. | |
| 995 | * | |
| 996 | * If the @p minuend does not contain duplicates, this is equivalent to adding | |
| 997 | * the set difference to the destination list. | |
| 998 | * | |
| 999 | * This function is optimized for the case when both the @p minuend and the | |
| 1000 | * @p subtrahend are sorted. | |
| 1001 | * | |
| 1002 | * @param dst the destination list | |
| 1003 | * @param minuend the list to subtract elements from | |
| 1004 | * @param subtrahend the elements that shall be subtracted | |
| 1005 | * @param clone_func the clone function for the elements | |
| 1006 | * @param clone_allocator the allocator that is passed to the clone function | |
| 1007 | * @param data optional additional data that is passed to the clone function | |
| 1008 | * @retval zero when the elements were successfully cloned | |
| 1009 | * @retval non-zero when an allocation error occurred | |
| 1010 | * @see cxListDifferenceSimple() | |
| 1011 | */ | |
| 1012 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 1013 | CX_EXPORT int cxListDifference(CxList *dst, | |
| 1014 | const CxList *minuend, const CxList *subtrahend, | |
| 1015 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 1016 | ||
| 1017 | /** | |
| 1018 | * Clones elements from a list only if they are also present in another list. | |
| 1019 | * | |
| 1020 | * This function is optimized for the case when both the @p src and the | |
| 1021 | * @p other list are sorted. | |
| 1022 | * | |
| 1023 | * If the destination list already contains elements, the intersection is appended | |
| 1024 | * to that list. | |
| 1025 | * | |
| 1026 | * @param dst the destination list | |
| 1027 | * @param src the list to clone the elements from | |
| 1028 | * @param other the list to check the elements for existence | |
| 1029 | * @param clone_func the clone function for the elements | |
| 1030 | * @param clone_allocator the allocator that is passed to the clone function | |
| 1031 | * @param data optional additional data that is passed to the clone function | |
| 1032 | * @retval zero when the elements were successfully cloned | |
| 1033 | * @retval non-zero when an allocation error occurred | |
| 1034 | * @see cxListIntersectionSimple() | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1035 | */ |
| 621 | 1036 | cx_attr_nonnull_arg(1, 2, 3, 4) |
| 1037 | CX_EXPORT int cxListIntersection(CxList *dst, const CxList *src, const CxList *other, | |
| 1038 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 1039 | ||
| 1040 | /** | |
| 1041 | * Performs a deep clone of one list into another, skipping duplicates. | |
| 1042 | * | |
| 1043 | * This function is optimized for the case when both the @p src and the | |
| 1044 | * @p other list are sorted. | |
| 1045 | * In that case, the union will also be sorted. | |
| 1046 | * | |
| 1047 | * If the destination list already contains elements, the union is appended | |
| 1048 | * to that list. In that case the destination is not necessarily sorted. | |
| 1049 | * | |
| 1050 | * @param dst the destination list | |
| 1051 | * @param src the primary source list | |
| 1052 | * @param other the other list, where elements are only cloned from | |
| 1053 | * when they are not in @p src | |
| 1054 | * @param clone_func the clone function for the elements | |
| 1055 | * @param clone_allocator the allocator that is passed to the clone function | |
| 1056 | * @param data optional additional data that is passed to the clone function | |
| 1057 | * @retval zero when the elements were successfully cloned | |
| 1058 | * @retval non-zero when an allocation error occurred | |
| 1059 | * @see cxListUnionSimple() | |
| 1060 | */ | |
| 1061 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 1062 | CX_EXPORT int cxListUnion(CxList *dst, const CxList *src, const CxList *other, | |
| 1063 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 1064 | ||
| 1065 | /** | |
| 1066 | * Performs a shallow clone of one list into another. | |
| 1067 | * | |
| 1068 | * This function uses the default allocator, if needed, and performs | |
| 1069 | * shallow clones with @c memcpy(). | |
| 1070 | * | |
| 1071 | * If the destination list already contains elements, the cloned elements | |
| 1072 | * are appended to that list. | |
| 1073 | * | |
| 1074 | * @attention If the cloned elements need to be destroyed by a destructor | |
| 1075 | * function, you must make sure that the destination list also uses this | |
| 1076 | * destructor function. | |
| 1077 | * | |
| 1078 | * @param dst the destination list | |
| 1079 | * @param src the source list | |
| 1080 | * @retval zero when all elements were successfully cloned | |
| 1081 | * @retval non-zero when an allocation error occurred | |
| 1082 | * @see cxListClone() | |
| 1083 | */ | |
| 1084 | cx_attr_nonnull | |
| 1085 | CX_EXPORT int cxListCloneSimple(CxList *dst, const CxList *src); | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1086 | |
| 621 | 1087 | /** |
| 1088 | * Clones elements from a list only if they are not present in another list. | |
| 1089 | * | |
| 1090 | * This function uses the default allocator, if needed, and performs | |
| 1091 | * shallow clones with @c memcpy(). | |
| 1092 | * | |
| 1093 | * If the @p minuend does not contain duplicates, this is equivalent to adding | |
| 1094 | * the set difference to the destination list. | |
| 1095 | * | |
| 1096 | * This function is optimized for the case when both the @p minuend and the | |
| 1097 | * @p subtrahend are sorted. | |
| 1098 | * | |
| 1099 | * @param dst the destination list | |
| 1100 | * @param minuend the list to subtract elements from | |
| 1101 | * @param subtrahend the elements that shall be subtracted | |
| 1102 | * @retval zero when the elements were successfully cloned | |
| 1103 | * @retval non-zero when an allocation error occurred | |
| 1104 | * @see cxListDifference() | |
| 1105 | */ | |
| 1106 | cx_attr_nonnull | |
| 1107 | CX_EXPORT int cxListDifferenceSimple(CxList *dst, | |
| 1108 | const CxList *minuend, const CxList *subtrahend); | |
| 1109 | ||
| 1110 | /** | |
| 1111 | * Clones elements from a list only if they are also present in another list. | |
| 1112 | * | |
| 1113 | * This function uses the default allocator, if needed, and performs | |
| 1114 | * shallow clones with @c memcpy(). | |
| 1115 | * | |
| 1116 | * This function is optimized for the case when both the @p src and the | |
| 1117 | * @p other list are sorted. | |
| 1118 | * | |
| 1119 | * If the destination list already contains elements, the intersection is appended | |
| 1120 | * to that list. | |
| 1121 | * | |
| 1122 | * @param dst the destination list | |
| 1123 | * @param src the list to clone the elements from | |
| 1124 | * @param other the list to check the elements for existence | |
| 1125 | * @retval zero when the elements were successfully cloned | |
| 1126 | * @retval non-zero when an allocation error occurred | |
| 1127 | * @see cxListIntersection() | |
| 1128 | */ | |
| 1129 | cx_attr_nonnull | |
| 1130 | CX_EXPORT int cxListIntersectionSimple(CxList *dst, const CxList *src, const CxList *other); | |
| 1131 | ||
| 1132 | /** | |
| 1133 | * Performs a deep clone of one list into another, skipping duplicates. | |
| 1134 | * | |
| 1135 | * This function uses the default allocator, if needed, and performs | |
| 1136 | * shallow clones with @c memcpy(). | |
| 1137 | * | |
| 1138 | * This function is optimized for the case when both the @p src and the | |
| 1139 | * @p other list are sorted. | |
| 1140 | * In that case, the union will also be sorted. | |
| 1141 | * | |
| 1142 | * If the destination list already contains elements, the union is appended | |
| 1143 | * to that list. In that case the destination is not necessarily sorted. | |
| 1144 | * | |
| 1145 | * @param dst the destination list | |
| 1146 | * @param src the primary source list | |
| 1147 | * @param other the other list, where elements are only cloned from | |
| 1148 | * when they are not in @p src | |
| 1149 | * @retval zero when the elements were successfully cloned | |
| 1150 | * @retval non-zero when an allocation error occurred | |
| 1151 | * @see cxListUnion() | |
| 1152 | */ | |
| 1153 | cx_attr_nonnull | |
| 1154 | CX_EXPORT int cxListUnionSimple(CxList *dst, const CxList *src, const CxList *other); | |
| 504 | 1155 | |
|
645
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1156 | /** |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1157 | * Asks the list to reserve enough memory for a given total number of elements. |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1158 | * |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1159 | * List implementations are free to choose if reserving memory upfront makes |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1160 | * sense. |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1161 | * For example, array-based implementations usually do support reserving memory |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1162 | * for additional elements while linked lists usually don't. |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1163 | * |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1164 | * @note When the requested capacity is smaller than the current size, |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1165 | * this function returns zero without performing any action. |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1166 | * |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1167 | * @param list the list |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1168 | * @param capacity the expected total number of elements |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1169 | * @retval zero on success or when overallocation is not supported |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1170 | * @retval non-zero when an allocation error occurred |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1171 | * @see cxListShrink() |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1172 | */ |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1173 | cx_attr_nonnull |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1174 | CX_EXPORT int cxListReserve(CxList *list, size_t capacity); |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1175 | |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1176 | /** |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1177 | * Advises the list to free any overallocated memory. |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1178 | * |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1179 | * Lists that do not support overallocation simply return zero. |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1180 | * |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1181 | * This function usually returns zero, except for very special and custom |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1182 | * list and/or allocator implementations where freeing memory can fail. |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1183 | * |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1184 | * @param list the list |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1185 | * @return usually zero |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1186 | */ |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1187 | cx_attr_nonnull |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1188 | CX_EXPORT int cxListShrink(CxList *list); |
|
0c85c4cd0dd8
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1189 | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1190 | #ifdef __cplusplus |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
1191 | } // extern "C" |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1192 | #endif |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1193 | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
1194 | #endif // UCX_LIST_H |