Mon, 10 Nov 2025 21:06:55 +0100
add ucx kv_list
|
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 | /** |
| 490 | 173 | * 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
|
174 | */ |
| 621 | 175 | 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
|
176 | }; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | /** |
| 582 | 179 | * Common type for all list implementations. |
| 180 | */ | |
| 181 | typedef struct cx_list_s CxList; | |
| 182 | ||
| 183 | /** | |
| 184 | * A shared instance of an empty list. | |
| 185 | * | |
| 186 | * Writing to that list is not allowed. | |
| 187 | * | |
| 621 | 188 | * You can use this as a placeholder for initializing CxList pointers |
| 582 | 189 | * for which you do not want to reserve memory right from the beginning. |
| 190 | */ | |
| 621 | 191 | CX_EXPORT extern CxList *const cxEmptyList; |
| 582 | 192 | |
| 193 | /** | |
| 579 | 194 | * Default implementation of an array insert. |
| 195 | * | |
| 196 | * This function uses the element insert function for each element of the array. | |
| 197 | * | |
| 198 | * Use this in your own list class if you do not want to implement an optimized | |
| 199 | * version for your list. | |
| 200 | * | |
| 201 | * @param list the list | |
| 202 | * @param index the index where to insert the data | |
| 203 | * @param data a pointer to the array of data to insert | |
| 204 | * @param n the number of elements to insert | |
| 205 | * @return the number of elements actually inserted | |
| 206 | */ | |
| 207 | cx_attr_nonnull | |
| 621 | 208 | CX_EXPORT size_t cx_list_default_insert_array(struct cx_list_s *list, |
| 209 | size_t index, const void *data, size_t n); | |
| 579 | 210 | |
| 211 | /** | |
| 212 | * Default implementation of a sorted insert. | |
| 213 | * | |
| 214 | * This function uses the array insert function to insert consecutive groups | |
| 215 | * of sorted data. | |
| 216 | * | |
| 217 | * The source data @em must already be sorted wrt. the list's compare function. | |
| 218 | * | |
| 219 | * Use this in your own list class if you do not want to implement an optimized | |
| 220 | * version for your list. | |
| 221 | * | |
| 222 | * @param list the list | |
| 223 | * @param sorted_data a pointer to the array of pre-sorted data to insert | |
| 224 | * @param n the number of elements to insert | |
| 225 | * @return the number of elements actually inserted | |
| 226 | */ | |
| 227 | cx_attr_nonnull | |
| 621 | 228 | CX_EXPORT size_t cx_list_default_insert_sorted(struct cx_list_s *list, |
| 229 | const void *sorted_data, size_t n); | |
| 230 | ||
| 231 | /** | |
| 232 | * Default implementation of an array insert where only elements are inserted when they don't exist in the list. | |
| 233 | * | |
| 234 | * This function is similar to cx_list_default_insert_sorted(), except it skips elements that are already in the list. | |
| 235 | * | |
| 236 | * @note The return value of this function denotes the number of elements from the @p sorted_data that are definitely | |
| 237 | * contained in the list after completing the call. It is @em not the number of elements that were newly inserted. | |
| 238 | * That means, when no error occurred, the return value should be @p n. | |
| 239 | * | |
| 240 | * Use this in your own list class if you do not want to implement an optimized version for your list. | |
| 241 | * | |
| 242 | * @param list the list | |
| 243 | * @param sorted_data a pointer to the array of pre-sorted data to insert | |
| 244 | * @param n the number of elements to insert | |
| 245 | * @return the number of elements from the @p sorted_data that are definitely present in the list after this call | |
| 246 | */ | |
| 247 | cx_attr_nonnull | |
| 248 | CX_EXPORT size_t cx_list_default_insert_unique(struct cx_list_s *list, | |
| 249 | const void *sorted_data, size_t n); | |
| 579 | 250 | |
| 251 | /** | |
| 252 | * Default unoptimized sort implementation. | |
| 253 | * | |
| 254 | * This function will copy all data to an array, sort the array with standard | |
| 255 | * qsort, and then copy the data back to the list memory. | |
| 256 | * | |
| 257 | * Use this in your own list class if you do not want to implement an optimized | |
| 258 | * version for your list. | |
| 259 | * | |
| 260 | * @param list the list that shall be sorted | |
| 261 | */ | |
| 262 | cx_attr_nonnull | |
| 621 | 263 | CX_EXPORT void cx_list_default_sort(struct cx_list_s *list); |
| 579 | 264 | |
| 265 | /** | |
| 266 | * Default unoptimized swap implementation. | |
| 267 | * | |
| 268 | * Use this in your own list class if you do not want to implement an optimized | |
| 269 | * version for your list. | |
| 270 | * | |
| 271 | * @param list the list in which to swap | |
| 272 | * @param i index of one element | |
| 273 | * @param j index of the other element | |
| 274 | * @retval zero success | |
| 275 | * @retval non-zero when indices are out of bounds or memory | |
| 276 | * allocation for the temporary buffer fails | |
| 277 | */ | |
| 278 | cx_attr_nonnull | |
| 621 | 279 | CX_EXPORT int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j); |
| 579 | 280 | |
| 281 | /** | |
| 282 | * Initializes a list struct. | |
| 283 | * | |
| 284 | * Only use this function if you are creating your own list implementation. | |
| 285 | * The purpose of this function is to be called in the initialization code | |
| 621 | 286 | * of your list to set certain members correctly. |
| 579 | 287 | * |
| 288 | * This is particularly important when you want your list to support | |
| 289 | * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list | |
| 290 | * class accordingly and make sure that you can implement your list as if | |
| 621 | 291 | * it was only storing objects, and the wrapper will automatically enable |
| 579 | 292 | * the feature of storing pointers. |
| 293 | * | |
| 294 | * @par Example | |
| 295 | * | |
| 296 | * @code | |
| 297 | * CxList *myCustomListCreate( | |
| 298 | * const CxAllocator *allocator, | |
| 299 | * cx_compare_func comparator, | |
| 300 | * size_t elem_size | |
| 301 | * ) { | |
| 302 | * if (allocator == NULL) { | |
| 303 | * allocator = cxDefaultAllocator; | |
| 304 | * } | |
| 305 | * | |
| 306 | * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList)); | |
| 307 | * if (list == NULL) return NULL; | |
| 308 | * | |
| 309 | * // initialize | |
| 310 | * cx_list_init((CxList*)list, &my_custom_list_class, | |
| 311 | * allocator, comparator, elem_size); | |
| 312 | * | |
| 313 | * // ... some more custom stuff ... | |
| 314 | * | |
| 315 | * return (CxList *) list; | |
| 316 | * } | |
| 317 | * @endcode | |
| 318 | * | |
| 319 | * @param list the list to initialize | |
| 320 | * @param cl the list class | |
| 321 | * @param allocator the allocator for the elements | |
| 322 | * @param comparator a compare function for the elements | |
| 323 | * @param elem_size the size of one element | |
| 324 | */ | |
| 325 | cx_attr_nonnull_arg(1, 2, 3) | |
| 621 | 326 | CX_EXPORT void cx_list_init(struct cx_list_s *list, |
| 327 | struct cx_list_class_s *cl, const struct cx_allocator_s *allocator, | |
| 328 | cx_compare_func comparator, size_t elem_size); | |
| 579 | 329 | |
| 330 | /** | |
| 490 | 331 | * Returns the number of elements currently stored in the list. |
| 332 | * | |
| 333 | * @param list the list | |
| 334 | * @return the number of currently stored elements | |
| 335 | */ | |
| 579 | 336 | cx_attr_nonnull |
| 621 | 337 | CX_EXPORT size_t cxListSize(const CxList *list); |
| 490 | 338 | |
| 339 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | * 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
|
341 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | * @param elem a pointer to the element to add |
| 579 | 344 | * @retval zero success |
| 345 | * @retval non-zero memory allocation failure | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
346 | * @see cxListAddArray() |
| 582 | 347 | * @see cxListEmplace() |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | */ |
| 579 | 349 | cx_attr_nonnull |
| 621 | 350 | 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
|
351 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | /** |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
353 | * Adds multiple items to the end of the list. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
354 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
355 | * 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
|
356 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
357 | * If there is not enough memory to add all elements, the returned value is |
| 579 | 358 | * less than @p n. |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
359 | * |
| 621 | 360 | * If this list is storing pointers instead of objects, @p array is expected to |
| 490 | 361 | * be an array of pointers. |
| 362 | * | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
363 | * @param list the list |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
364 | * @param array a pointer to the elements to add |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
365 | * @param n the number of elements to add |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
366 | * @return the number of added elements |
| 621 | 367 | * @see cxListEmplaceArray() |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
368 | */ |
| 579 | 369 | cx_attr_nonnull |
| 621 | 370 | 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
|
371 | |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
372 | /** |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | * Inserts an item at the specified index. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | * |
| 621 | 375 | * 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
|
376 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | * @param index the index the element shall have |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | * @param elem a pointer to the element to add |
| 579 | 380 | * @retval zero success |
| 381 | * @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
|
382 | * @see cxListInsertAfter() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | * @see cxListInsertBefore() |
| 582 | 384 | * @see cxListEmplaceAt() |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | */ |
| 579 | 386 | cx_attr_nonnull |
| 621 | 387 | CX_EXPORT int cxListInsert(CxList *list, size_t index, const void *elem); |
| 582 | 388 | |
| 389 | /** | |
| 390 | * Allocates memory for an element at the specified index and returns a pointer to that memory. | |
| 391 | * | |
| 392 | * @remark When the list is storing pointers, this will return a @c void**. | |
| 393 | * | |
| 394 | * @param list the list | |
| 395 | * @param index the index where to emplace the element | |
| 396 | * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds | |
| 397 | * @see cxListEmplace() | |
| 621 | 398 | * @see cxListEmplaceArrayAt() |
| 582 | 399 | * @see cxListInsert() |
| 400 | */ | |
| 401 | cx_attr_nonnull | |
| 621 | 402 | CX_EXPORT void *cxListEmplaceAt(CxList *list, size_t index); |
| 582 | 403 | |
| 404 | /** | |
| 405 | * Allocates memory for an element at the end of the list and returns a pointer to that memory. | |
| 406 | * | |
| 407 | * @remark When the list is storing pointers, this will return a @c void**. | |
| 408 | * | |
| 409 | * @param list the list | |
| 410 | * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds | |
| 411 | * @see cxListEmplaceAt() | |
| 412 | * @see cxListAdd() | |
| 413 | */ | |
| 414 | cx_attr_nonnull | |
| 621 | 415 | CX_EXPORT void *cxListEmplace(CxList *list); |
| 416 | ||
| 417 | /** | |
| 418 | * Allocates memory for multiple elements and returns an iterator. | |
| 419 | * | |
| 420 | * The iterator will only iterate over the successfully allocated elements. | |
| 421 | * The @c elem_count attribute is set to that number, and the @c index attribute | |
| 422 | * will range from zero to @c elem_count minus one. | |
| 423 | * | |
| 424 | * @remark When the list is storing pointers, the iterator will iterate over | |
| 425 | * the @c void** elements. | |
| 426 | * | |
| 427 | * @param list the list | |
| 428 | * @param index the index where to insert the new data | |
| 429 | * @param n the number of elements for which to allocate the memory | |
| 430 | * @return an iterator, iterating over the new memory | |
| 431 | * @see cxListEmplaceAt() | |
| 432 | * @see cxListInsertArray() | |
| 433 | */ | |
| 434 | cx_attr_nonnull | |
| 435 | CX_EXPORT CxIterator cxListEmplaceArrayAt(CxList *list, size_t index, size_t n); | |
| 436 | ||
| 437 | /** | |
| 438 | * Allocates memory for multiple elements and returns an iterator. | |
| 439 | * | |
| 440 | * The iterator will only iterate over the successfully allocated elements. | |
| 441 | * The @c elem_count attribute is set to that number, and the @c index attribute | |
| 442 | * will range from zero to @c elem_count minus one. | |
| 443 | * | |
| 444 | * @remark When the list is storing pointers, the iterator will iterate over | |
| 445 | * the @c void** elements. | |
| 446 | * | |
| 447 | * @param list the list | |
| 448 | * @param n the number of elements for which to allocate the memory | |
| 449 | * @return an iterator, iterating over the new memory | |
| 450 | * @see cxListEmplace() | |
| 451 | * @see cxListAddArray() | |
| 452 | */ | |
| 453 | cx_attr_nonnull | |
| 454 | CX_EXPORT CxIterator cxListEmplaceArray(CxList *list, size_t n); | |
| 490 | 455 | |
| 456 | /** | |
| 579 | 457 | * Inserts an item into a sorted list. |
| 458 | * | |
| 459 | * If the list is not sorted already, the behavior is undefined. | |
| 460 | * | |
| 461 | * @param list the list | |
| 462 | * @param elem a pointer to the element to add | |
| 463 | * @retval zero success | |
| 464 | * @retval non-zero memory allocation failure | |
| 465 | */ | |
| 466 | cx_attr_nonnull | |
| 621 | 467 | CX_EXPORT int cxListInsertSorted(CxList *list, const void *elem); |
| 468 | ||
| 469 | /** | |
| 470 | * Inserts an item into a list if it does not exist. | |
| 471 | * | |
| 472 | * If the list is not sorted already, this function will check all elements | |
| 473 | * and append the new element when it was not found. | |
| 474 | * It is strongly recommended to use this function only on sorted lists, where | |
| 475 | * the element, if it is not contained, is inserted at the correct position. | |
| 476 | * | |
| 477 | * @param list the list | |
| 478 | * @param elem a pointer to the element to add | |
| 479 | * @retval zero success (also when the element was already in the list) | |
| 480 | * @retval non-zero memory allocation failure | |
| 481 | */ | |
| 482 | cx_attr_nonnull | |
| 483 | CX_EXPORT int cxListInsertUnique(CxList *list, const void *elem); | |
| 579 | 484 | |
| 485 | /** | |
| 490 | 486 | * Inserts multiple items to the list at the specified index. |
| 621 | 487 | * If the @p index equals the list size, this is effectively cxListAddArray(). |
| 490 | 488 | * |
| 489 | * This method is usually more efficient than invoking cxListInsert() | |
| 490 | * multiple times. | |
| 491 | * | |
| 492 | * If there is not enough memory to add all elements, the returned value is | |
| 579 | 493 | * less than @p n. |
| 490 | 494 | * |
| 621 | 495 | * If this list is storing pointers instead of objects, @p array is expected to |
| 490 | 496 | * be an array of pointers. |
| 497 | * | |
| 498 | * @param list the list | |
| 499 | * @param index the index where to add the elements | |
| 500 | * @param array a pointer to the elements to add | |
| 501 | * @param n the number of elements to add | |
| 502 | * @return the number of added elements | |
| 621 | 503 | * @see cxListEmplaceArrayAt() |
| 490 | 504 | */ |
| 579 | 505 | cx_attr_nonnull |
| 621 | 506 | 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
|
507 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | /** |
| 579 | 509 | * Inserts a sorted array into a sorted list. |
| 510 | * | |
| 621 | 511 | * This method is usually more efficient than inserting each element separately |
| 579 | 512 | * because consecutive chunks of sorted data are inserted in one pass. |
| 513 | * | |
| 514 | * If there is not enough memory to add all elements, the returned value is | |
| 515 | * less than @p n. | |
| 516 | * | |
| 621 | 517 | * If this list is storing pointers instead of objects, @p array is expected to |
| 579 | 518 | * be an array of pointers. |
| 519 | * | |
| 520 | * If the list is not sorted already, the behavior is undefined. | |
| 521 | * | |
| 522 | * @param list the list | |
| 523 | * @param array a pointer to the elements to add | |
| 524 | * @param n the number of elements to add | |
| 525 | * @return the number of added elements | |
| 526 | */ | |
| 527 | cx_attr_nonnull | |
| 621 | 528 | CX_EXPORT size_t cxListInsertSortedArray(CxList *list, const void *array, size_t n); |
| 529 | ||
| 530 | /** | |
| 531 | * Inserts an array into a list, skipping duplicates. | |
| 532 | * | |
| 533 | * The @p list does not need to be sorted (in contrast to cxListInsertSortedArray()). | |
| 534 | * But it is strongly recommended to use this function only on sorted lists, | |
| 535 | * because otherwise it will fall back to an inefficient algorithm which inserts | |
| 536 | * all elements one by one. | |
| 537 | * If the @p list is not sorted, the @p array also does not need to be sorted. | |
| 538 | * But when the @p list is sorted, the @p array must also be sorted. | |
| 539 | * | |
| 540 | * This method is usually more efficient than inserting each element separately | |
| 541 | * because consecutive chunks of sorted data are inserted in one pass. | |
| 542 | * | |
| 543 | * If there is not enough memory to add all elements, the returned value is | |
| 544 | * less than @p n. | |
| 545 | * | |
| 546 | * @note The return value of this function denotes the number of elements | |
| 547 | * from the @p sorted_data that are definitely contained in the list after | |
| 548 | * completing the call. It is @em not the number of elements that were newly | |
| 549 | * inserted. That means, when no error occurred, the return value should | |
| 550 | * be @p n. | |
| 551 | * | |
| 552 | * If this list is storing pointers instead of objects @p array is expected to | |
| 553 | * be an array of pointers. | |
| 554 | * | |
| 555 | * @param list the list | |
| 556 | * @param array a pointer to the elements to add | |
| 557 | * @param n the number of elements to add | |
| 558 | * @return the number of added elements | |
| 559 | * | |
| 560 | * @return the number of elements from the @p sorted_data that are definitely present in the list after this call | |
| 561 | */ | |
| 562 | cx_attr_nonnull | |
| 563 | CX_EXPORT size_t cxListInsertUniqueArray(CxList *list, const void *array, size_t n); | |
| 579 | 564 | |
| 565 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
566 | * 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
|
567 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
568 | * 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
|
569 | * be considered invalidated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
570 | * |
| 579 | 571 | * If @p iter is not a list iterator, the behavior is undefined. |
| 572 | * 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
|
573 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
574 | * @param iter an iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
575 | * @param elem the element to insert |
| 579 | 576 | * @retval zero success |
| 577 | * @retval non-zero memory allocation failure | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
578 | * @see cxListInsert() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
579 | * @see cxListInsertBefore() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
580 | */ |
| 579 | 581 | cx_attr_nonnull |
| 621 | 582 | 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
|
583 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
584 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
585 | * 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
|
586 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
587 | * 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
|
588 | * be considered invalidated. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
589 | * |
| 579 | 590 | * If @p iter is not a list iterator, the behavior is undefined. |
| 591 | * 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
|
592 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
593 | * @param iter an iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
594 | * @param elem the element to insert |
| 579 | 595 | * @retval zero success |
| 596 | * @retval non-zero memory allocation failure | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
597 | * @see cxListInsert() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
598 | * @see cxListInsertAfter() |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
599 | */ |
| 579 | 600 | cx_attr_nonnull |
| 621 | 601 | 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
|
602 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
603 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
604 | * Removes the element at the specified index. |
| 490 | 605 | * |
| 606 | * If an element destructor function is specified, it is called before | |
| 607 | * removing the element. | |
| 608 | * | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
609 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
610 | * @param index the index of the element |
| 579 | 611 | * @retval zero success |
| 612 | * @retval non-zero index out of bounds | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
613 | */ |
| 579 | 614 | cx_attr_nonnull |
| 621 | 615 | CX_EXPORT int cxListRemove(CxList *list, size_t index); |
| 579 | 616 | |
| 617 | /** | |
| 618 | * Removes and returns the element at the specified index. | |
| 619 | * | |
| 582 | 620 | * No destructor is called, and instead the element is copied to the |
| 579 | 621 | * @p targetbuf which MUST be large enough to hold the removed element. |
| 582 | 622 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
| 579 | 623 | * |
| 624 | * @param list the list | |
| 625 | * @param index the index of the element | |
| 626 | * @param targetbuf a buffer where to copy the element | |
| 627 | * @retval zero success | |
| 628 | * @retval non-zero index out of bounds | |
| 629 | */ | |
| 621 | 630 | cx_attr_nonnull cx_attr_access_w(3) |
| 631 | CX_EXPORT int cxListRemoveAndGet(CxList *list, size_t index, void *targetbuf); | |
| 579 | 632 | |
| 633 | /** | |
| 582 | 634 | * Removes and returns the first element of the list. |
| 635 | * | |
| 636 | * No destructor is called, and instead the element is copied to the | |
| 637 | * @p targetbuf which MUST be large enough to hold the removed element. | |
| 638 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. | |
| 639 | * | |
| 640 | * @param list the list | |
| 641 | * @param targetbuf a buffer where to copy the element | |
| 642 | * @retval zero success | |
| 621 | 643 | * @retval non-zero the list is empty |
| 582 | 644 | * @see cxListPopFront() |
| 645 | * @see cxListRemoveAndGetLast() | |
| 646 | */ | |
| 621 | 647 | cx_attr_nonnull cx_attr_access_w(2) |
| 648 | CX_EXPORT int cxListRemoveAndGetFirst(CxList *list, void *targetbuf); | |
| 582 | 649 | |
| 650 | /** | |
| 651 | * Removes and returns the first element of the list. | |
| 652 | * | |
| 653 | * Alias for cxListRemoveAndGetFirst(). | |
| 654 | * | |
| 655 | * No destructor is called, and instead the element is copied to the | |
| 656 | * @p targetbuf which MUST be large enough to hold the removed element. | |
| 657 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. | |
| 658 | * | |
| 659 | * @param list (@c CxList*) the list | |
| 660 | * @param targetbuf (@c void*) a buffer where to copy the element | |
| 661 | * @retval zero success | |
| 621 | 662 | * @retval non-zero the list is empty |
| 582 | 663 | * @see cxListRemoveAndGetFirst() |
| 664 | * @see cxListPop() | |
| 665 | */ | |
| 666 | #define cxListPopFront(list, targetbuf) cxListRemoveAndGetFirst((list), (targetbuf)) | |
| 667 | ||
| 668 | ||
| 669 | /** | |
| 670 | * Removes and returns the last element of the list. | |
| 671 | * | |
| 672 | * No destructor is called, and instead the element is copied to the | |
| 673 | * @p targetbuf which MUST be large enough to hold the removed element. | |
| 674 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. | |
| 675 | * | |
| 676 | * @param list the list | |
| 677 | * @param targetbuf a buffer where to copy the element | |
| 678 | * @retval zero success | |
| 621 | 679 | * @retval non-zero the list is empty |
| 582 | 680 | */ |
| 621 | 681 | cx_attr_nonnull cx_attr_access_w(2) |
| 682 | CX_EXPORT int cxListRemoveAndGetLast(CxList *list, void *targetbuf); | |
| 582 | 683 | |
| 684 | /** | |
| 685 | * Removes and returns the last element of the list. | |
| 686 | * | |
| 687 | * Alias for cxListRemoveAndGetLast(). | |
| 688 | * | |
| 689 | * No destructor is called, and instead the element is copied to the | |
| 690 | * @p targetbuf which MUST be large enough to hold the removed element. | |
| 691 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. | |
| 692 | * | |
| 693 | * @param list (@c CxList*) the list | |
| 694 | * @param targetbuf (@c void*) a buffer where to copy the element | |
| 695 | * @retval zero success | |
| 621 | 696 | * @retval non-zero the list is empty |
| 582 | 697 | * @see cxListRemoveAndGetLast() |
| 698 | * @see cxListPopFront() | |
| 699 | */ | |
| 700 | #define cxListPop(list, targetbuf) cxListRemoveAndGetLast((list), (targetbuf)) | |
| 701 | ||
| 702 | /** | |
| 579 | 703 | * Removes multiple element starting at the specified index. |
| 704 | * | |
| 705 | * If an element destructor function is specified, it is called for each | |
| 706 | * element. It is guaranteed that the destructor is called before removing | |
| 582 | 707 | * the element. However, due to possible optimizations, it is neither guaranteed |
| 579 | 708 | * that the destructors are invoked for all elements before starting to remove |
| 709 | * them, nor that the element is removed immediately after the destructor call | |
| 710 | * before proceeding to the next element. | |
| 711 | * | |
| 712 | * @param list the list | |
| 713 | * @param index the index of the element | |
| 714 | * @param num the number of elements to remove | |
| 715 | * @return the actual number of removed elements | |
| 716 | */ | |
| 717 | cx_attr_nonnull | |
| 621 | 718 | CX_EXPORT size_t cxListRemoveArray(CxList *list, size_t index, size_t num); |
| 579 | 719 | |
| 720 | /** | |
| 582 | 721 | * Removes and returns multiple elements starting at the specified index. |
| 579 | 722 | * |
| 582 | 723 | * No destructor is called, and instead the elements are copied to the |
| 579 | 724 | * @p targetbuf which MUST be large enough to hold all removed elements. |
| 582 | 725 | * If the list is storing pointers, @p targetbuf is expected to be an array of pointers. |
| 579 | 726 | * |
| 727 | * @param list the list | |
| 728 | * @param index the index of the element | |
| 729 | * @param num the number of elements to remove | |
| 730 | * @param targetbuf a buffer where to copy the elements | |
| 731 | * @return the actual number of removed elements | |
| 732 | */ | |
| 621 | 733 | cx_attr_nonnull cx_attr_access_w(4) |
| 734 | 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
|
735 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
736 | /** |
| 490 | 737 | * Removes all elements from this list. |
| 738 | * | |
| 579 | 739 | * If element destructor functions are specified, they are called for each |
| 490 | 740 | * element before removing them. |
| 741 | * | |
| 742 | * @param list the list | |
| 743 | */ | |
| 579 | 744 | cx_attr_nonnull |
| 621 | 745 | CX_EXPORT void cxListClear(CxList *list); |
| 490 | 746 | |
| 747 | /** | |
| 748 | * Swaps two items in the list. | |
| 749 | * | |
| 582 | 750 | * Implementations should only allocate temporary memory for the swap if |
| 490 | 751 | * it is necessary. |
| 752 | * | |
| 753 | * @param list the list | |
| 754 | * @param i the index of the first element | |
| 755 | * @param j the index of the second element | |
| 579 | 756 | * @retval zero success |
| 582 | 757 | * @retval non-zero one of the indices is out of bounds, |
| 758 | * or the swap needed extra memory, but allocation failed | |
| 490 | 759 | */ |
| 579 | 760 | cx_attr_nonnull |
| 621 | 761 | CX_EXPORT int cxListSwap(CxList *list, size_t i, size_t j); |
| 490 | 762 | |
| 763 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
764 | * 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
|
765 | * |
| 582 | 766 | * If the list is storing pointers, returns the pointer stored at the specified index. |
| 767 | * | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
768 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
769 | * @param index the index of the element |
| 579 | 770 | * @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
|
771 | */ |
| 579 | 772 | cx_attr_nonnull |
| 621 | 773 | 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
|
774 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | /** |
| 582 | 776 | * Returns a pointer to the first element. |
| 777 | * | |
| 778 | * If the list is storing pointers, returns the first pointer stored in the list. | |
| 779 | * | |
| 780 | * @param list the list | |
| 781 | * @return a pointer to the first element or @c NULL if the list is empty | |
| 782 | */ | |
| 783 | cx_attr_nonnull | |
| 621 | 784 | CX_EXPORT void *cxListFirst(const CxList *list); |
| 582 | 785 | |
| 786 | /** | |
| 787 | * Returns a pointer to the last element. | |
| 788 | * | |
| 789 | * If the list is storing pointers, returns the last pointer stored in the list. | |
| 790 | * | |
| 791 | * @param list the list | |
| 792 | * @return a pointer to the last element or @c NULL if the list is empty | |
| 793 | */ | |
| 794 | cx_attr_nonnull | |
| 621 | 795 | CX_EXPORT void *cxListLast(const CxList *list); |
| 582 | 796 | |
| 797 | /** | |
| 621 | 798 | * Sets the element at the specified index in the list. |
| 799 | * | |
| 800 | * This overwrites the element in-place without calling any destructor | |
| 801 | * on the overwritten element. | |
| 582 | 802 | * |
| 803 | * @param list the list to set the element in | |
| 804 | * @param index the index to set the element at | |
| 805 | * @param elem element to set | |
| 806 | * @retval zero on success | |
| 807 | * @retval non-zero when index is out of bounds | |
| 808 | */ | |
| 809 | cx_attr_nonnull | |
| 621 | 810 | CX_EXPORT int cxListSet(CxList *list, size_t index, const void *elem); |
| 582 | 811 | |
| 812 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
813 | * 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
|
814 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
815 | * The returned iterator is position-aware. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
816 | * |
| 621 | 817 | * 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
|
818 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
819 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
820 | * @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
|
821 | * @return a new iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
822 | */ |
| 579 | 823 | cx_attr_nodiscard |
| 621 | 824 | CX_EXPORT CxIterator cxListIteratorAt(const CxList *list, size_t index); |
| 490 | 825 | |
| 826 | /** | |
| 827 | * Returns a backwards iterator pointing to the item at the specified index. | |
| 828 | * | |
| 829 | * The returned iterator is position-aware. | |
| 830 | * | |
| 621 | 831 | * 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
|
832 | * |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
833 | * @param list the list |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
834 | * @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
|
835 | * @return a new iterator |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
836 | */ |
| 579 | 837 | cx_attr_nodiscard |
| 621 | 838 | 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
|
839 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
841 | * 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
|
842 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
843 | * The returned iterator is position-aware. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
844 | * |
| 582 | 845 | * 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
|
846 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
847 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
848 | * @return a new iterator |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
849 | */ |
| 579 | 850 | cx_attr_nodiscard |
| 621 | 851 | CX_EXPORT CxIterator cxListIterator(const CxList *list); |
| 490 | 852 | |
| 853 | /** | |
| 854 | * Returns a backwards iterator pointing to the last item of the list. | |
| 855 | * | |
| 856 | * The returned iterator is position-aware. | |
| 857 | * | |
| 582 | 858 | * If the list is empty or @c NULL, a past-the-end iterator will be returned. |
| 490 | 859 | * |
| 860 | * @param list the list | |
| 861 | * @return a new iterator | |
| 862 | */ | |
| 579 | 863 | cx_attr_nodiscard |
| 621 | 864 | CX_EXPORT CxIterator cxListBackwardsIterator(const CxList *list); |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
865 | |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
866 | /** |
| 579 | 867 | * 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
|
868 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
869 | * 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
|
870 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
871 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
872 | * @param elem the element to find |
| 579 | 873 | * @return the index of the element or the size of the list when the element is not found |
| 874 | * @see cxListIndexValid() | |
| 582 | 875 | * @see cxListContains() |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
876 | */ |
| 621 | 877 | cx_attr_nonnull cx_attr_nodiscard |
| 878 | CX_EXPORT size_t cxListFind(const CxList *list, const void *elem); | |
| 579 | 879 | |
| 880 | /** | |
| 621 | 881 | * Checks if the list contains the specified element. |
| 582 | 882 | * |
| 883 | * The elements are compared with the list's comparator function. | |
| 884 | * | |
| 885 | * @param list the list | |
| 886 | * @param elem the element to find | |
| 887 | * @retval true if the element is contained | |
| 888 | * @retval false if the element is not contained | |
| 889 | * @see cxListFind() | |
| 890 | */ | |
| 621 | 891 | cx_attr_nonnull cx_attr_nodiscard |
| 892 | CX_EXPORT bool cxListContains(const CxList* list, const void* elem); | |
| 582 | 893 | |
| 894 | /** | |
| 579 | 895 | * Checks if the specified index is within bounds. |
| 896 | * | |
| 897 | * @param list the list | |
| 898 | * @param index the index | |
| 899 | * @retval true if the index is within bounds | |
| 900 | * @retval false if the index is out of bounds | |
| 901 | */ | |
| 621 | 902 | cx_attr_nonnull cx_attr_nodiscard |
| 903 | 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
|
904 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
905 | /** |
| 579 | 906 | * Removes and returns the index of the first element that equals @p elem. |
| 907 | * | |
| 908 | * 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
|
909 | * |
| 579 | 910 | * @param list the list |
| 911 | * @param elem the element to find and remove | |
| 912 | * @return the index of the now removed element or the list size | |
| 913 | * when the element is not found or could not be removed | |
| 914 | * @see cxListIndexValid() | |
| 915 | */ | |
| 916 | cx_attr_nonnull | |
| 621 | 917 | CX_EXPORT size_t cxListFindRemove(CxList *list, const void *elem); |
| 579 | 918 | |
| 919 | /** | |
| 920 | * Sorts the list. | |
| 921 | * | |
| 922 | * @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
|
923 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
924 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
925 | */ |
| 579 | 926 | cx_attr_nonnull |
| 621 | 927 | CX_EXPORT void cxListSort(CxList *list); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
928 | |
|
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 | * Reverses the order of the items. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
931 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
932 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933 | */ |
| 579 | 934 | cx_attr_nonnull |
| 621 | 935 | CX_EXPORT void cxListReverse(CxList *list); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
936 | |
|
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 | * 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
|
939 | * |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
940 | * First, the list sizes are compared. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
941 | * 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
|
942 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
943 | * @param list the list |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
944 | * @param other the list to compare to |
| 579 | 945 | * @retval zero both lists are equal element wise |
| 621 | 946 | * @retval negative the first list is smaller, |
| 579 | 947 | * or the first non-equal element in the first list is smaller |
| 948 | * @retval positive the first list is larger | |
| 949 | * 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
|
950 | */ |
| 621 | 951 | cx_attr_nonnull cx_attr_nodiscard |
| 952 | 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
|
953 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
954 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
955 | * Deallocates the memory of the specified list structure. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
956 | * |
| 579 | 957 | * 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
|
958 | * |
| 621 | 959 | * @param list the list that shall be freed |
| 960 | */ | |
| 961 | CX_EXPORT void cxListFree(CxList *list); | |
| 962 | ||
| 963 | ||
| 964 | /** | |
| 965 | * Performs a deep clone of one list into another. | |
| 966 | * | |
| 967 | * If the destination list already contains elements, the cloned elements | |
| 968 | * are appended to that list. | |
| 969 | * | |
| 970 | * @attention If the cloned elements need to be destroyed by a destructor | |
| 971 | * function, you must make sure that the destination list also uses this | |
| 972 | * destructor function. | |
| 973 | * | |
| 974 | * @param dst the destination list | |
| 975 | * @param src the source list | |
| 976 | * @param clone_func the clone function for the elements | |
| 977 | * @param clone_allocator the allocator that is passed to the clone function | |
| 978 | * @param data optional additional data that is passed to the clone function | |
| 979 | * @retval zero when all elements were successfully cloned | |
| 980 | * @retval non-zero when an allocation error occurred | |
| 981 | * @see cxListCloneSimple() | |
| 982 | */ | |
| 983 | cx_attr_nonnull_arg(1, 2, 3) | |
| 984 | CX_EXPORT int cxListClone(CxList *dst, const CxList *src, | |
| 985 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 986 | ||
| 987 | /** | |
| 988 | * Clones elements from a list only if they are not present in another list. | |
| 989 | * | |
| 990 | * If the @p minuend does not contain duplicates, this is equivalent to adding | |
| 991 | * the set difference to the destination list. | |
| 992 | * | |
| 993 | * This function is optimized for the case when both the @p minuend and the | |
| 994 | * @p subtrahend are sorted. | |
| 995 | * | |
| 996 | * @param dst the destination list | |
| 997 | * @param minuend the list to subtract elements from | |
| 998 | * @param subtrahend the elements that shall be subtracted | |
| 999 | * @param clone_func the clone function for the elements | |
| 1000 | * @param clone_allocator the allocator that is passed to the clone function | |
| 1001 | * @param data optional additional data that is passed to the clone function | |
| 1002 | * @retval zero when the elements were successfully cloned | |
| 1003 | * @retval non-zero when an allocation error occurred | |
| 1004 | * @see cxListDifferenceSimple() | |
| 1005 | */ | |
| 1006 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 1007 | CX_EXPORT int cxListDifference(CxList *dst, | |
| 1008 | const CxList *minuend, const CxList *subtrahend, | |
| 1009 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 1010 | ||
| 1011 | /** | |
| 1012 | * Clones elements from a list only if they are also present in another list. | |
| 1013 | * | |
| 1014 | * This function is optimized for the case when both the @p src and the | |
| 1015 | * @p other list are sorted. | |
| 1016 | * | |
| 1017 | * If the destination list already contains elements, the intersection is appended | |
| 1018 | * to that list. | |
| 1019 | * | |
| 1020 | * @param dst the destination list | |
| 1021 | * @param src the list to clone the elements from | |
| 1022 | * @param other the list to check the elements for existence | |
| 1023 | * @param clone_func the clone function for the elements | |
| 1024 | * @param clone_allocator the allocator that is passed to the clone function | |
| 1025 | * @param data optional additional data that is passed to the clone function | |
| 1026 | * @retval zero when the elements were successfully cloned | |
| 1027 | * @retval non-zero when an allocation error occurred | |
| 1028 | * @see cxListIntersectionSimple() | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1029 | */ |
| 621 | 1030 | cx_attr_nonnull_arg(1, 2, 3, 4) |
| 1031 | CX_EXPORT int cxListIntersection(CxList *dst, const CxList *src, const CxList *other, | |
| 1032 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 1033 | ||
| 1034 | /** | |
| 1035 | * Performs a deep clone of one list into another, skipping duplicates. | |
| 1036 | * | |
| 1037 | * This function is optimized for the case when both the @p src and the | |
| 1038 | * @p other list are sorted. | |
| 1039 | * In that case, the union will also be sorted. | |
| 1040 | * | |
| 1041 | * If the destination list already contains elements, the union is appended | |
| 1042 | * to that list. In that case the destination is not necessarily sorted. | |
| 1043 | * | |
| 1044 | * @param dst the destination list | |
| 1045 | * @param src the primary source list | |
| 1046 | * @param other the other list, where elements are only cloned from | |
| 1047 | * when they are not in @p src | |
| 1048 | * @param clone_func the clone function for the elements | |
| 1049 | * @param clone_allocator the allocator that is passed to the clone function | |
| 1050 | * @param data optional additional data that is passed to the clone function | |
| 1051 | * @retval zero when the elements were successfully cloned | |
| 1052 | * @retval non-zero when an allocation error occurred | |
| 1053 | * @see cxListUnionSimple() | |
| 1054 | */ | |
| 1055 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 1056 | CX_EXPORT int cxListUnion(CxList *dst, const CxList *src, const CxList *other, | |
| 1057 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 1058 | ||
| 1059 | /** | |
| 1060 | * Performs a shallow clone of one list into another. | |
| 1061 | * | |
| 1062 | * This function uses the default allocator, if needed, and performs | |
| 1063 | * shallow clones with @c memcpy(). | |
| 1064 | * | |
| 1065 | * If the destination list already contains elements, the cloned elements | |
| 1066 | * are appended to that list. | |
| 1067 | * | |
| 1068 | * @attention If the cloned elements need to be destroyed by a destructor | |
| 1069 | * function, you must make sure that the destination list also uses this | |
| 1070 | * destructor function. | |
| 1071 | * | |
| 1072 | * @param dst the destination list | |
| 1073 | * @param src the source list | |
| 1074 | * @retval zero when all elements were successfully cloned | |
| 1075 | * @retval non-zero when an allocation error occurred | |
| 1076 | * @see cxListClone() | |
| 1077 | */ | |
| 1078 | cx_attr_nonnull | |
| 1079 | 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
|
1080 | |
| 621 | 1081 | /** |
| 1082 | * Clones elements from a list only if they are not present in another list. | |
| 1083 | * | |
| 1084 | * This function uses the default allocator, if needed, and performs | |
| 1085 | * shallow clones with @c memcpy(). | |
| 1086 | * | |
| 1087 | * If the @p minuend does not contain duplicates, this is equivalent to adding | |
| 1088 | * the set difference to the destination list. | |
| 1089 | * | |
| 1090 | * This function is optimized for the case when both the @p minuend and the | |
| 1091 | * @p subtrahend are sorted. | |
| 1092 | * | |
| 1093 | * @param dst the destination list | |
| 1094 | * @param minuend the list to subtract elements from | |
| 1095 | * @param subtrahend the elements that shall be subtracted | |
| 1096 | * @retval zero when the elements were successfully cloned | |
| 1097 | * @retval non-zero when an allocation error occurred | |
| 1098 | * @see cxListDifference() | |
| 1099 | */ | |
| 1100 | cx_attr_nonnull | |
| 1101 | CX_EXPORT int cxListDifferenceSimple(CxList *dst, | |
| 1102 | const CxList *minuend, const CxList *subtrahend); | |
| 1103 | ||
| 1104 | /** | |
| 1105 | * Clones elements from a list only if they are also present in another list. | |
| 1106 | * | |
| 1107 | * This function uses the default allocator, if needed, and performs | |
| 1108 | * shallow clones with @c memcpy(). | |
| 1109 | * | |
| 1110 | * This function is optimized for the case when both the @p src and the | |
| 1111 | * @p other list are sorted. | |
| 1112 | * | |
| 1113 | * If the destination list already contains elements, the intersection is appended | |
| 1114 | * to that list. | |
| 1115 | * | |
| 1116 | * @param dst the destination list | |
| 1117 | * @param src the list to clone the elements from | |
| 1118 | * @param other the list to check the elements for existence | |
| 1119 | * @retval zero when the elements were successfully cloned | |
| 1120 | * @retval non-zero when an allocation error occurred | |
| 1121 | * @see cxListIntersection() | |
| 1122 | */ | |
| 1123 | cx_attr_nonnull | |
| 1124 | CX_EXPORT int cxListIntersectionSimple(CxList *dst, const CxList *src, const CxList *other); | |
| 1125 | ||
| 1126 | /** | |
| 1127 | * Performs a deep clone of one list into another, skipping duplicates. | |
| 1128 | * | |
| 1129 | * This function uses the default allocator, if needed, and performs | |
| 1130 | * shallow clones with @c memcpy(). | |
| 1131 | * | |
| 1132 | * This function is optimized for the case when both the @p src and the | |
| 1133 | * @p other list are sorted. | |
| 1134 | * In that case, the union will also be sorted. | |
| 1135 | * | |
| 1136 | * If the destination list already contains elements, the union is appended | |
| 1137 | * to that list. In that case the destination is not necessarily sorted. | |
| 1138 | * | |
| 1139 | * @param dst the destination list | |
| 1140 | * @param src the primary source list | |
| 1141 | * @param other the other list, where elements are only cloned from | |
| 1142 | * when they are not in @p src | |
| 1143 | * @retval zero when the elements were successfully cloned | |
| 1144 | * @retval non-zero when an allocation error occurred | |
| 1145 | * @see cxListUnion() | |
| 1146 | */ | |
| 1147 | cx_attr_nonnull | |
| 1148 | CX_EXPORT int cxListUnionSimple(CxList *dst, const CxList *src, const CxList *other); | |
| 504 | 1149 | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1150 | #ifdef __cplusplus |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
1151 | } // extern "C" |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1152 | #endif |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1153 | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
1154 | #endif // UCX_LIST_H |