Wed, 31 Dec 2025 16:41:16 +0100
update ucx to version 4.0
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 852 | 29 | * @file array_list.h |
| 30 | * @brief Array list implementation. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #ifndef UCX_ARRAY_LIST_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #define UCX_ARRAY_LIST_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "list.h" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | /** |
| 889 | 43 | * The maximum item size in an array list that fits into |
| 44 | * a stack buffer when swapped. | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
45 | */ |
| 889 | 46 | CX_EXPORT extern const unsigned cx_array_swap_sbo_size; |
| 852 | 47 | |
| 48 | /** | |
| 891 | 49 | * Declares a typed array with size and capacity. |
| 852 | 50 | * |
| 891 | 51 | * @param type the type of the elements |
| 52 | * @param name the name of the array | |
| 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. | |
| 852 | 63 | * |
| 891 | 64 | * A generalization of array structures declared with CX_ARRAY(). |
| 65 | */ | |
| 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; | |
| 74 | ||
| 75 | /** | |
| 76 | * Initializes an array by allocating memory. | |
| 852 | 77 | * |
| 891 | 78 | * Internal function - do not use manually. |
| 79 | * | |
| 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 | |
| 852 | 86 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
87 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
88 | int cx_array_init_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity); |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
89 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
90 | /** |
| 891 | 91 | * Initializes an array by allocating memory. |
| 852 | 92 | * |
| 891 | 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. | |
| 852 | 97 | * |
| 891 | 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 | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
103 | */ |
| 891 | 104 | #define cx_array_init_a(allocator, array, capacity) cx_array_init_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity) |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
105 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
106 | /** |
| 891 | 107 | * Initializes an array by allocating memory. |
| 852 | 108 | * |
| 891 | 109 | * The size is set to zero. |
| 852 | 110 | * |
| 891 | 111 | * @attention If the array was already initialized, this will leak memory. |
| 886 | 112 | * |
| 852 | 113 | * @param array the name of the array |
| 891 | 114 | * @param capacity (@c size_t) the initial maximum number of elements |
| 115 | * @retval zero allocation was successful | |
| 116 | * @retval non-zero allocation failed | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
117 | */ |
| 891 | 118 | #define cx_array_init(array, capacity) cx_array_init_a(cxDefaultAllocator, array, capacity) |
| 119 | ||
| 120 | /** | |
| 121 | * Initializes an array with fixed size memory. | |
| 122 | * | |
| 123 | * Internal function - do not use manually. | |
| 124 | * | |
| 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 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
130 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
131 | void cx_array_init_fixed_(CxArray *array, const void *data, size_t capacity, size_t size); |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
132 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
133 | /** |
| 891 | 134 | * Initializes an array with fixed size memory. |
| 135 | * | |
| 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. | |
| 138 | * | |
| 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. | |
| 852 | 142 | * |
| 891 | 143 | * The capacity is determined automatically by the compiler. |
| 852 | 144 | * |
| 891 | 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. | |
| 148 | * | |
| 149 | * @attention When you pass a pointer to an array that does not have a fixed | |
| 150 | * size, the behavior is unspecified. | |
| 852 | 151 | * |
| 891 | 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() | |
| 156 | */ | |
| 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) | |
| 159 | ||
| 160 | /** | |
| 161 | * Changes the capacity of an array. | |
| 852 | 162 | * |
| 891 | 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 | |
| 852 | 171 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
172 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
173 | int cx_array_reserve_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity); |
| 852 | 174 | |
| 175 | /** | |
| 891 | 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 | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | */ |
| 891 | 186 | #define cx_array_reserve_a(allocator, array, capacity) \ |
| 187 | cx_array_reserve_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity) | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | |
| 891 | 189 | /** |
| 190 | * Changes the capacity of an array. | |
| 191 | * | |
| 192 | * If required, the size is reduced to fit into the new capacity. | |
| 193 | * | |
| 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) | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | /** |
| 891 | 203 | * Copies the array to a new memory region. |
| 204 | * | |
| 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 | |
| 852 | 213 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
214 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
215 | int cx_array_copy_to_new_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity); |
| 852 | 216 | |
| 217 | /** | |
| 891 | 218 | * Copies the array to a new memory region. |
| 852 | 219 | * |
| 891 | 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. | |
| 222 | * | |
| 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. | |
| 852 | 225 | * |
| 891 | 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() | |
| 852 | 232 | */ |
| 891 | 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) | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
235 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
236 | /** |
| 891 | 237 | * Copies the array to a new memory region. |
| 852 | 238 | * |
| 891 | 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. | |
| 852 | 241 | * |
| 891 | 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. | |
| 852 | 244 | * |
| 891 | 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() | |
| 250 | */ | |
| 251 | #define cx_array_copy_to_new(array, capacity) \ | |
| 252 | cx_array_copy_to_new_a(cxDefaultAllocator, array, capacity) | |
| 253 | ||
| 254 | /** | |
| 255 | * Inserts data into an array. | |
| 256 | * | |
| 257 | * Internal function - do not use. | |
| 258 | * | |
| 259 | * @param allocator the allocator to use for a possible reallocation | |
| 260 | * @param array a pointer to the array structure | |
| 852 | 261 | * @param elem_size the size of one element |
| 891 | 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 | |
| 852 | 265 | * @retval zero success |
| 891 | 266 | * @retval non-zero a re-allocation was necessary but failed |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
267 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
268 | CX_EXTERN CX_NONNULL_ARG(1, 2) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
269 | int cx_array_insert_(const CxAllocator *allocator, CxArray *array, |
| 891 | 270 | size_t elem_size, size_t index, const void *other, size_t n); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | /** |
| 891 | 273 | * Appends an element to an array. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | * |
| 891 | 275 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | * |
| 891 | 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 | |
| 279 | * @param element the element that shall be added | |
| 852 | 280 | * @retval zero success |
| 891 | 281 | * @retval non-zero a re-allocation was necessary but failed |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | */ |
| 891 | 283 | #define cx_array_add_a(allocator, array, element) \ |
| 284 | cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, (void*)&(element), 1) | |
| 285 | ||
| 286 | /** | |
| 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. | |
| 290 | * | |
| 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 | |
| 293 | * @retval zero success | |
| 294 | * @retval non-zero a re-allocation was necessary but failed | |
| 295 | */ | |
| 296 | #define cx_array_add(array, element) \ | |
| 297 | cx_array_add_a(cxDefaultAllocator, array, element) | |
| 852 | 298 | |
| 299 | /** | |
| 891 | 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. | |
| 852 | 303 | * |
| 891 | 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 | |
| 307 | * @param element the element that shall be inserted | |
| 852 | 308 | * @retval zero success |
| 891 | 309 | * @retval non-zero a re-allocation was necessary but failed |
| 852 | 310 | */ |
| 891 | 311 | #define cx_array_insert_a(allocator, array, index, element) \ |
| 312 | cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, (void*)&(element), 1) | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
314 | /** |
| 891 | 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. | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
318 | * |
| 891 | 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 | |
| 852 | 322 | * @retval zero success |
| 891 | 323 | * @retval non-zero a re-allocation was necessary but failed |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
324 | */ |
| 891 | 325 | #define cx_array_insert(array, index, element) \ |
| 326 | cx_array_insert_a(cxDefaultAllocator, array, index, element) | |
| 852 | 327 | |
| 328 | /** | |
| 891 | 329 | * Inserts data into an array. |
| 330 | * | |
| 331 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 852 | 332 | * |
| 891 | 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 | |
| 852 | 338 | * @retval zero success |
| 891 | 339 | * @retval non-zero a re-allocation was necessary but failed |
| 852 | 340 | */ |
| 891 | 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) | |
| 852 | 343 | |
| 344 | /** | |
| 891 | 345 | * Inserts data into an array. |
| 346 | * | |
| 347 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 852 | 348 | * |
| 891 | 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 | |
| 852 | 353 | * @retval zero success |
| 891 | 354 | * @retval non-zero a re-allocation was necessary but failed |
| 852 | 355 | */ |
| 891 | 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) | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
373 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
374 | /** |
| 891 | 375 | * Appends data to an array. |
| 852 | 376 | * |
| 891 | 377 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. |
| 852 | 378 | * |
| 891 | 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 | |
| 852 | 382 | * @retval zero success |
| 891 | 383 | * @retval non-zero a re-allocation was necessary but failed |
| 852 | 384 | */ |
| 891 | 385 | #define cx_array_add_array(array, other, n) \ |
| 386 | cx_array_add_array_a(cxDefaultAllocator, array, other, n) | |
| 852 | 387 | |
| 388 | /** | |
| 891 | 389 | * Inserts sorted data into a sorted array. |
| 390 | * | |
| 391 | * Internal function - do not use. | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
392 | * |
| 891 | 393 | * @param allocator the allocator to use for a possible reallocation |
| 394 | * @param array a pointer to the array structure | |
| 395 | * @param elem_size the size of one element | |
| 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 | |
| 398 | * @param cmp_func the compare function | |
| 399 | * @param allow_duplicates @c false if duplicates shall be skipped during insertion | |
| 852 | 400 | * @retval zero success |
| 891 | 401 | * @retval non-zero a re-allocation was necessary but failed |
| 852 | 402 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
403 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
404 | int cx_array_insert_sorted_(const CxAllocator *allocator, CxArray *array, |
| 891 | 405 | size_t elem_size, const void *sorted_data, size_t n, |
| 406 | cx_compare_func cmp_func, bool allow_duplicates); | |
| 852 | 407 | |
| 408 | /** | |
| 891 | 409 | * Inserts an element into a sorted array. |
| 852 | 410 | * |
| 891 | 411 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 852 | 412 | * |
| 891 | 413 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 852 | 414 | * |
| 891 | 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 | |
| 417 | * @param element the element that shall be inserted | |
| 418 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order | |
| 852 | 419 | * @retval zero success |
| 891 | 420 | * @retval non-zero a re-allocation was necessary but failed |
| 852 | 421 | */ |
| 891 | 422 | #define cx_array_insert_sorted_a(allocator, array, element, cmp_func) \ |
| 423 | cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, true) | |
| 852 | 424 | |
| 425 | /** | |
| 426 | * Inserts an element into a sorted array. | |
| 427 | * | |
| 891 | 428 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. |
| 429 | * | |
| 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 | |
| 433 | * @param element the element that shall be inserted | |
| 434 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order | |
| 435 | * @retval zero success | |
| 436 | * @retval non-zero a re-allocation was necessary but failed | |
| 437 | */ | |
| 438 | #define cx_array_insert_sorted(array, element, cmp_func) \ | |
| 439 | cx_array_insert_sorted_a(cxDefaultAllocator, array, element, cmp_func) | |
| 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. | |
| 852 | 445 | * |
| 891 | 446 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. |
| 852 | 447 | * |
| 891 | 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 | |
| 452 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order | |
| 453 | * @retval zero success | |
| 454 | * @retval non-zero a re-allocation was necessary but failed | |
| 455 | */ | |
| 456 | #define cx_array_insert_sorted_array_a(allocator, array, sorted_data, n, cmp_func) \ | |
| 457 | cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, true) | |
| 458 | ||
| 459 | /** | |
| 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. | |
| 463 | * | |
| 464 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 852 | 465 | * |
| 891 | 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 | |
| 469 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order | |
| 852 | 470 | * @retval zero success |
| 891 | 471 | * @retval non-zero a re-allocation was necessary but failed |
| 472 | */ | |
| 473 | #define cx_array_insert_sorted_array(array, sorted_data, n, cmp_func) \ | |
| 474 | cx_array_insert_sorted_array_a(cxDefaultAllocator, array, sorted_data, n, cmp_func) | |
| 475 | ||
| 476 | /** | |
| 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. | |
| 482 | * | |
| 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 | |
| 485 | * @param element the element that shall be inserted | |
| 486 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order | |
| 487 | * @retval zero success | |
| 488 | * @retval non-zero a re-allocation was necessary but failed | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
489 | */ |
| 891 | 490 | #define cx_array_insert_unique_a(allocator, array, element, cmp_func) \ |
| 491 | cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, false) | |
| 492 | ||
| 493 | /** | |
| 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. | |
| 497 | * | |
| 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 | |
| 501 | * @param element the element that shall be inserted | |
| 502 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order | |
| 503 | * @retval zero success | |
| 504 | * @retval non-zero a re-allocation was necessary but failed | |
| 505 | */ | |
| 506 | #define cx_array_insert_unique(array, element, cmp_func) \ | |
| 507 | cx_array_insert_unique_a(cxDefaultAllocator, array, element, cmp_func) | |
| 852 | 508 | |
| 509 | /** | |
| 891 | 510 | * Inserts sorted data into a sorted array, skipping duplicates. |
| 511 | * | |
| 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. | |
| 515 | * | |
| 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 | |
| 520 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order | |
| 521 | * @retval zero success | |
| 522 | * @retval non-zero a re-allocation was necessary but failed | |
| 523 | */ | |
| 524 | #define cx_array_insert_unique_array_a(allocator, array, sorted_data, n, cmp_func) \ | |
| 525 | cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, false) | |
| 526 | ||
| 527 | /** | |
| 528 | * Inserts sorted data into a sorted array, skipping duplicates. | |
| 529 | * | |
| 530 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 531 | * | |
| 532 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 852 | 533 | * |
| 891 | 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 | |
| 537 | * @param cmp_func (@c cx_compare_func) the compare function that establishes the order | |
| 538 | * @retval zero success | |
| 539 | * @retval non-zero a re-allocation was necessary but failed | |
| 540 | */ | |
| 541 | #define cx_array_insert_unique_array(array, sorted_data, n, cmp_func) \ | |
| 542 | cx_array_insert_unique_array_a(cxDefaultAllocator, array, sorted_data, n, cmp_func) | |
| 543 | ||
| 544 | /** | |
| 545 | * Inserts sorted data into a sorted array. | |
| 546 | * | |
| 547 | * Internal function - do not use. | |
| 548 | * | |
| 549 | * @param allocator the allocator to use for a possible reallocation | |
| 550 | * @param array a pointer to the array structure | |
| 551 | * @param elem_size the size of one element | |
| 552 | * @param sorted_data a pointer to an array of data that shall be inserted | |
| 553 | * @param n the number of elements that shall be inserted | |
| 554 | * @param cmp_func the compare function | |
| 555 | * @param context additional context for the compare function | |
| 556 | * @param allow_duplicates @c false if duplicates shall be skipped during insertion | |
| 852 | 557 | * @retval zero success |
| 891 | 558 | * @retval non-zero a re-allocation was necessary but failed |
| 559 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
560 | CX_EXTERN CX_NONNULL_ARG(1, 2, 4, 6) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
561 | int cx_array_insert_sorted_c_(const CxAllocator *allocator, CxArray *array, |
| 891 | 562 | size_t elem_size, const void *sorted_data, size_t n, |
| 563 | cx_compare_func2 cmp_func, void *context, bool allow_duplicates); | |
| 564 | ||
| 565 | /** | |
| 566 | * Inserts an element into a sorted array. | |
| 567 | * | |
| 568 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 569 | * | |
| 570 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 571 | * | |
| 572 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation | |
| 573 | * @param array the name of the array where the elements shall be inserted | |
| 574 | * @param element the element that shall be inserted | |
| 575 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order | |
| 576 | * @param context (@c void*) additional context for the compare function | |
| 577 | * @retval zero success | |
| 578 | * @retval non-zero a re-allocation was necessary but failed | |
| 852 | 579 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
580 | #define cx_array_insert_sorted_ca(allocator, array, element, cmp_func, context) \ |
| 891 | 581 | cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, true) |
| 582 | ||
| 583 | /** | |
| 584 | * Inserts an element into a sorted array. | |
| 585 | * | |
| 586 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 587 | * | |
| 588 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 589 | * | |
| 590 | * @param array the name of the array where the elements shall be inserted | |
| 591 | * @param element the element that shall be inserted | |
| 592 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order | |
| 593 | * @param context (@c void*) additional context for the compare function | |
| 594 | * @retval zero success | |
| 595 | * @retval non-zero a re-allocation was necessary but failed | |
| 596 | */ | |
| 597 | #define cx_array_insert_sorted_c(array, element, cmp_func, context) \ | |
| 598 | cx_array_insert_sorted_ca(cxDefaultAllocator, array, element, cmp_func, context) | |
| 599 | ||
| 600 | /** | |
| 601 | * Inserts sorted data into a sorted array. | |
| 602 | * | |
| 603 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 604 | * | |
| 605 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 606 | * | |
| 607 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation | |
| 608 | * @param array the name of the array where the elements shall be inserted | |
| 609 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted | |
| 610 | * @param n (@c size_t) the number of elements that shall be inserted | |
| 611 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order | |
| 612 | * @param context (@c void*) additional context for the compare function | |
| 613 | * @retval zero success | |
| 614 | * @retval non-zero a re-allocation was necessary but failed | |
| 615 | */ | |
| 616 | #define cx_array_insert_sorted_array_ca(allocator, array, sorted_data, n, cmp_func, context) \ | |
| 617 | cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, context, true) | |
| 852 | 618 | |
| 619 | /** | |
| 891 | 620 | * Inserts sorted data into a sorted array. |
| 621 | * | |
| 622 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 623 | * | |
| 624 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 852 | 625 | * |
| 891 | 626 | * @param array the name of the array where the elements shall be inserted |
| 627 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted | |
| 628 | * @param n (@c size_t) the number of elements that shall be inserted | |
| 629 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order | |
| 630 | * @param context (@c void*) additional context for the compare function | |
| 631 | * @retval zero success | |
| 632 | * @retval non-zero a re-allocation was necessary but failed | |
| 633 | */ | |
| 634 | #define cx_array_insert_sorted_array_c(array, sorted_data, n, cmp_func, context) \ | |
| 635 | cx_array_insert_sorted_array_ca(cxDefaultAllocator, array, sorted_data, n, cmp_func, context) | |
| 636 | ||
| 637 | /** | |
| 638 | * Inserts an element into a sorted array if it is not already contained. | |
| 639 | * | |
| 640 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 641 | * | |
| 642 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 643 | * | |
| 644 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation | |
| 645 | * @param array the name of the array where the elements shall be inserted | |
| 646 | * @param element the element that shall be inserted | |
| 647 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order | |
| 648 | * @param context (@c void*) additional context for the compare function | |
| 852 | 649 | * @retval zero success |
| 891 | 650 | * @retval non-zero a re-allocation was necessary but failed |
| 651 | */ | |
| 652 | #define cx_array_insert_unique_ca(allocator, array, element, cmp_func, context) \ | |
| 653 | cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, false) | |
| 654 | ||
| 655 | /** | |
| 656 | * Inserts an element into a sorted array if it is not already contained. | |
| 657 | * | |
| 658 | * When the capacity is not enough to hold the new element, a re-allocation is attempted. | |
| 659 | * | |
| 660 | * @attention if the array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 661 | * | |
| 662 | * @param array the name of the array where the elements shall be inserted | |
| 663 | * @param element the element that shall be inserted | |
| 664 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order | |
| 665 | * @param context (@c void*) additional context for the compare function | |
| 666 | * @retval zero success | |
| 667 | * @retval non-zero a re-allocation was necessary but failed | |
| 852 | 668 | */ |
| 891 | 669 | #define cx_array_insert_unique_c(array, element, cmp_func, context) \ |
| 670 | cx_array_insert_unique_ca(cxDefaultAllocator, array, element, cmp_func, context) | |
| 671 | ||
| 672 | /** | |
| 673 | * Inserts sorted data into a sorted array, skipping duplicates. | |
| 674 | * | |
| 675 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 676 | * | |
| 677 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 678 | * | |
| 679 | * @param allocator (@c CxAllocator*) the allocator to use for a possible reallocation | |
| 680 | * @param array the name of the array where the elements shall be inserted | |
| 681 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted | |
| 682 | * @param n (@c size_t) the number of elements that shall be inserted | |
| 683 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order | |
| 684 | * @param context (@c void*) additional context for the compare function | |
| 685 | * @retval zero success | |
| 686 | * @retval non-zero a re-allocation was necessary but failed | |
| 687 | */ | |
| 688 | #define cx_array_insert_unique_array_ca(allocator, array, sorted_data, n, cmp_func, context) \ | |
| 689 | cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, context, false) | |
| 690 | ||
| 691 | /** | |
| 692 | * Inserts sorted data into a sorted array, skipping duplicates. | |
| 693 | * | |
| 694 | * When the capacity is not enough to hold the new elements, a re-allocation is attempted. | |
| 695 | * | |
| 696 | * @attention if either array is not sorted according to the specified @p cmp_func, the behavior is undefined. | |
| 697 | * | |
| 698 | * @param array the name of the array where the elements shall be inserted | |
| 699 | * @param sorted_data (@c void*) a pointer to an array of sorted data that shall be inserted | |
| 700 | * @param n (@c size_t) the number of elements that shall be inserted | |
| 701 | * @param cmp_func (@c cx_compare_func2) the compare function that establishes the order | |
| 702 | * @param context (@c void*) additional context for the compare function | |
| 703 | * @retval zero success | |
| 704 | * @retval non-zero a re-allocation was necessary but failed | |
| 705 | */ | |
| 706 | #define cx_array_insert_unique_array_c(array, sorted_data, n, cmp_func, context) \ | |
| 707 | cx_array_insert_unique_array_ca(cxDefaultAllocator, array, sorted_data, n, cmp_func, context) | |
| 852 | 708 | |
| 709 | /** | |
| 891 | 710 | * An alternative to qsort_r() when that is not available on your platform. |
| 711 | * | |
| 712 | * If it is available, qsort_r() is used directly. | |
| 713 | * | |
| 714 | * @param array the array that shall be sorted | |
| 715 | * @param nmemb the number of elements in the array | |
| 716 | * @param size the size of one element | |
| 717 | * @param fn the compare function | |
| 718 | * @param context the context for the compare function | |
| 719 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
720 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
721 | void cx_array_qsort_c(void *array, size_t nmemb, size_t size, |
| 891 | 722 | cx_compare_func2 fn, void *context); |
| 723 | ||
| 724 | /** | |
| 725 | * Sorts an array. | |
| 726 | * | |
| 727 | * Internal function - do not use. | |
| 852 | 728 | * |
| 891 | 729 | * @param array a pointer to the array structure |
| 730 | * @param elem_size the size of one element | |
| 731 | * @param fn the compare function | |
| 852 | 732 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
733 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
734 | void cx_array_sort_(CxArray *array, size_t elem_size, |
| 891 | 735 | cx_compare_func fn); |
| 736 | ||
| 737 | /** | |
| 738 | * Sorts an array. | |
| 739 | * | |
| 740 | * Internal function - do not use. | |
| 741 | * | |
| 742 | * @param array a pointer to the array structure | |
| 743 | * @param elem_size the size of one element | |
| 744 | * @param fn the compare function | |
| 745 | * @param context the context for the compare function | |
| 746 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
747 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
748 | void cx_array_sort_c_(CxArray *array, size_t elem_size, |
| 891 | 749 | cx_compare_func2 fn, void *context); |
| 750 | ||
| 751 | /** | |
| 752 | * Sorts an array. | |
| 753 | * | |
| 754 | * @param array the name of the array | |
| 755 | * @param fn (@c cx_compare_func) the compare function | |
| 756 | */ | |
| 757 | #define cx_array_sort(array, fn) \ | |
| 758 | cx_array_sort_((CxArray*)&(array), sizeof((array).data[0]), fn) | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
759 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
760 | /** |
| 891 | 761 | * Sorts an array. |
| 762 | * | |
| 763 | * @param array the name of the array | |
| 764 | * @param fn (@c cx_compare_func2) the compare function | |
| 765 | * @param context (@c void*) the context for the compare function | |
| 766 | */ | |
| 767 | #define cx_array_sort_c(array, fn, context) \ | |
| 768 | cx_array_sort_c_((CxArray*)&(array), sizeof((array).data[0]), fn, context) | |
| 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 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
779 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
780 | CxIterator cx_array_iterator_(CxArray *array, size_t elem_size); |
| 891 | 781 | |
| 782 | /** | |
| 783 | * Creates an iterator over the elements of an array. | |
| 784 | * | |
| 785 | * The iterator will yield pointers to the elements. | |
| 786 | * | |
| 787 | * This iterator cannot be used to remove elements | |
| 788 | * because it does not get a modifiable reference to the array's size. | |
| 852 | 789 | * |
| 891 | 790 | * @param array the name of the array |
| 791 | * @return an iterator over the elements | |
| 792 | * @see cx_array_iterator_ptr() | |
| 793 | */ | |
| 794 | #define cx_array_iterator(array) \ | |
| 795 | cx_array_iterator_((CxArray*)&(array), sizeof((array).data[0])) | |
| 796 | ||
| 797 | /** | |
| 798 | * Creates an iterator over the elements of an array containing pointers. | |
| 799 | * | |
| 800 | * Internal function - do not use. | |
| 801 | * | |
| 802 | * @param array the name of the array | |
| 803 | * @return an iterator over the elements | |
| 852 | 804 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
805 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
806 | CxIterator cx_array_iterator_ptr_(CxArray *array); |
| 891 | 807 | |
| 808 | /** | |
| 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. | |
| 813 | * | |
| 814 | * This iterator cannot be used to remove elements | |
| 815 | * because it does not get a modifiable reference to the array's size. | |
| 816 | * | |
| 817 | * @param array the name of the array | |
| 818 | * @return an iterator over the elements | |
| 819 | * @see cx_array_iterator() | |
| 820 | */ | |
| 821 | #define cx_array_iterator_ptr(array) \ | |
| 822 | cx_array_iterator_ptr_((CxArray*)&(array)) | |
| 852 | 823 | |
| 889 | 824 | |
| 825 | /** | |
| 891 | 826 | * Removes elements from the array. |
| 889 | 827 | * |
| 891 | 828 | * Internal function - do not use. |
| 889 | 829 | * |
| 891 | 830 | * @param array a pointer to the array structure |
| 889 | 831 | * @param elem_size the size of one element |
| 891 | 832 | * @param index the index of the first element to remove |
| 833 | * @param n the number of elements to remove | |
| 834 | * @param fast indicates whether tail elements should be copied into the gap | |
| 889 | 835 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
836 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
837 | void cx_array_remove_(CxArray *array, size_t elem_size, size_t index, size_t n, bool fast); |
| 889 | 838 | |
| 839 | /** | |
| 891 | 840 | * Removes one element from the array. |
| 889 | 841 | * |
| 891 | 842 | * Tail elements are all moved by one. If you don't need a stable order |
| 843 | * in the array, consider using cx_array_remove_fast(). | |
| 889 | 844 | * |
| 891 | 845 | * If the index is out of bounds, this function does nothing. |
| 889 | 846 | * |
| 891 | 847 | * @param array the name of the array |
| 848 | * @param index (@c size_t) the index of the element to remove | |
| 849 | * @see cx_array_remove_fast() | |
| 889 | 850 | */ |
| 891 | 851 | #define cx_array_remove(array, index) \ |
| 852 | cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, 1, false) | |
| 853 | ||
| 854 | /** | |
| 855 | * Removes one element from the array. | |
| 856 | * | |
| 857 | * The gap will be filled with a copy of the last element in the array. | |
| 858 | * This changes the order of elements. If you want a stable order, | |
| 859 | * use cx_array_remove() instead. | |
| 860 | * | |
| 861 | * If the index is out of bounds, this function does nothing. | |
| 862 | * | |
| 863 | * @param array the name of the array | |
| 864 | * @param index (@c size_t) the index of the element to remove | |
| 865 | * @see cx_array_remove() | |
| 866 | */ | |
| 867 | #define cx_array_remove_fast(array, index) \ | |
| 868 | cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, 1, true) | |
| 889 | 869 | |
| 870 | /** | |
| 891 | 871 | * Removes multiple elements from the array. |
| 872 | * | |
| 873 | * Tail elements are all moved to close the gap. If you don't need a stable | |
| 874 | * order in the array, consider using cx_array_remove_array_fast(). | |
| 889 | 875 | * |
| 891 | 876 | * If the index is out of bounds, this function does nothing. |
| 877 | * If @n overflows the array, this function removes as many elements as it can. | |
| 878 | * | |
| 879 | * @param array the name of the array | |
| 880 | * @param index (@c size_t) the index of the first element to remove | |
| 881 | * @param n (@c size_t) the number of elements to remove | |
| 882 | * @see cx_array_remove_array_fast() | |
| 889 | 883 | */ |
| 891 | 884 | #define cx_array_remove_array(array, index, n) \ |
| 885 | cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, n, false) | |
| 889 | 886 | |
| 887 | /** | |
| 891 | 888 | * Removes multiple elements from the array. |
| 889 | * | |
| 890 | * Tail elements are copied into the gap. If you have more tail elements | |
| 891 | * than the number of elements that are removed, this will change the order | |
| 892 | * of elements. If you want a stable order, use cx_array_remove_array() instead. | |
| 889 | 893 | * |
| 891 | 894 | * If the index is out of bounds, this function does nothing. |
| 895 | * If @n overflows the array, this function removes as many elements as it can. | |
| 896 | * | |
| 897 | * @param array the name of the array | |
| 898 | * @param index (@c size_t) the index of the first element to remove | |
| 899 | * @param n (@c size_t) the number of elements to remove | |
| 900 | * @see cx_array_remove_array() | |
| 889 | 901 | */ |
| 891 | 902 | #define cx_array_remove_array_fast(array, index, n) \ |
| 903 | cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, n, true) | |
| 889 | 904 | |
| 905 | /** | |
| 891 | 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 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
913 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
914 | void cx_array_free_(const CxAllocator *allocator, CxArray *array); |
| 891 | 915 | |
| 916 | /** | |
| 917 | * Deallocates an array. | |
| 918 | * | |
| 919 | * The structure is reset to zero and can be re-initialized with | |
| 920 | * cx_array_inita(). | |
| 889 | 921 | * |
| 891 | 922 | * @param array the name of the array |
| 889 | 923 | */ |
| 891 | 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 | ||
| 889 | 937 | |
| 852 | 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 | |
| 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. | |
| 944 | * | |
| 891 | 945 | * When such an element exists more than once, the largest index of all those |
| 946 | * elements is returned. | |
| 947 | * | |
| 852 | 948 | * If @p elem is contained in the array, this is identical to |
| 949 | * #cx_array_binary_search(). | |
| 950 | * | |
| 951 | * If the array is not sorted with respect to the @p cmp_func, the behavior | |
| 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 | |
| 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() | |
| 962 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
963 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
964 | size_t cx_array_binary_search_inf(const void *arr, size_t size, |
| 889 | 965 | size_t elem_size, const void *elem, cx_compare_func cmp_func); |
| 852 | 966 | |
| 967 | /** | |
| 968 | * Searches an item in a sorted array. | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
969 | * |
| 891 | 970 | * When such an element exists more than once, the largest index of all those |
| 971 | * elements is returned. | |
| 972 | * | |
| 852 | 973 | * If the array is not sorted with respect to the @p cmp_func, the behavior |
| 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 | |
| 981 | * @return the index of the element in the array, or @p size if the element | |
| 982 | * cannot be found | |
| 983 | * @see cx_array_binary_search_inf() | |
| 984 | * @see cx_array_binary_search_sup() | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
985 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
986 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
987 | size_t cx_array_binary_search(const void *arr, size_t size, |
| 889 | 988 | size_t elem_size, const void *elem, cx_compare_func cmp_func); |
| 852 | 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 | |
| 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. | |
| 996 | * | |
| 891 | 997 | * When such an element exists more than once, the smallest index of all those |
| 998 | * elements is returned. | |
| 999 | * | |
| 852 | 1000 | * If @p elem is contained in the array, this is identical to |
| 1001 | * #cx_array_binary_search(). | |
| 1002 | * | |
| 1003 | * If the array is not sorted with respect to the @p cmp_func, the behavior | |
| 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 | |
| 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() | |
| 1014 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1015 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1016 | size_t cx_array_binary_search_sup(const void *arr, size_t size, |
| 889 | 1017 | size_t elem_size, const void *elem, cx_compare_func cmp_func); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1018 | |
| 891 | 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 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1046 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1047 | size_t cx_array_binary_search_inf_c(const void *arr, size_t size, |
| 891 | 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 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1070 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1071 | size_t cx_array_binary_search_c(const void *arr, size_t size, |
| 891 | 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 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1100 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1101 | size_t cx_array_binary_search_sup_c(const void *arr, size_t size, |
| 891 | 1102 | size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context); |
| 1103 | ||
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1104 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1105 | * Swaps two array elements. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1106 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1107 | * @param arr the array |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1108 | * @param elem_size the element size |
| 889 | 1109 | * @param idx1 index of the first element |
| 1110 | * @param idx2 index of the second element | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1111 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1112 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1113 | void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1114 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1115 | /** |
| 852 | 1116 | * Allocates an array list for storing elements with @p elem_size bytes each. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1117 | * |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
1118 | * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
| 889 | 1119 | * copies of the added elements, and the compare function will be automatically set |
| 891 | 1120 | * to cx_cmp_ptr(). |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1121 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1122 | * @param allocator the allocator for allocating the list memory |
| 886 | 1123 | * (if @c NULL, the cxDefaultAllocator will be used) |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
1124 | * @param elem_size the size of each element in bytes |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1125 | * @param initial_capacity the initial number of elements the array can store |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1126 | * @return the created list |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1127 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1128 | CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxListFree, 1) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
891
diff
changeset
|
1129 | CxList *cxArrayListCreate(const CxAllocator *allocator, |
| 891 | 1130 | size_t elem_size, size_t initial_capacity); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1131 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1132 | #endif // UCX_ARRAY_LIST_H |