Wed, 31 Dec 2025 16:40:12 +0100
update ucx to version 4.0
| 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 array_list.h |
| 30 | * @brief Array list implementation. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
| 174 | 34 | */ |
| 35 | ||
| 36 | ||
| 37 | #ifndef UCX_ARRAY_LIST_H | |
| 38 | #define UCX_ARRAY_LIST_H | |
| 39 | ||
| 40 | #include "list.h" | |
| 41 | ||
| 42 | /** | |
| 845 | 43 | * The maximum item size in an array list that fits into |
| 44 | * a stack buffer when swapped. | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
45 | */ |
| 870 | 46 | CX_EXPORT extern const unsigned cx_array_swap_sbo_size; |
| 440 | 47 | |
| 48 | /** | |
| 1016 | 49 | * Declares a typed array with size and capacity. |
| 440 | 50 | * |
| 1016 | 51 | * @param type the type of the elements |
| 440 | 52 | * @param name the name of the array |
| 1016 | 53 | */ |
| 54 | #define CX_ARRAY(type, name) \ | |
| 55 | struct { \ | |
| 56 | type *data; \ | |
| 57 | size_t size; \ | |
| 58 | size_t capacity; \ | |
| 59 | } name | |
| 60 | ||
| 61 | /** | |
| 62 | * Internal structure for arrays. | |
| 440 | 63 | * |
| 1016 | 64 | * A generalization of array structures declared with CX_ARRAY(). |
| 440 | 65 | */ |
| 1016 | 66 | typedef struct cx_array_s { |
| 67 | /** The array data. */ | |
| 68 | void *data; | |
| 69 | /** The number of elements. */ | |
| 70 | size_t size; | |
| 71 | /** The maximum number of elements. */ | |
| 72 | size_t capacity; | |
| 73 | } CxArray; | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
74 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
75 | /** |
| 1016 | 76 | * Initializes an array by allocating memory. |
| 440 | 77 | * |
| 1016 | 78 | * Internal function - do not use manually. |
| 440 | 79 | * |
| 1016 | 80 | * @param allocator the allocator for the array |
| 81 | * @param array a pointer to the array structure | |
| 82 | * @param elem_size size of one element | |
| 83 | * @param capacity the initial maximum number of elements | |
| 84 | * @retval zero allocation was successful | |
| 85 | * @retval non-zero allocation failed | |
| 324 | 86 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
87 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
88 | int cx_array_init_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity); |
| 324 | 89 | |
| 90 | /** | |
| 1016 | 91 | * Initializes an array by allocating memory. |
| 440 | 92 | * |
| 1016 | 93 | * The size is set to zero. |
| 94 | * | |
| 95 | * @attention If the array was already initialized, this will leak memory. | |
| 96 | * Use cx_array_reserve() to change the capacity of an initialized array. | |
| 440 | 97 | * |
| 1016 | 98 | * @param allocator (@c CxAllocator*) the allocator for the array |
| 99 | * @param array the name of the array | |
| 100 | * @param capacity (@c size_t) the initial maximum number of elements | |
| 101 | * @retval zero allocation was successful | |
| 102 | * @retval non-zero allocation failed | |
| 103 | */ | |
| 104 | #define cx_array_init_a(allocator, array, capacity) cx_array_init_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity) | |
| 105 | ||
| 106 | /** | |
| 107 | * Initializes an array by allocating memory. | |
| 440 | 108 | * |
| 1016 | 109 | * The size is set to zero. |
| 440 | 110 | * |
| 1016 | 111 | * @attention If the array was already initialized, this will leak memory. |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
112 | * |
| 440 | 113 | * @param array the name of the array |
| 1016 | 114 | * @param capacity (@c size_t) the initial maximum number of elements |
| 115 | * @retval zero allocation was successful | |
| 116 | * @retval non-zero allocation failed | |
| 324 | 117 | */ |
| 1016 | 118 | #define cx_array_init(array, capacity) cx_array_init_a(cxDefaultAllocator, array, capacity) |
| 324 | 119 | |
| 120 | /** | |
| 1016 | 121 | * Initializes an array with fixed size memory. |
| 122 | * | |
| 123 | * Internal function - do not use manually. | |
| 440 | 124 | * |
| 1016 | 125 | * @param array a pointer to the array structure |
| 126 | * @param data the fixed size array | |
| 127 | * @param capacity the capacity of the fixed size array | |
| 128 | * @param size the number of initialized elements in the fixed size array | |
| 129 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
130 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
131 | void cx_array_init_fixed_(CxArray *array, const void *data, size_t capacity, size_t size); |
| 1016 | 132 | |
| 133 | /** | |
| 134 | * Initializes an array with fixed size memory. | |
| 440 | 135 | * |
| 1016 | 136 | * This is useful, for example, when you want to work with memory on the stack |
| 137 | * and only want to move to the heap when the stack memory is not enough. | |
| 440 | 138 | * |
| 1016 | 139 | * With the @p num_initialized argument you can specify how many elements in the |
| 140 | * fixed size array are already correctly initialized, which determines the | |
| 141 | * initial size of the array. | |
| 142 | * | |
| 143 | * The capacity is determined automatically by the compiler. | |
| 144 | * | |
| 145 | * @attention When you add elements to an array that was initialized with fixed | |
| 146 | * size memory, you MUST check the capacity before adding the element and invoke | |
| 147 | * cx_array_copy_to_new() when you intend to exceed the capacity. | |
| 440 | 148 | * |
| 1016 | 149 | * @attention When you pass a pointer to an array that does not have a fixed |
| 150 | * size, the behavior is unspecified. | |
| 151 | * | |
| 152 | * @param array the name of the array to initialize | |
| 153 | * @param fixed_size_array (@c void*) the fixed size array | |
| 154 | * @param num_initialized (@c size_t) the number of already initialized elements in the fixed size array | |
| 155 | * @see cx_array_copy_to_new() | |
| 440 | 156 | */ |
| 1016 | 157 | #define cx_array_init_fixed(array, fixed_size_array, num_initialized) \ |
| 158 | cx_array_init_fixed_((CxArray*)&(array), fixed_size_array, cx_nmemb(fixed_size_array), num_initialized) | |
| 440 | 159 | |
| 160 | /** | |
| 1016 | 161 | * Changes the capacity of an array. |
| 162 | * | |
| 163 | * Internal function - do not use. | |
| 164 | * | |
| 165 | * @param allocator the allocator | |
| 166 | * @param array a pointer to the array structure | |
| 167 | * @param elem_size the size of one element | |
| 168 | * @param capacity the new capacity | |
| 169 | * @retval zero allocation was successful | |
| 170 | * @retval non-zero allocation failed | |
| 174 | 171 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
172 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
173 | int cx_array_reserve_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity); |
| 174 | 174 | |
| 175 | /** | |
| 1016 | 176 | * Changes the capacity of an array. |
| 177 | * | |
| 178 | * If required, the size is reduced to fit into the new capacity. | |
| 179 | * | |
| 180 | * @param allocator (@c CxAllocator*) the allocator for the array | |
| 181 | * @param array the name of the array | |
| 182 | * @param capacity (@c size_t) the new maximum number of elements | |
| 183 | * @retval zero allocation was successful | |
| 184 | * @retval non-zero allocation failed | |
| 440 | 185 | */ |
| 1016 | 186 | #define cx_array_reserve_a(allocator, array, capacity) \ |
| 187 | cx_array_reserve_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity) | |
| 440 | 188 | |
| 189 | /** | |
| 1016 | 190 | * Changes the capacity of an array. |
| 440 | 191 | * |
| 1016 | 192 | * If required, the size is reduced to fit into the new capacity. |
| 440 | 193 | * |
| 1016 | 194 | * @param array the name of the array |
| 195 | * @param capacity (@c size_t) the new maximum number of elements | |
| 196 | * @retval zero allocation was successful | |
| 197 | * @retval non-zero allocation failed | |
| 198 | */ | |
| 199 | #define cx_array_reserve(array, capacity) \ | |
| 200 | cx_array_reserve_a(cxDefaultAllocator, array, capacity) | |
| 201 | ||
| 202 | /** | |
| 203 | * Copies the array to a new memory region. | |
| 440 | 204 | * |
| 1016 | 205 | * Internal function - do not use. |
| 206 | * | |
| 207 | * @param allocator the allocator for new new memory | |
| 208 | * @param array a pointer to the array structure | |
| 209 | * @param elem_size the size of one element | |
| 210 | * @param capacity the new capacity | |
| 211 | * @retval zero allocation was successful | |
| 212 | * @retval non-zero allocation failed | |
| 440 | 213 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
214 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
215 | int cx_array_copy_to_new_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity); |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
216 | |
|
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
217 | /** |
| 1016 | 218 | * Copies the array to a new memory region. |
| 440 | 219 | * |
| 1016 | 220 | * This is useful when you have initialized the array with a fixed size memory |
| 221 | * using cx_array_init_fixed(), and now you want to increase the capacity. | |
| 440 | 222 | * |
| 1016 | 223 | * @attention When the original memory does not belong to stack memory, and |
| 224 | * you do not have another reference to this memory, it will leak. | |
| 440 | 225 | * |
| 1016 | 226 | * @param allocator (@c CxAllocator*) the allocator for the new memory |
| 227 | * @param array the name of the array | |
| 228 | * @param capacity (@c size_t) the new maximum number of elements | |
| 229 | * @retval zero allocation was successful | |
| 230 | * @retval non-zero allocation failed | |
| 231 | * @see cx_array_init_fixed() | |
| 232 | */ | |
| 233 | #define cx_array_copy_to_new_a(allocator, array, capacity) \ | |
| 234 | cx_array_copy_to_new_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity) | |
| 235 | ||
| 236 | /** | |
| 237 | * Copies the array to a new memory region. | |
|
943
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
238 | * |
| 1016 | 239 | * This is useful when you have initialized the array with a fixed size memory |
| 240 | * using cx_array_init_fixed(), and now you want to increase the capacity. | |
| 241 | * | |
| 242 | * @attention When the original memory does not belong to stack memory, and | |
| 243 | * you do not have another reference to this memory, it will leak. | |
| 244 | * | |
| 245 | * @param array the name of the array | |
| 246 | * @param capacity (@c size_t) the new maximum number of elements | |
| 247 | * @retval zero allocation was successful | |
| 248 | * @retval non-zero allocation failed | |
| 249 | * @see cx_array_init_fixed() | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
250 | */ |
| 1016 | 251 | #define cx_array_copy_to_new(array, capacity) \ |
| 252 | cx_array_copy_to_new_a(cxDefaultAllocator, array, capacity) | |
| 174 | 253 | |
| 254 | /** | |
| 1016 | 255 | * Inserts data into an array. |
| 174 | 256 | * |
| 1016 | 257 | * Internal function - do not use. |
|
943
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
258 | * |
| 1016 | 259 | * @param allocator the allocator to use for a possible reallocation |
| 260 | * @param array a pointer to the array structure | |
| 174 | 261 | * @param elem_size the size of one element |
| 1016 | 262 | * @param index the index where to insert the @p other data |
| 263 | * @param other a pointer to an array of data that shall be inserted | |
| 264 | * @param n the number of elements that shall be inserted | |
| 440 | 265 | * @retval zero success |
| 1016 | 266 | * @retval non-zero a re-allocation was necessary but failed |
| 174 | 267 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
268 | CX_EXTERN CX_NONNULL_ARG(1, 2) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
269 | int cx_array_insert_(const CxAllocator *allocator, CxArray *array, |
| 1016 | 270 | size_t elem_size, size_t index, const void *other, size_t n); |
| 324 | 271 | |
| 272 | /** | |
| 1016 | 273 | * Appends an element to an array. |
| 274 | * | |
| 275 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 324 | 276 | * |
| 1016 | 277 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 278 | * @param array the name of the array where the element shall be added | |
|
1034
330b415910bd
fix build (Win32)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
279 | * @param element the element that shall be added |
| 440 | 280 | * @retval zero success |
| 1016 | 281 | * @retval non-zero a re-allocation was necessary but failed |
| 440 | 282 | */ |
| 1016 | 283 | #define cx_array_add_a(allocator, array, element) \ |
|
1034
330b415910bd
fix build (Win32)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
284 | cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, (void*)&(element), 1) |
| 440 | 285 | |
| 286 | /** | |
| 1016 | 287 | * Appends an element to an array. |
| 288 | * | |
| 289 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 440 | 290 | * |
| 1016 | 291 | * @param array the name of the array where the element shall be added |
| 292 | * @param element (@c void*) a pointer to the element that shall be added | |
| 440 | 293 | * @retval zero success |
| 1016 | 294 | * @retval non-zero a re-allocation was necessary but failed |
| 324 | 295 | */ |
| 1016 | 296 | #define cx_array_add(array, element) \ |
| 297 | cx_array_add_a(cxDefaultAllocator, array, element) | |
| 440 | 298 | |
| 299 | /** | |
| 1016 | 300 | * Inserts an element into an array. |
| 301 | * | |
| 302 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 440 | 303 | * |
| 1016 | 304 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 305 | * @param array the name of the array where the element shall be inserted | |
| 306 | * @param index (@c size_t) the index where to insert the @p element | |
|
1034
330b415910bd
fix build (Win32)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
307 | * @param element the element that shall be inserted |
| 440 | 308 | * @retval zero success |
| 1016 | 309 | * @retval non-zero a re-allocation was necessary but failed |
| 440 | 310 | */ |
| 1016 | 311 | #define cx_array_insert_a(allocator, array, index, element) \ |
|
1034
330b415910bd
fix build (Win32)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
312 | cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, (void*)&(element), 1) |
| 440 | 313 | |
| 314 | /** | |
| 1016 | 315 | * Inserts an element into an array. |
| 316 | * | |
| 317 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 440 | 318 | * |
| 1016 | 319 | * @param array the name of the array where the element shall be inserted |
| 320 | * @param index (@c size_t) the index where to insert the @p element | |
| 321 | * @param element (@c void*) a pointer to the element that shall be inserted | |
| 440 | 322 | * @retval zero success |
| 1016 | 323 | * @retval non-zero a re-allocation was necessary but failed |
| 440 | 324 | */ |
| 1016 | 325 | #define cx_array_insert(array, index, element) \ |
| 326 | cx_array_insert_a(cxDefaultAllocator, array, index, element) | |
| 327 | ||
| 328 | /** | |
| 329 | * Inserts data into an array. | |
| 330 | * | |
| 331 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 332 | * | |
| 333 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation | |
| 334 | * @param array the name of the array where the elements shall be inserted | |
| 335 | * @param index (@c size_t) the index where to insert the @p other data | |
| 336 | * @param other (@c void*) a pointer to an array of data that shall be inserted | |
| 337 | * @param n (@c size_t) the number of elements that shall be inserted | |
| 338 | * @retval zero success | |
| 339 | * @retval non-zero a re-allocation was necessary but failed | |
| 340 | */ | |
| 341 | #define cx_array_insert_array_a(allocator, array, index, other, n) \ | |
| 342 | cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, other, n) | |
| 174 | 343 | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
344 | /** |
| 1016 | 345 | * Inserts data into an array. |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
346 | * |
| 1016 | 347 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. |
| 440 | 348 | * |
| 1016 | 349 | * @param array the name of the array where the elements shall be inserted |
| 350 | * @param index (@c size_t) the index where to insert the @p other data | |
| 351 | * @param other (@c void*) a pointer to an array of data that shall be inserted | |
| 352 | * @param n (@c size_t) the number of elements that shall be inserted | |
| 440 | 353 | * @retval zero success |
| 1016 | 354 | * @retval non-zero a re-allocation was necessary but failed |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
355 | */ |
| 1016 | 356 | #define cx_array_insert_array(array, index, other, n) \ |
| 357 | cx_array_insert_array_a(cxDefaultAllocator, array, index, other, n) | |
| 358 | ||
| 359 | /** | |
| 360 | * Appends data to an array. | |
| 361 | * | |
| 362 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 363 | * | |
| 364 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation | |
| 365 | * @param array the name of the array where the elements shall be added | |
| 366 | * @param other (@c void*) a pointer to an array of data that shall be added | |
| 367 | * @param n (@c size_t) the number of elements that shall be added | |
| 368 | * @retval zero success | |
| 369 | * @retval non-zero a re-allocation was necessary but failed | |
| 370 | */ | |
| 371 | #define cx_array_add_array_a(allocator, array, other, n) \ | |
| 372 | cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, other, n) | |
| 440 | 373 | |
| 374 | /** | |
| 1016 | 375 | * Appends data to an array. |
| 376 | * | |
| 377 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 440 | 378 | * |
| 1016 | 379 | * @param array the name of the array where the elements shall be added |
| 380 | * @param other (@c void*) a pointer to an array of data that shall be added | |
| 381 | * @param n (@c size_t) the number of elements that shall be added | |
| 440 | 382 | * @retval zero success |
| 1016 | 383 | * @retval non-zero a re-allocation was necessary but failed |
| 440 | 384 | */ |
| 1016 | 385 | #define cx_array_add_array(array, other, n) \ |
| 386 | cx_array_add_array_a(cxDefaultAllocator, array, other, n) | |
| 174 | 387 | |
| 388 | /** | |
| 1016 | 389 | * Inserts sorted data into a sorted array. |
| 324 | 390 | * |
| 1016 | 391 | * Internal function - do not use. |
| 324 | 392 | * |
| 1016 | 393 | * @param allocator the allocator to use for a possible reallocation |
| 394 | * @param array a pointer to the array structure | |
| 324 | 395 | * @param elem_size the size of one element |
| 1016 | 396 | * @param sorted_data a pointer to an array of data that shall be inserted |
| 397 | * @param n the number of elements that shall be inserted | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
398 | * @param cmp_func the compare function |
| 1016 | 399 | * @param allow_duplicates @c false if duplicates shall be skipped during insertion |
| 440 | 400 | * @retval zero success |
| 1016 | 401 | * @retval non-zero a re-allocation was necessary but failed |
| 324 | 402 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
403 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
404 | int cx_array_insert_sorted_(const CxAllocator *allocator, CxArray *array, |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
405 | size_t elem_size, const void *sorted_data, size_t n, |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
406 | cx_compare_func cmp_func, bool allow_duplicates); |
| 324 | 407 | |
| 408 | /** | |
| 409 | * Inserts an element into a sorted array. | |
| 410 | * | |
| 1016 | 411 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 324 | 412 | * |
| 1016 | 413 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 440 | 414 | * |
| 1016 | 415 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 416 | * @param array the name of the array where the elements shall be inserted | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
417 | * @param element the element that shall be inserted |
| 1016 | 418 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 440 | 419 | * @retval zero success |
| 1016 | 420 | * @retval non-zero a re-allocation was necessary but failed |
| 324 | 421 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
422 | #define cx_array_insert_sorted_a(allocator, array, element, cmp_func) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
423 | cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, true) |
| 324 | 424 | |
| 425 | /** | |
| 1016 | 426 | * Inserts an element into a sorted array. |
| 427 | * | |
| 428 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 440 | 429 | * |
| 1016 | 430 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 431 | * | |
| 432 | * @param array the name of the array where the elements shall be inserted | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
433 | * @param element the element that shall be inserted |
| 1016 | 434 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 440 | 435 | * @retval zero success |
| 1016 | 436 | * @retval non-zero a re-allocation was necessary but failed |
| 440 | 437 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
438 | #define cx_array_insert_sorted(array, element, cmp_func) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
439 | cx_array_insert_sorted_a(cxDefaultAllocator, array, element, cmp_func) |
| 1016 | 440 | |
| 441 | /** | |
| 442 | * Inserts sorted data into a sorted array. | |
| 443 | * | |
| 444 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 445 | * | |
| 446 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 447 | * | |
| 448 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation | |
| 449 | * @param array the name of the array where the elements shall be inserted | |
| 450 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted | |
| 451 | * @param n (@c size_t) the number of elements that shall be inserted | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
452 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 1016 | 453 | * @retval zero success |
| 454 | * @retval non-zero a re-allocation was necessary but failed | |
| 455 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
456 | #define cx_array_insert_sorted_array_a(allocator, array, sorted_data, n, cmp_func) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
457 | cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, true) |
| 440 | 458 | |
| 459 | /** | |
| 1016 | 460 | * Inserts sorted data into a sorted array. |
| 461 | * | |
| 462 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 324 | 463 | * |
| 1016 | 464 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 465 | * | |
| 466 | * @param array the name of the array where the elements shall be inserted | |
| 467 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted | |
| 468 | * @param n (@c size_t) the number of elements that shall be inserted | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
469 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 440 | 470 | * @retval zero success |
| 1016 | 471 | * @retval non-zero a re-allocation was necessary but failed |
| 324 | 472 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
473 | #define cx_array_insert_sorted_array(array, sorted_data, n, cmp_func) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
474 | cx_array_insert_sorted_array_a(cxDefaultAllocator, array, sorted_data, n, cmp_func) |
| 440 | 475 | |
| 476 | /** | |
| 1016 | 477 | * Inserts an element into a sorted array if it is not already contained. |
| 478 | * | |
| 479 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 480 | * | |
| 481 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 440 | 482 | * |
| 1016 | 483 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 484 | * @param array the name of the array where the elements shall be inserted | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
485 | * @param element the element that shall be inserted |
| 1016 | 486 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 440 | 487 | * @retval zero success |
| 1016 | 488 | * @retval non-zero a re-allocation was necessary but failed |
| 440 | 489 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
490 | #define cx_array_insert_unique_a(allocator, array, element, cmp_func) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
491 | cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, false) |
| 324 | 492 | |
| 493 | /** | |
| 1016 | 494 | * Inserts an element into a sorted array if it is not already contained. |
| 495 | * | |
| 496 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 324 | 497 | * |
| 1016 | 498 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 499 | * | |
| 500 | * @param array the name of the array where the elements shall be inserted | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
501 | * @param element the element that shall be inserted |
| 1016 | 502 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 440 | 503 | * @retval zero success |
| 1016 | 504 | * @retval non-zero a re-allocation was necessary but failed |
| 324 | 505 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
506 | #define cx_array_insert_unique(array, element, cmp_func) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
507 | cx_array_insert_unique_a(cxDefaultAllocator, array, element, cmp_func) |
| 845 | 508 | |
| 509 | /** | |
| 1016 | 510 | * Inserts sorted data into a sorted array, skipping duplicates. |
| 845 | 511 | * |
| 1016 | 512 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. |
| 513 | * | |
| 514 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 845 | 515 | * |
| 1016 | 516 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
| 517 | * @param array the name of the array where the elements shall be inserted | |
| 518 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted | |
| 519 | * @param n (@c size_t) the number of elements that shall be inserted | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
520 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
| 845 | 521 | * @retval zero success |
| 1016 | 522 | * @retval non-zero a re-allocation was necessary but failed |
| 845 | 523 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
524 | #define cx_array_insert_unique_array_a(allocator, array, sorted_data, n, cmp_func) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
525 | cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, false) |
| 845 | 526 | |
| 527 | /** | |
| 1016 | 528 | * Inserts sorted data into a sorted array, skipping duplicates. |
| 845 | 529 | * |
| 1016 | 530 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. |
| 845 | 531 | * |
| 1016 | 532 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 845 | 533 | * |
| 1016 | 534 | * @param array the name of the array where the elements shall be inserted |
| 535 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted | |
| 536 | * @param n (@c size_t) the number of elements that shall be inserted | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
537 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
538 | * @retval zero success |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
539 | * @retval non-zero a re-allocation was necessary but failed |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
540 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
541 | #define cx_array_insert_unique_array(array, sorted_data, n, cmp_func) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
542 | cx_array_insert_unique_array_a(cxDefaultAllocator, array, sorted_data, n, cmp_func) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
543 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
544 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
545 | * Inserts sorted data into a sorted array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
546 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
547 | * Internal function - do not use. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
548 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
549 | * @param allocator the allocator to use for a possible reallocation |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
550 | * @param array a pointer to the array structure |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
551 | * @param elem_size the size of one element |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
552 | * @param sorted_data a pointer to an array of data that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
553 | * @param n the number of elements that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
554 | * @param cmp_func the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
555 | * @param context additional context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
556 | * @param allow_duplicates @c false if duplicates shall be skipped during insertion |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
557 | * @retval zero success |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
558 | * @retval non-zero a re-allocation was necessary but failed |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
559 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
560 | CX_EXTERN CX_NONNULL_ARG(1, 2, 4, 6) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
561 | int cx_array_insert_sorted_c_(const CxAllocator *allocator, CxArray *array, |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
562 | size_t elem_size, const void *sorted_data, size_t n, |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
563 | cx_compare_func2 cmp_func, void *context, bool allow_duplicates); |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
564 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
565 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
566 | * Inserts an element into a sorted array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
567 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
568 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
569 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
570 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
571 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
572 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
573 | * @param array the name of the array where the elements shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
574 | * @param element the element that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
575 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
576 | * @param context (@c void*) additional context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
577 | * @retval zero success |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
578 | * @retval non-zero a re-allocation was necessary but failed |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
579 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
580 | #define cx_array_insert_sorted_ca(allocator, array, element, cmp_func, context) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
581 | cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, true) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
582 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
583 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
584 | * Inserts an element into a sorted array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
585 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
586 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
587 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
588 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
589 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
590 | * @param array the name of the array where the elements shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
591 | * @param element the element that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
592 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
593 | * @param context (@c void*) additional context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
594 | * @retval zero success |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
595 | * @retval non-zero a re-allocation was necessary but failed |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
596 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
597 | #define cx_array_insert_sorted_c(array, element, cmp_func, context) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
598 | cx_array_insert_sorted_ca(cxDefaultAllocator, array, element, cmp_func, context) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
599 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
600 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
601 | * Inserts sorted data into a sorted array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
602 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
603 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
604 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
605 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
606 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
607 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
608 | * @param array the name of the array where the elements shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
609 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
610 | * @param n (@c size_t) the number of elements that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
611 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
612 | * @param context (@c void*) additional context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
613 | * @retval zero success |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
614 | * @retval non-zero a re-allocation was necessary but failed |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
615 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
616 | #define cx_array_insert_sorted_array_ca(allocator, array, sorted_data, n, cmp_func, context) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
617 | cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, context, true) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
618 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
619 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
620 | * Inserts sorted data into a sorted array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
621 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
622 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
623 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
624 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
625 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
626 | * @param array the name of the array where the elements shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
627 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
628 | * @param n (@c size_t) the number of elements that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
629 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
630 | * @param context (@c void*) additional context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
631 | * @retval zero success |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
632 | * @retval non-zero a re-allocation was necessary but failed |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
633 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
634 | #define cx_array_insert_sorted_array_c(array, sorted_data, n, cmp_func, context) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
635 | cx_array_insert_sorted_array_ca(cxDefaultAllocator, array, sorted_data, n, cmp_func, context) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
636 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
637 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
638 | * Inserts an element into a sorted array if it is not already contained. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
639 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
640 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
641 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
642 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
643 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
644 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
645 | * @param array the name of the array where the elements shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
646 | * @param element the element that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
647 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
648 | * @param context (@c void*) additional context for the compare function |
| 1016 | 649 | * @retval zero success |
| 650 | * @retval non-zero a re-allocation was necessary but failed | |
| 845 | 651 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
652 | #define cx_array_insert_unique_ca(allocator, array, element, cmp_func, context) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
653 | cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, false) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
654 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
655 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
656 | * Inserts an element into a sorted array if it is not already contained. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
657 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
658 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
659 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
660 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
661 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
662 | * @param array the name of the array where the elements shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
663 | * @param element the element that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
664 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
665 | * @param context (@c void*) additional context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
666 | * @retval zero success |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
667 | * @retval non-zero a re-allocation was necessary but failed |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
668 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
669 | #define cx_array_insert_unique_c(array, element, cmp_func, context) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
670 | cx_array_insert_unique_ca(cxDefaultAllocator, array, element, cmp_func, context) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
671 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
672 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
673 | * Inserts sorted data into a sorted array, skipping duplicates. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
674 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
675 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
676 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
677 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
678 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
679 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
680 | * @param array the name of the array where the elements shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
681 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
682 | * @param n (@c size_t) the number of elements that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
683 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
684 | * @param context (@c void*) additional context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
685 | * @retval zero success |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
686 | * @retval non-zero a re-allocation was necessary but failed |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
687 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
688 | #define cx_array_insert_unique_array_ca(allocator, array, sorted_data, n, cmp_func, context) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
689 | cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, context, false) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
690 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
691 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
692 | * Inserts sorted data into a sorted array, skipping duplicates. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
693 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
694 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
695 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
696 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
697 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
698 | * @param array the name of the array where the elements shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
699 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
700 | * @param n (@c size_t) the number of elements that shall be inserted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
701 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
702 | * @param context (@c void*) additional context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
703 | * @retval zero success |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
704 | * @retval non-zero a re-allocation was necessary but failed |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
705 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
706 | #define cx_array_insert_unique_array_c(array, sorted_data, n, cmp_func, context) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
707 | cx_array_insert_unique_array_ca(cxDefaultAllocator, array, sorted_data, n, cmp_func, context) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
708 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
709 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
710 | * An alternative to qsort_r() when that is not available on your platform. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
711 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
712 | * If it is available, qsort_r() is used directly. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
713 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
714 | * @param array the array that shall be sorted |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
715 | * @param nmemb the number of elements in the array |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
716 | * @param size the size of one element |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
717 | * @param fn the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
718 | * @param context the context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
719 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
720 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
721 | void cx_array_qsort_c(void *array, size_t nmemb, size_t size, |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
722 | cx_compare_func2 fn, void *context); |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
723 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
724 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
725 | * Sorts an array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
726 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
727 | * Internal function - do not use. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
728 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
729 | * @param array a pointer to the array structure |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
730 | * @param elem_size the size of one element |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
731 | * @param fn the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
732 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
733 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
734 | void cx_array_sort_(CxArray *array, size_t elem_size, |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
735 | cx_compare_func fn); |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
736 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
737 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
738 | * Sorts an array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
739 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
740 | * Internal function - do not use. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
741 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
742 | * @param array a pointer to the array structure |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
743 | * @param elem_size the size of one element |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
744 | * @param fn the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
745 | * @param context the context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
746 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
747 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
748 | void cx_array_sort_c_(CxArray *array, size_t elem_size, |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
749 | cx_compare_func2 fn, void *context); |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
750 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
751 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
752 | * Sorts an array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
753 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
754 | * @param array the name of the array |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
755 | * @param fn (@c cx_compare_func) the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
756 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
757 | #define cx_array_sort(array, fn) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
758 | cx_array_sort_((CxArray*)&(array), sizeof((array).data[0]), fn) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
759 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
760 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
761 | * Sorts an array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
762 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
763 | * @param array the name of the array |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
764 | * @param fn (@c cx_compare_func2) the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
765 | * @param context (@c void*) the context for the compare function |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
766 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
767 | #define cx_array_sort_c(array, fn, context) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
768 | cx_array_sort_c_((CxArray*)&(array), sizeof((array).data[0]), fn, context) |
| 1016 | 769 | |
| 770 | /** | |
| 771 | * Creates an iterator over the elements of an array. | |
| 772 | * | |
| 773 | * Internal function - do not use. | |
| 774 | * | |
| 775 | * @param array a pointer to the array structure | |
| 776 | * @param elem_size the size of one element | |
| 777 | * @return an iterator over the elements | |
| 778 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
779 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
780 | CxIterator cx_array_iterator_(CxArray *array, size_t elem_size); |
| 845 | 781 | |
| 782 | /** | |
| 1016 | 783 | * Creates an iterator over the elements of an array. |
| 784 | * | |
| 785 | * The iterator will yield pointers to the elements. | |
| 845 | 786 | * |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
787 | * This iterator cannot be used to remove elements |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
788 | * because it does not get a modifiable reference to the array's size. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
789 | * |
| 1016 | 790 | * @param array the name of the array |
| 791 | * @return an iterator over the elements | |
| 792 | * @see cx_array_iterator_ptr() | |
| 845 | 793 | */ |
| 1016 | 794 | #define cx_array_iterator(array) \ |
| 795 | cx_array_iterator_((CxArray*)&(array), sizeof((array).data[0])) | |
| 845 | 796 | |
| 797 | /** | |
| 1016 | 798 | * Creates an iterator over the elements of an array containing pointers. |
| 799 | * | |
| 800 | * Internal function - do not use. | |
| 845 | 801 | * |
| 1016 | 802 | * @param array the name of the array |
| 803 | * @return an iterator over the elements | |
| 845 | 804 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
805 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
806 | CxIterator cx_array_iterator_ptr_(CxArray *array); |
| 845 | 807 | |
| 808 | /** | |
| 1016 | 809 | * Creates an iterator over the elements of an array containing pointers. |
| 810 | * | |
| 811 | * The iterator will yield the elements themselves, which are supposed to | |
| 812 | * be pointers. | |
| 845 | 813 | * |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
814 | * This iterator cannot be used to remove elements |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
815 | * because it does not get a modifiable reference to the array's size. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
816 | * |
| 1016 | 817 | * @param array the name of the array |
| 818 | * @return an iterator over the elements | |
| 819 | * @see cx_array_iterator() | |
| 845 | 820 | */ |
| 1016 | 821 | #define cx_array_iterator_ptr(array) \ |
| 822 | cx_array_iterator_ptr_((CxArray*)&(array)) | |
| 845 | 823 | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
824 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
825 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
826 | * Removes elements from the array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
827 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
828 | * Internal function - do not use. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
829 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
830 | * @param array a pointer to the array structure |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
831 | * @param elem_size the size of one element |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
832 | * @param index the index of the first element to remove |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
833 | * @param n the number of elements to remove |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
834 | * @param fast indicates whether tail elements should be copied into the gap |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
835 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
836 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
837 | void cx_array_remove_(CxArray *array, size_t elem_size, size_t index, size_t n, bool fast); |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
838 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
839 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
840 | * Removes one element from the array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
841 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
842 | * Tail elements are all moved by one. If you don't need a stable order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
843 | * in the array, consider using cx_array_remove_fast(). |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
844 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
845 | * If the index is out of bounds, this function does nothing. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
846 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
847 | * @param array the name of the array |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
848 | * @param index (@c size_t) the index of the element to remove |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
849 | * @see cx_array_remove_fast() |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
850 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
851 | #define cx_array_remove(array, index) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
852 | cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, 1, false) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
853 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
854 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
855 | * Removes one element from the array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
856 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
857 | * The gap will be filled with a copy of the last element in the array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
858 | * This changes the order of elements. If you want a stable order, |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
859 | * use cx_array_remove() instead. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
860 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
861 | * If the index is out of bounds, this function does nothing. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
862 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
863 | * @param array the name of the array |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
864 | * @param index (@c size_t) the index of the element to remove |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
865 | * @see cx_array_remove() |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
866 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
867 | #define cx_array_remove_fast(array, index) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
868 | cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, 1, true) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
869 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
870 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
871 | * Removes multiple elements from the array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
872 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
873 | * Tail elements are all moved to close the gap. If you don't need a stable |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
874 | * order in the array, consider using cx_array_remove_array_fast(). |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
875 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
876 | * If the index is out of bounds, this function does nothing. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
877 | * If @n overflows the array, this function removes as many elements as it can. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
878 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
879 | * @param array the name of the array |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
880 | * @param index (@c size_t) the index of the first element to remove |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
881 | * @param n (@c size_t) the number of elements to remove |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
882 | * @see cx_array_remove_array_fast() |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
883 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
884 | #define cx_array_remove_array(array, index, n) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
885 | cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, n, false) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
886 | |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
887 | /** |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
888 | * Removes multiple elements from the array. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
889 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
890 | * Tail elements are copied into the gap. If you have more tail elements |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
891 | * than the number of elements that are removed, this will change the order |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
892 | * of elements. If you want a stable order, use cx_array_remove_array() instead. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
893 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
894 | * If the index is out of bounds, this function does nothing. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
895 | * If @n overflows the array, this function removes as many elements as it can. |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
896 | * |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
897 | * @param array the name of the array |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
898 | * @param index (@c size_t) the index of the first element to remove |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
899 | * @param n (@c size_t) the number of elements to remove |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
900 | * @see cx_array_remove_array() |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
901 | */ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
902 | #define cx_array_remove_array_fast(array, index, n) \ |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
903 | cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, n, true) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
904 | |
| 845 | 905 | /** |
| 1016 | 906 | * Deallocates an array. |
| 907 | * | |
| 908 | * Internal function - do not use. | |
| 909 | * | |
| 910 | * @param allocator (@c CxAllocator*) the allocator which was used to allocate the array | |
| 911 | * @param array a pointer to the array structure | |
| 912 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
913 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
914 | void cx_array_free_(const CxAllocator *allocator, CxArray *array); |
| 1016 | 915 | |
| 916 | /** | |
| 917 | * Deallocates an array. | |
| 918 | * | |
| 919 | * The structure is reset to zero and can be re-initialized with | |
| 920 | * cx_array_inita(). | |
| 845 | 921 | * |
| 1016 | 922 | * @param array the name of the array |
| 845 | 923 | */ |
| 1016 | 924 | #define cx_array_free(array) cx_array_free_(cxDefaultAllocator, (CxArray*)&(array)) |
| 925 | ||
| 926 | /** | |
| 927 | * Deallocates an array. | |
| 928 | * | |
| 929 | * The structure is reset to zero and can be re-initialized with | |
| 930 | * cx_array_init_a(). | |
| 931 | * | |
| 932 | * @param allocator (@c CxAllocator*) the allocator which was used to allocate the array | |
| 933 | * @param array the name of the array | |
| 934 | */ | |
| 935 | #define cx_array_free_a(allocator, array) cx_array_free_(allocator, (CxArray*)&(array)) | |
| 936 | ||
| 845 | 937 | |
| 324 | 938 | /** |
| 939 | * Searches the largest lower bound in a sorted array. | |
| 940 | * | |
| 941 | * In other words, this function returns the index of the largest element | |
| 440 | 942 | * in @p arr that is less or equal to @p elem with respect to @p cmp_func. |
| 943 | * When no such element exists, @p size is returned. | |
| 324 | 944 | * |
|
943
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
945 | * When such an element exists more than once, the largest index of all those |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
946 | * elements is returned. |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
947 | * |
| 440 | 948 | * If @p elem is contained in the array, this is identical to |
| 324 | 949 | * #cx_array_binary_search(). |
| 950 | * | |
| 440 | 951 | * If the array is not sorted with respect to the @p cmp_func, the behavior |
| 324 | 952 | * is undefined. |
| 953 | * | |
| 954 | * @param arr the array to search | |
| 955 | * @param size the size of the array | |
| 956 | * @param elem_size the size of one element | |
| 957 | * @param elem the element to find | |
| 958 | * @param cmp_func the compare function | |
| 440 | 959 | * @return the index of the largest lower bound, or @p size |
| 960 | * @see cx_array_binary_search_sup() | |
| 961 | * @see cx_array_binary_search() | |
| 324 | 962 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
963 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
964 | size_t cx_array_binary_search_inf(const void *arr, size_t size, |
| 870 | 965 | size_t elem_size, const void *elem, cx_compare_func cmp_func); |
| 324 | 966 | |
| 967 | /** | |
| 968 | * Searches an item in a sorted array. | |
| 969 | * | |
|
943
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
970 | * When such an element exists more than once, the largest index of all those |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
971 | * elements is returned. |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
972 | * |
| 440 | 973 | * If the array is not sorted with respect to the @p cmp_func, the behavior |
| 324 | 974 | * is undefined. |
| 975 | * | |
| 976 | * @param arr the array to search | |
| 977 | * @param size the size of the array | |
| 978 | * @param elem_size the size of one element | |
| 979 | * @param elem the element to find | |
| 980 | * @param cmp_func the compare function | |
| 440 | 981 | * @return the index of the element in the array, or @p size if the element |
| 324 | 982 | * cannot be found |
| 440 | 983 | * @see cx_array_binary_search_inf() |
| 984 | * @see cx_array_binary_search_sup() | |
| 324 | 985 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
986 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
987 | size_t cx_array_binary_search(const void *arr, size_t size, |
| 870 | 988 | size_t elem_size, const void *elem, cx_compare_func cmp_func); |
| 324 | 989 | |
| 990 | /** | |
| 991 | * Searches the smallest upper bound in a sorted array. | |
| 992 | * | |
| 993 | * In other words, this function returns the index of the smallest element | |
| 440 | 994 | * in @p arr that is greater or equal to @p elem with respect to @p cmp_func. |
| 995 | * When no such element exists, @p size is returned. | |
| 324 | 996 | * |
|
943
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
997 | * When such an element exists more than once, the smallest index of all those |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
998 | * elements is returned. |
|
9b5948aa5b90
update ucx to version 3.2
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
999 | * |
| 440 | 1000 | * If @p elem is contained in the array, this is identical to |
| 324 | 1001 | * #cx_array_binary_search(). |
| 1002 | * | |
| 440 | 1003 | * If the array is not sorted with respect to the @p cmp_func, the behavior |
| 324 | 1004 | * is undefined. |
| 1005 | * | |
| 1006 | * @param arr the array to search | |
| 1007 | * @param size the size of the array | |
| 1008 | * @param elem_size the size of one element | |
| 1009 | * @param elem the element to find | |
| 1010 | * @param cmp_func the compare function | |
| 440 | 1011 | * @return the index of the smallest upper bound, or @p size |
| 1012 | * @see cx_array_binary_search_inf() | |
| 1013 | * @see cx_array_binary_search() | |
| 324 | 1014 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1015 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1016 | size_t cx_array_binary_search_sup(const void *arr, size_t size, |
| 870 | 1017 | size_t elem_size, const void *elem, cx_compare_func cmp_func); |
| 324 | 1018 | |
| 1016 | 1019 | |
| 1020 | /** | |
| 1021 | * Searches the largest lower bound in a sorted array. | |
| 1022 | * | |
| 1023 | * In other words, this function returns the index of the largest element | |
| 1024 | * in @p arr that is less or equal to @p elem with respect to @p cmp_func. | |
| 1025 | * When no such element exists, @p size is returned. | |
| 1026 | * | |
| 1027 | * When such an element exists more than once, the largest index of all those | |
| 1028 | * elements is returned. | |
| 1029 | * | |
| 1030 | * If @p elem is contained in the array, this is identical to | |
| 1031 | * #cx_array_binary_search(). | |
| 1032 | * | |
| 1033 | * If the array is not sorted with respect to the @p cmp_func, the behavior | |
| 1034 | * is undefined. | |
| 1035 | * | |
| 1036 | * @param arr the array to search | |
| 1037 | * @param size the size of the array | |
| 1038 | * @param elem_size the size of one element | |
| 1039 | * @param elem the element to find | |
| 1040 | * @param cmp_func the compare function | |
| 1041 | * @param context the context for the compare function | |
| 1042 | * @return the index of the largest lower bound, or @p size | |
| 1043 | * @see cx_array_binary_search_sup() | |
| 1044 | * @see cx_array_binary_search() | |
| 1045 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1046 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1047 | size_t cx_array_binary_search_inf_c(const void *arr, size_t size, |
| 1016 | 1048 | size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context); |
| 1049 | ||
| 1050 | /** | |
| 1051 | * Searches an item in a sorted array. | |
| 1052 | * | |
| 1053 | * When such an element exists more than once, the largest index of all those | |
| 1054 | * elements is returned. | |
| 1055 | * | |
| 1056 | * If the array is not sorted with respect to the @p cmp_func, the behavior | |
| 1057 | * is undefined. | |
| 1058 | * | |
| 1059 | * @param arr the array to search | |
| 1060 | * @param size the size of the array | |
| 1061 | * @param elem_size the size of one element | |
| 1062 | * @param elem the element to find | |
| 1063 | * @param cmp_func the compare function | |
| 1064 | * @param context the context for the compare function | |
| 1065 | * @return the index of the element in the array, or @p size if the element | |
| 1066 | * cannot be found | |
| 1067 | * @see cx_array_binary_search_inf() | |
| 1068 | * @see cx_array_binary_search_sup() | |
| 1069 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1070 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1071 | size_t cx_array_binary_search_c(const void *arr, size_t size, |
| 1016 | 1072 | size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context); |
| 1073 | ||
| 1074 | /** | |
| 1075 | * Searches the smallest upper bound in a sorted array. | |
| 1076 | * | |
| 1077 | * In other words, this function returns the index of the smallest element | |
| 1078 | * in @p arr that is greater or equal to @p elem with respect to @p cmp_func. | |
| 1079 | * When no such element exists, @p size is returned. | |
| 1080 | * | |
| 1081 | * When such an element exists more than once, the smallest index of all those | |
| 1082 | * elements is returned. | |
| 1083 | * | |
| 1084 | * If @p elem is contained in the array, this is identical to | |
| 1085 | * #cx_array_binary_search(). | |
| 1086 | * | |
| 1087 | * If the array is not sorted with respect to the @p cmp_func, the behavior | |
| 1088 | * is undefined. | |
| 1089 | * | |
| 1090 | * @param arr the array to search | |
| 1091 | * @param size the size of the array | |
| 1092 | * @param elem_size the size of one element | |
| 1093 | * @param elem the element to find | |
| 1094 | * @param cmp_func the compare function | |
| 1095 | * @param context the context for the compare function | |
| 1096 | * @return the index of the smallest upper bound, or @p size | |
| 1097 | * @see cx_array_binary_search_inf() | |
| 1098 | * @see cx_array_binary_search() | |
| 1099 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1100 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1101 | size_t cx_array_binary_search_sup_c(const void *arr, size_t size, |
| 1016 | 1102 | size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context); |
| 1103 | ||
| 324 | 1104 | /** |
| 174 | 1105 | * Swaps two array elements. |
| 1106 | * | |
| 1107 | * @param arr the array | |
| 1108 | * @param elem_size the element size | |
| 845 | 1109 | * @param idx1 index of the first element |
| 1110 | * @param idx2 index of the second element | |
| 174 | 1111 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1112 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1113 | void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2); |
| 174 | 1114 | |
| 1115 | /** | |
| 440 | 1116 | * Allocates an array list for storing elements with @p elem_size bytes each. |
| 174 | 1117 | * |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
1118 | * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
| 845 | 1119 | * copies of the added elements, and the compare function will be automatically set |
| 1016 | 1120 | * to cx_cmp_ptr(). |
| 174 | 1121 | * |
| 1122 | * @param allocator the allocator for allocating the list memory | |
|
629
0385a450c2a6
add list initializer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
1123 | * (if @c NULL, the cxDefaultAllocator will be used) |
| 324 | 1124 | * @param elem_size the size of each element in bytes |
| 174 | 1125 | * @param initial_capacity the initial number of elements the array can store |
| 1126 | * @return the created list | |
| 1127 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1128 | CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxListFree, 1) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1034
diff
changeset
|
1129 | CxList *cxArrayListCreate(const CxAllocator *allocator, |
| 1016 | 1130 | size_t elem_size, size_t initial_capacity); |
| 174 | 1131 | |
| 1132 | #endif // UCX_ARRAY_LIST_H |