Tue, 21 Oct 2025 16:20:51 +0200
update ucx
| 174 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | /** | |
| 440 | 29 | * @file list.h |
| 30 | * @brief Interface for list implementations. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
| 174 | 34 | */ |
| 35 | ||
| 36 | #ifndef UCX_LIST_H | |
| 37 | #define UCX_LIST_H | |
| 38 | ||
| 39 | #include "common.h" | |
| 40 | #include "collection.h" | |
| 41 | ||
| 42 | #ifdef __cplusplus | |
| 43 | extern "C" { | |
| 44 | #endif | |
| 45 | ||
| 46 | /** | |
| 47 | * List class type. | |
| 48 | */ | |
| 49 | typedef struct cx_list_class_s cx_list_class; | |
| 50 | ||
| 51 | /** | |
| 52 | * Structure for holding the base data of a list. | |
| 53 | */ | |
| 54 | struct cx_list_s { | |
| 440 | 55 | /** |
| 56 | * Common members for collections. | |
| 57 | */ | |
| 324 | 58 | CX_COLLECTION_BASE; |
| 174 | 59 | /** |
| 60 | * The list class definition. | |
| 61 | */ | |
| 324 | 62 | const cx_list_class *cl; |
| 174 | 63 | /** |
| 64 | * The actual implementation in case the list class is delegating. | |
| 65 | */ | |
| 324 | 66 | const cx_list_class *climpl; |
| 174 | 67 | }; |
| 68 | ||
| 69 | /** | |
| 70 | * The class definition for arbitrary lists. | |
| 71 | */ | |
| 72 | struct cx_list_class_s { | |
| 73 | /** | |
| 74 | * Destructor function. | |
| 75 | * | |
| 76 | * Implementations SHALL invoke the content destructor functions if provided | |
| 440 | 77 | * and SHALL deallocate the entire list memory. |
| 174 | 78 | */ |
| 440 | 79 | void (*deallocate)(struct cx_list_s *list); |
| 174 | 80 | |
| 81 | /** | |
|
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
82 | * Member function for inserting a single element. |
| 845 | 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. | |
| 174 | 85 | */ |
| 870 | 86 | void *(*insert_element)(struct cx_list_s *list, size_t index, const void *data); |
| 174 | 87 | |
| 88 | /** | |
| 89 | * Member function for inserting multiple elements. | |
| 440 | 90 | * |
| 870 | 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 | * | |
| 324 | 94 | * @see cx_list_default_insert_array() |
| 174 | 95 | */ |
| 870 | 96 | size_t (*insert_array)(struct cx_list_s *list, size_t index, const void *data, size_t n); |
| 324 | 97 | |
| 98 | /** | |
| 99 | * Member function for inserting sorted elements into a sorted list. | |
| 870 | 100 | * Returns the number of successfully inserted elements. |
| 324 | 101 | * |
| 102 | * @see cx_list_default_insert_sorted() | |
| 103 | */ | |
| 870 | 104 | size_t (*insert_sorted)(struct cx_list_s *list, const void *sorted_data, size_t n); |
| 174 | 105 | |
| 106 | /** | |
| 845 | 107 | * Member function for inserting multiple elements if they do not exist. |
| 870 | 108 | * Implementations shall return the number of successfully processed elements |
| 109 | * (including those which were not added because they are already contained). | |
| 845 | 110 | * @see cx_list_default_insert_unique() |
| 111 | */ | |
| 870 | 112 | size_t (*insert_unique)(struct cx_list_s *list, const void *sorted_data, size_t n); |
| 845 | 113 | |
| 114 | /** | |
| 174 | 115 | * Member function for inserting an element relative to an iterator position. |
| 116 | */ | |
| 870 | 117 | int (*insert_iter)(struct cx_iterator_s *iter, const void *elem, int prepend); |
| 174 | 118 | |
| 119 | /** | |
| 440 | 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. | |
| 174 | 128 | */ |
| 870 | 129 | size_t (*remove)(struct cx_list_s *list, size_t index, size_t num, void *targetbuf); |
| 174 | 130 | |
| 131 | /** | |
| 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. | |
| 440 | 138 | * |
| 324 | 139 | * @see cx_list_default_swap() |
| 174 | 140 | */ |
| 870 | 141 | int (*swap)(struct cx_list_s *list, size_t i, size_t j); |
| 174 | 142 | |
| 143 | /** | |
| 144 | * Member function for element lookup. | |
| 145 | */ | |
| 870 | 146 | void *(*at)(const struct cx_list_s *list, size_t index); |
| 174 | 147 | |
| 148 | /** | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
149 | * Member function for finding and optionally removing an element. |
| 174 | 150 | */ |
| 870 | 151 | size_t (*find_remove)(struct cx_list_s *list, const void *elem, bool remove); |
| 174 | 152 | |
| 153 | /** | |
| 440 | 154 | * Member function for sorting the list. |
| 155 | * | |
| 324 | 156 | * @see cx_list_default_sort() |
| 174 | 157 | */ |
| 158 | void (*sort)(struct cx_list_s *list); | |
| 159 | ||
| 160 | /** | |
| 324 | 161 | * Optional member function for comparing this list |
| 162 | * to another list of the same type. | |
| 845 | 163 | * If set to @c NULL, the comparison won't be optimized. |
| 174 | 164 | */ |
| 870 | 165 | int (*compare)(const struct cx_list_s *list, const struct cx_list_s *other); |
| 174 | 166 | |
| 167 | /** | |
| 168 | * Member function for reversing the order of the items. | |
| 169 | */ | |
| 170 | void (*reverse)(struct cx_list_s *list); | |
| 171 | ||
| 172 | /** | |
| 173 | * Member function for returning an iterator pointing to the specified index. | |
| 174 | */ | |
| 870 | 175 | struct cx_iterator_s (*iterator)(const struct cx_list_s *list, size_t index, bool backward); |
| 174 | 176 | }; |
| 177 | ||
| 178 | /** | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
179 | * Common type for all list implementations. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
180 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
181 | typedef struct cx_list_s CxList; |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
182 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
183 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
184 | * A shared instance of an empty list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
185 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
186 | * Writing to that list is not allowed. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
187 | * |
| 845 | 188 | * You can use this as a placeholder for initializing CxList pointers |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
189 | * for which you do not want to reserve memory right from the beginning. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
190 | */ |
| 870 | 191 | CX_EXPORT extern CxList *const cxEmptyList; |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
192 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
193 | /** |
| 324 | 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 | */ | |
| 440 | 207 | cx_attr_nonnull |
| 870 | 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); | |
| 324 | 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 | * | |
| 440 | 217 | * The source data @em must already be sorted wrt. the list's compare function. |
| 324 | 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 | */ | |
| 440 | 227 | cx_attr_nonnull |
| 870 | 228 | CX_EXPORT size_t cx_list_default_insert_sorted(struct cx_list_s *list, |
| 229 | const void *sorted_data, size_t n); | |
| 324 | 230 | |
| 231 | /** | |
| 845 | 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 | |
| 870 | 248 | CX_EXPORT size_t cx_list_default_insert_unique(struct cx_list_s *list, |
| 249 | const void *sorted_data, size_t n); | |
| 845 | 250 | |
| 251 | /** | |
| 324 | 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 | */ | |
| 440 | 262 | cx_attr_nonnull |
| 870 | 263 | CX_EXPORT void cx_list_default_sort(struct cx_list_s *list); |
| 324 | 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 | |
| 440 | 274 | * @retval zero success |
| 275 | * @retval non-zero when indices are out of bounds or memory | |
| 324 | 276 | * allocation for the temporary buffer fails |
| 277 | */ | |
| 440 | 278 | cx_attr_nonnull |
| 870 | 279 | CX_EXPORT int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j); |
| 324 | 280 | |
| 281 | /** | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
282 | * Initializes a list struct. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
283 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
284 | * Only use this function if you are creating your own list implementation. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
285 | * The purpose of this function is to be called in the initialization code |
| 845 | 286 | * of your list to set certain members correctly. |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
287 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
288 | * This is particularly important when you want your list to support |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
289 | * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
290 | * class accordingly and make sure that you can implement your list as if |
| 845 | 291 | * it was only storing objects, and the wrapper will automatically enable |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
292 | * the feature of storing pointers. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
293 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
294 | * @par Example |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
295 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
296 | * @code |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
297 | * CxList *myCustomListCreate( |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
298 | * const CxAllocator *allocator, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
299 | * cx_compare_func comparator, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
300 | * size_t elem_size |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
301 | * ) { |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
302 | * if (allocator == NULL) { |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
303 | * allocator = cxDefaultAllocator; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
304 | * } |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
305 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
306 | * MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList)); |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
307 | * if (list == NULL) return NULL; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
308 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
309 | * // initialize |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
310 | * cx_list_init((CxList*)list, &my_custom_list_class, |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
311 | * allocator, comparator, elem_size); |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
312 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
313 | * // ... some more custom stuff ... |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
314 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
315 | * return (CxList *) list; |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
316 | * } |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
317 | * @endcode |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
318 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
319 | * @param list the list to initialize |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
320 | * @param cl the list class |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
321 | * @param allocator the allocator for the elements |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
322 | * @param comparator a compare function for the elements |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
323 | * @param elem_size the size of one element |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
324 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
325 | cx_attr_nonnull_arg(1, 2, 3) |
| 870 | 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); | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
329 | |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
330 | /** |
| 174 | 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 | */ | |
| 440 | 336 | cx_attr_nonnull |
| 870 | 337 | CX_EXPORT size_t cxListSize(const CxList *list); |
| 174 | 338 | |
| 339 | /** | |
| 340 | * Adds an item to the end of the list. | |
| 341 | * | |
| 342 | * @param list the list | |
| 343 | * @param elem a pointer to the element to add | |
| 440 | 344 | * @retval zero success |
| 345 | * @retval non-zero memory allocation failure | |
| 174 | 346 | * @see cxListAddArray() |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
347 | * @see cxListEmplace() |
| 174 | 348 | */ |
| 440 | 349 | cx_attr_nonnull |
| 870 | 350 | CX_EXPORT int cxListAdd(CxList *list, const void *elem); |
| 174 | 351 | |
| 352 | /** | |
| 353 | * Adds multiple items to the end of the list. | |
| 354 | * | |
| 355 | * This method is more efficient than invoking cxListAdd() multiple times. | |
| 356 | * | |
| 357 | * If there is not enough memory to add all elements, the returned value is | |
| 440 | 358 | * less than @p n. |
| 174 | 359 | * |
| 845 | 360 | * If this list is storing pointers instead of objects, @p array is expected to |
| 174 | 361 | * be an array of pointers. |
| 362 | * | |
| 363 | * @param list the list | |
| 364 | * @param array a pointer to the elements to add | |
| 365 | * @param n the number of elements to add | |
| 366 | * @return the number of added elements | |
| 870 | 367 | * @see cxListEmplaceArray() |
| 174 | 368 | */ |
| 440 | 369 | cx_attr_nonnull |
| 870 | 370 | CX_EXPORT size_t cxListAddArray(CxList *list, const void *array, size_t n); |
| 174 | 371 | |
| 372 | /** | |
| 373 | * Inserts an item at the specified index. | |
| 374 | * | |
| 845 | 375 | * If the @p index equals the list @c size, this is effectively cxListAdd(). |
| 174 | 376 | * |
| 377 | * @param list the list | |
| 378 | * @param index the index the element shall have | |
| 379 | * @param elem a pointer to the element to add | |
| 440 | 380 | * @retval zero success |
| 381 | * @retval non-zero memory allocation failure or the index is out of bounds | |
| 174 | 382 | * @see cxListInsertAfter() |
| 383 | * @see cxListInsertBefore() | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
384 | * @see cxListEmplaceAt() |
| 174 | 385 | */ |
| 440 | 386 | cx_attr_nonnull |
| 870 | 387 | CX_EXPORT int cxListInsert(CxList *list, size_t index, const void *elem); |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
388 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
389 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
390 | * Allocates memory for an element at the specified index and returns a pointer to that memory. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
391 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
392 | * @remark When the list is storing pointers, this will return a @c void**. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
393 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
394 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
395 | * @param index the index where to emplace the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
396 | * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
397 | * @see cxListEmplace() |
| 870 | 398 | * @see cxListEmplaceArrayAt() |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
399 | * @see cxListInsert() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
400 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
401 | cx_attr_nonnull |
| 870 | 402 | CX_EXPORT void *cxListEmplaceAt(CxList *list, size_t index); |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
403 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
404 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
405 | * Allocates memory for an element at the end of the list and returns a pointer to that memory. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
406 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
407 | * @remark When the list is storing pointers, this will return a @c void**. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
408 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
409 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
410 | * @return a pointer to the allocated memory; @c NULL when the operation fails, or the index is out-of-bounds |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
411 | * @see cxListEmplaceAt() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
412 | * @see cxListAdd() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
413 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
414 | cx_attr_nonnull |
| 870 | 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); | |
| 174 | 455 | |
| 456 | /** | |
| 324 | 457 | * Inserts an item into a sorted list. |
| 458 | * | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
459 | * If the list is not sorted already, the behavior is undefined. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
460 | * |
| 324 | 461 | * @param list the list |
| 462 | * @param elem a pointer to the element to add | |
| 440 | 463 | * @retval zero success |
| 464 | * @retval non-zero memory allocation failure | |
| 324 | 465 | */ |
| 440 | 466 | cx_attr_nonnull |
| 870 | 467 | CX_EXPORT int cxListInsertSorted(CxList *list, const void *elem); |
| 324 | 468 | |
| 469 | /** | |
| 870 | 470 | * Inserts an item into a list if it does not exist. |
| 845 | 471 | * |
| 870 | 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. | |
| 845 | 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 | |
| 870 | 483 | CX_EXPORT int cxListInsertUnique(CxList *list, const void *elem); |
| 845 | 484 | |
| 485 | /** | |
| 174 | 486 | * Inserts multiple items to the list at the specified index. |
| 845 | 487 | * If the @p index equals the list size, this is effectively cxListAddArray(). |
| 174 | 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 | |
| 440 | 493 | * less than @p n. |
| 174 | 494 | * |
| 845 | 495 | * If this list is storing pointers instead of objects, @p array is expected to |
| 174 | 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 | |
| 870 | 503 | * @see cxListEmplaceArrayAt() |
| 174 | 504 | */ |
| 440 | 505 | cx_attr_nonnull |
| 870 | 506 | CX_EXPORT size_t cxListInsertArray(CxList *list, size_t index, const void *array, size_t n); |
| 174 | 507 | |
| 508 | /** | |
| 324 | 509 | * Inserts a sorted array into a sorted list. |
| 510 | * | |
| 845 | 511 | * This method is usually more efficient than inserting each element separately |
| 324 | 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 | |
| 440 | 515 | * less than @p n. |
| 324 | 516 | * |
| 845 | 517 | * If this list is storing pointers instead of objects, @p array is expected to |
| 324 | 518 | * be an array of pointers. |
| 519 | * | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
520 | * If the list is not sorted already, the behavior is undefined. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
521 | * |
| 324 | 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 | */ | |
| 440 | 527 | cx_attr_nonnull |
| 870 | 528 | CX_EXPORT size_t cxListInsertSortedArray(CxList *list, const void *array, size_t n); |
| 324 | 529 | |
| 530 | /** | |
| 870 | 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. | |
| 845 | 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 | |
| 870 | 563 | CX_EXPORT size_t cxListInsertUniqueArray(CxList *list, const void *array, size_t n); |
| 845 | 564 | |
| 565 | /** | |
| 174 | 566 | * Inserts an element after the current location of the specified iterator. |
| 567 | * | |
| 568 | * The used iterator remains operational, but all other active iterators should | |
| 569 | * be considered invalidated. | |
| 570 | * | |
| 440 | 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. | |
| 174 | 573 | * |
| 574 | * @param iter an iterator | |
| 575 | * @param elem the element to insert | |
| 440 | 576 | * @retval zero success |
| 577 | * @retval non-zero memory allocation failure | |
| 174 | 578 | * @see cxListInsert() |
| 579 | * @see cxListInsertBefore() | |
| 580 | */ | |
| 440 | 581 | cx_attr_nonnull |
| 870 | 582 | CX_EXPORT int cxListInsertAfter(CxIterator *iter, const void *elem); |
| 174 | 583 | |
| 584 | /** | |
| 585 | * Inserts an element before the current location of the specified iterator. | |
| 586 | * | |
| 587 | * The used iterator remains operational, but all other active iterators should | |
| 588 | * be considered invalidated. | |
| 589 | * | |
| 440 | 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. | |
| 174 | 592 | * |
| 593 | * @param iter an iterator | |
| 594 | * @param elem the element to insert | |
| 440 | 595 | * @retval zero success |
| 596 | * @retval non-zero memory allocation failure | |
| 174 | 597 | * @see cxListInsert() |
| 598 | * @see cxListInsertAfter() | |
| 599 | */ | |
| 440 | 600 | cx_attr_nonnull |
| 870 | 601 | CX_EXPORT int cxListInsertBefore(CxIterator *iter, const void *elem); |
| 174 | 602 | |
| 603 | /** | |
| 604 | * Removes the element at the specified index. | |
| 605 | * | |
| 606 | * If an element destructor function is specified, it is called before | |
| 607 | * removing the element. | |
| 608 | * | |
| 609 | * @param list the list | |
| 610 | * @param index the index of the element | |
| 440 | 611 | * @retval zero success |
| 612 | * @retval non-zero index out of bounds | |
| 174 | 613 | */ |
| 440 | 614 | cx_attr_nonnull |
| 870 | 615 | CX_EXPORT int cxListRemove(CxList *list, size_t index); |
| 440 | 616 | |
| 617 | /** | |
| 618 | * Removes and returns the element at the specified index. | |
| 619 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
620 | * No destructor is called, and instead the element is copied to the |
| 440 | 621 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
622 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
| 440 | 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 | */ | |
| 870 | 630 | cx_attr_nonnull cx_attr_access_w(3) |
| 631 | CX_EXPORT int cxListRemoveAndGet(CxList *list, size_t index, void *targetbuf); | |
| 440 | 632 | |
| 633 | /** | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
634 | * Removes and returns the first element of the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
635 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
636 | * No destructor is called, and instead the element is copied to the |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
637 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
638 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
639 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
640 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
641 | * @param targetbuf a buffer where to copy the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
642 | * @retval zero success |
| 845 | 643 | * @retval non-zero the list is empty |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
644 | * @see cxListPopFront() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
645 | * @see cxListRemoveAndGetLast() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
646 | */ |
| 870 | 647 | cx_attr_nonnull cx_attr_access_w(2) |
| 648 | CX_EXPORT int cxListRemoveAndGetFirst(CxList *list, void *targetbuf); | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
649 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
650 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
651 | * Removes and returns the first element of the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
652 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
653 | * Alias for cxListRemoveAndGetFirst(). |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
654 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
655 | * No destructor is called, and instead the element is copied to the |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
656 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
657 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
658 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
659 | * @param list (@c CxList*) the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
660 | * @param targetbuf (@c void*) a buffer where to copy the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
661 | * @retval zero success |
| 845 | 662 | * @retval non-zero the list is empty |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
663 | * @see cxListRemoveAndGetFirst() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
664 | * @see cxListPop() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
665 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
666 | #define cxListPopFront(list, targetbuf) cxListRemoveAndGetFirst((list), (targetbuf)) |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
667 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
668 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
669 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
670 | * Removes and returns the last element of the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
671 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
672 | * No destructor is called, and instead the element is copied to the |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
673 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
674 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
675 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
676 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
677 | * @param targetbuf a buffer where to copy the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
678 | * @retval zero success |
| 845 | 679 | * @retval non-zero the list is empty |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
680 | */ |
| 870 | 681 | cx_attr_nonnull cx_attr_access_w(2) |
| 682 | CX_EXPORT int cxListRemoveAndGetLast(CxList *list, void *targetbuf); | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
683 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
684 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
685 | * Removes and returns the last element of the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
686 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
687 | * Alias for cxListRemoveAndGetLast(). |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
688 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
689 | * No destructor is called, and instead the element is copied to the |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
690 | * @p targetbuf which MUST be large enough to hold the removed element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
691 | * If the list is storing pointers, only the pointer is copied to @p targetbuf. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
692 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
693 | * @param list (@c CxList*) the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
694 | * @param targetbuf (@c void*) a buffer where to copy the element |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
695 | * @retval zero success |
| 845 | 696 | * @retval non-zero the list is empty |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
697 | * @see cxListRemoveAndGetLast() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
698 | * @see cxListPopFront() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
699 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
700 | #define cxListPop(list, targetbuf) cxListRemoveAndGetLast((list), (targetbuf)) |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
701 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
702 | /** |
| 440 | 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 | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
707 | * the element. However, due to possible optimizations, it is neither guaranteed |
| 440 | 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 | |
| 870 | 718 | CX_EXPORT size_t cxListRemoveArray(CxList *list, size_t index, size_t num); |
| 440 | 719 | |
| 720 | /** | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
721 | * Removes and returns multiple elements starting at the specified index. |
| 440 | 722 | * |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
723 | * No destructor is called, and instead the elements are copied to the |
| 440 | 724 | * @p targetbuf which MUST be large enough to hold all removed elements. |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
725 | * If the list is storing pointers, @p targetbuf is expected to be an array of pointers. |
| 440 | 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 | */ | |
| 870 | 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); | |
| 174 | 735 | |
| 736 | /** | |
| 737 | * Removes all elements from this list. | |
| 738 | * | |
| 440 | 739 | * If element destructor functions are specified, they are called for each |
| 174 | 740 | * element before removing them. |
| 741 | * | |
| 742 | * @param list the list | |
| 743 | */ | |
| 440 | 744 | cx_attr_nonnull |
| 870 | 745 | CX_EXPORT void cxListClear(CxList *list); |
| 174 | 746 | |
| 747 | /** | |
| 748 | * Swaps two items in the list. | |
| 749 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
750 | * Implementations should only allocate temporary memory for the swap if |
| 174 | 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 | |
| 440 | 756 | * @retval zero success |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
757 | * @retval non-zero one of the indices is out of bounds, |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
758 | * or the swap needed extra memory, but allocation failed |
| 174 | 759 | */ |
| 440 | 760 | cx_attr_nonnull |
| 870 | 761 | CX_EXPORT int cxListSwap(CxList *list, size_t i, size_t j); |
| 174 | 762 | |
| 763 | /** | |
| 764 | * Returns a pointer to the element at the specified index. | |
| 765 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
766 | * If the list is storing pointers, returns the pointer stored at the specified index. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
767 | * |
| 174 | 768 | * @param list the list |
| 769 | * @param index the index of the element | |
| 440 | 770 | * @return a pointer to the element or @c NULL if the index is out of bounds |
| 174 | 771 | */ |
| 440 | 772 | cx_attr_nonnull |
| 870 | 773 | CX_EXPORT void *cxListAt(const CxList *list, size_t index); |
| 174 | 774 | |
| 775 | /** | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
776 | * Returns a pointer to the first element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
777 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
778 | * If the list is storing pointers, returns the first pointer stored in the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
779 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
780 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
781 | * @return a pointer to the first element or @c NULL if the list is empty |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
782 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
783 | cx_attr_nonnull |
| 870 | 784 | CX_EXPORT void *cxListFirst(const CxList *list); |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
785 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
786 | /** |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
787 | * Returns a pointer to the last element. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
788 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
789 | * If the list is storing pointers, returns the last pointer stored in the list. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
790 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
791 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
792 | * @return a pointer to the last element or @c NULL if the list is empty |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
793 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
794 | cx_attr_nonnull |
| 870 | 795 | CX_EXPORT void *cxListLast(const CxList *list); |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
796 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
797 | /** |
| 870 | 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. | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
802 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
803 | * @param list the list to set the element in |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
804 | * @param index the index to set the element at |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
805 | * @param elem element to set |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
806 | * @retval zero on success |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
807 | * @retval non-zero when index is out of bounds |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
808 | */ |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
809 | cx_attr_nonnull |
| 870 | 810 | CX_EXPORT int cxListSet(CxList *list, size_t index, const void *elem); |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
811 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
812 | /** |
| 174 | 813 | * Returns an iterator pointing to the item at the specified index. |
| 814 | * | |
| 815 | * The returned iterator is position-aware. | |
| 816 | * | |
| 845 | 817 | * If the index is out of range or @p list is @c NULL, a past-the-end iterator will be returned. |
| 174 | 818 | * |
| 819 | * @param list the list | |
| 820 | * @param index the index where the iterator shall point at | |
| 821 | * @return a new iterator | |
| 822 | */ | |
| 440 | 823 | cx_attr_nodiscard |
| 870 | 824 | CX_EXPORT CxIterator cxListIteratorAt(const CxList *list, size_t index); |
| 174 | 825 | |
| 826 | /** | |
| 827 | * Returns a backwards iterator pointing to the item at the specified index. | |
| 828 | * | |
| 829 | * The returned iterator is position-aware. | |
| 830 | * | |
| 845 | 831 | * If the index is out of range or @p list is @c NULL, a past-the-end iterator will be returned. |
| 174 | 832 | * |
| 833 | * @param list the list | |
| 834 | * @param index the index where the iterator shall point at | |
| 835 | * @return a new iterator | |
| 836 | */ | |
| 440 | 837 | cx_attr_nodiscard |
| 870 | 838 | CX_EXPORT CxIterator cxListBackwardsIteratorAt(const CxList *list, size_t index); |
| 174 | 839 | |
| 840 | /** | |
| 841 | * Returns an iterator pointing to the first item of the list. | |
| 842 | * | |
| 843 | * The returned iterator is position-aware. | |
| 844 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
845 | * If the list is empty or @c NULL, a past-the-end iterator will be returned. |
| 174 | 846 | * |
| 847 | * @param list the list | |
| 848 | * @return a new iterator | |
| 849 | */ | |
| 440 | 850 | cx_attr_nodiscard |
| 870 | 851 | CX_EXPORT CxIterator cxListIterator(const CxList *list); |
| 174 | 852 | |
| 853 | /** | |
| 854 | * Returns a backwards iterator pointing to the last item of the list. | |
| 855 | * | |
| 856 | * The returned iterator is position-aware. | |
| 857 | * | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
858 | * If the list is empty or @c NULL, a past-the-end iterator will be returned. |
| 174 | 859 | * |
| 860 | * @param list the list | |
| 861 | * @return a new iterator | |
| 862 | */ | |
| 440 | 863 | cx_attr_nodiscard |
| 870 | 864 | CX_EXPORT CxIterator cxListBackwardsIterator(const CxList *list); |
| 174 | 865 | |
| 866 | /** | |
| 440 | 867 | * Returns the index of the first element that equals @p elem. |
| 174 | 868 | * |
| 869 | * Determining equality is performed by the list's comparator function. | |
| 870 | * | |
| 871 | * @param list the list | |
| 872 | * @param elem the element to find | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
873 | * @return the index of the element or the size of the list when the element is not found |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
874 | * @see cxListIndexValid() |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
875 | * @see cxListContains() |
| 174 | 876 | */ |
| 870 | 877 | cx_attr_nonnull cx_attr_nodiscard |
| 878 | CX_EXPORT size_t cxListFind(const CxList *list, const void *elem); | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
879 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
880 | /** |
| 845 | 881 | * Checks if the list contains the specified element. |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
882 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
883 | * The elements are compared with the list's comparator function. |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
884 | * |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
885 | * @param list the list |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
886 | * @param elem the element to find |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
887 | * @retval true if the element is contained |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
888 | * @retval false if the element is not contained |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
889 | * @see cxListFind() |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
890 | */ |
| 870 | 891 | cx_attr_nonnull cx_attr_nodiscard |
| 892 | CX_EXPORT bool cxListContains(const CxList* list, const void* elem); | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
893 | |
|
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
894 | /** |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
895 | * Checks if the specified index is within bounds. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
896 | * |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
897 | * @param list the list |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
898 | * @param index the index |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
899 | * @retval true if the index is within bounds |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
900 | * @retval false if the index is out of bounds |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
901 | */ |
| 870 | 902 | cx_attr_nonnull cx_attr_nodiscard |
| 903 | CX_EXPORT bool cxListIndexValid(const CxList *list, size_t index); | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
904 | |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
905 | /** |
| 440 | 906 | * Removes and returns the index of the first element that equals @p elem. |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
907 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
908 | * Determining equality is performed by the list's comparator function. |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
909 | * |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
910 | * @param list the list |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
911 | * @param elem the element to find and remove |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
912 | * @return the index of the now removed element or the list size |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
913 | * when the element is not found or could not be removed |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
914 | * @see cxListIndexValid() |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
915 | */ |
| 440 | 916 | cx_attr_nonnull |
| 870 | 917 | CX_EXPORT size_t cxListFindRemove(CxList *list, const void *elem); |
| 174 | 918 | |
| 919 | /** | |
| 440 | 920 | * Sorts the list. |
| 174 | 921 | * |
| 440 | 922 | * @remark The underlying sort algorithm is implementation defined. |
| 174 | 923 | * |
| 924 | * @param list the list | |
| 925 | */ | |
| 440 | 926 | cx_attr_nonnull |
| 870 | 927 | CX_EXPORT void cxListSort(CxList *list); |
| 174 | 928 | |
| 929 | /** | |
| 930 | * Reverses the order of the items. | |
| 931 | * | |
| 932 | * @param list the list | |
| 933 | */ | |
| 440 | 934 | cx_attr_nonnull |
| 870 | 935 | CX_EXPORT void cxListReverse(CxList *list); |
| 174 | 936 | |
| 937 | /** | |
| 938 | * Compares a list to another list of the same type. | |
| 939 | * | |
| 940 | * First, the list sizes are compared. | |
| 941 | * If they match, the lists are compared element-wise. | |
| 942 | * | |
| 943 | * @param list the list | |
| 944 | * @param other the list to compare to | |
| 440 | 945 | * @retval zero both lists are equal element wise |
| 870 | 946 | * @retval negative the first list is smaller, |
| 440 | 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 | |
| 174 | 950 | */ |
| 870 | 951 | cx_attr_nonnull cx_attr_nodiscard |
| 952 | CX_EXPORT int cxListCompare(const CxList *list, const CxList *other); | |
| 174 | 953 | |
| 954 | /** | |
| 955 | * Deallocates the memory of the specified list structure. | |
| 956 | * | |
| 440 | 957 | * Also calls the content destructor functions for each element, if specified. |
| 174 | 958 | * |
| 845 | 959 | * @param list the list that shall be freed |
| 174 | 960 | */ |
| 870 | 961 | CX_EXPORT void cxListFree(CxList *list); |
| 174 | 962 | |
| 963 | ||
| 964 | #ifdef __cplusplus | |
| 965 | } // extern "C" | |
| 966 | #endif | |
| 967 | ||
| 968 | #endif // UCX_LIST_H |