Mon, 08 Sep 2025 12:10:13 +0200
add dav_resource_path_key
|
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 | #ifdef __cplusplus |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | extern "C" { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | /** |
| 852 | 47 | * The maximum item size in an array list that fits into stack buffer |
| 48 | * when swapped. | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
49 | */ |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
50 | cx_attr_export |
| 852 | 51 | extern const unsigned cx_array_swap_sbo_size; |
| 52 | ||
| 53 | /** | |
| 54 | * Declares variables for an array that can be used with the convenience macros. | |
| 55 | * | |
| 56 | * @par Examples | |
| 57 | * @code | |
| 58 | * // integer array with at most 255 elements | |
| 59 | * CX_ARRAY_DECLARE_SIZED(int, myarray, uint8_t) | |
| 60 | * | |
| 61 | * // array of MyObject* pointers where size and capacity are stored as unsigned int | |
| 62 | * CX_ARRAY_DECLARE_SIZED(MyObject*, objects, unsigned int) | |
| 63 | * | |
| 64 | * // initializing code | |
| 65 | * cx_array_initialize(myarray, 16); // reserve space for 16 | |
| 66 | * cx_array_initialize(objects, 100); // reserve space for 100 | |
| 67 | * @endcode | |
| 68 | * | |
| 69 | * @param type the type of the data | |
| 70 | * @param name the name of the array | |
| 71 | * @param size_type the type of the size (should be uint8_t, uint16_t, uint32_t, or size_t) | |
| 72 | * | |
| 73 | * @see cx_array_initialize() | |
| 74 | * @see cx_array_simple_add() | |
| 75 | * @see cx_array_simple_copy() | |
| 76 | * @see cx_array_simple_add_sorted() | |
| 77 | * @see cx_array_simple_insert_sorted() | |
| 78 | */ | |
| 79 | #define CX_ARRAY_DECLARE_SIZED(type, name, size_type) \ | |
| 80 | type * name; \ | |
| 81 | /** Array size. */ size_type name##_size; \ | |
| 82 | /** Array capacity. */ size_type name##_capacity | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
83 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
84 | /** |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
85 | * Declares variables for an array that can be used with the convenience macros. |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
86 | * |
| 852 | 87 | * The size and capacity variables will have @c size_t type. |
| 88 | * Use #CX_ARRAY_DECLARE_SIZED() to specify a different type. | |
| 89 | * | |
| 90 | * @par Examples | |
| 91 | * @code | |
| 92 | * // int array | |
| 93 | * CX_ARRAY_DECLARE(int, myarray) | |
| 94 | * | |
| 95 | * // initializing code | |
| 96 | * cx_array_initialize(myarray, 32); // reserve space for 32 | |
| 97 | * @endcode | |
| 98 | * | |
| 99 | * @param type the type of the data | |
| 100 | * @param name the name of the array | |
| 101 | * | |
| 102 | * @see cx_array_initialize() | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
103 | * @see cx_array_simple_add() |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
104 | * @see cx_array_simple_copy() |
| 852 | 105 | * @see cx_array_simple_add_sorted() |
| 106 | * @see cx_array_simple_insert_sorted() | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
107 | */ |
| 852 | 108 | #define CX_ARRAY_DECLARE(type, name) CX_ARRAY_DECLARE_SIZED(type, name, size_t) |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
109 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
110 | /** |
| 852 | 111 | * Initializes an array with the given capacity. |
| 112 | * | |
| 113 | * The type of the capacity depends on the type used during declaration. | |
| 114 | * | |
| 115 | * @par Examples | |
| 116 | * @code | |
| 117 | * CX_ARRAY_DECLARE_SIZED(int, arr1, uint8_t) | |
| 118 | * CX_ARRAY_DECLARE(int, arr2) // size and capacity are implicitly size_t | |
| 119 | * | |
| 120 | * // initializing code | |
| 121 | * cx_array_initialize(arr1, 500); // error: maximum for uint8_t is 255 | |
| 122 | * cx_array_initialize(arr2, 500); // OK | |
| 123 | * @endcode | |
| 124 | * | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
125 | * |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
126 | * The memory for the array is allocated with stdlib malloc(). |
| 852 | 127 | * @param array the name of the array |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
128 | * @param capacity the initial capacity |
| 852 | 129 | * @see cx_array_initialize_a() |
| 130 | * @see CX_ARRAY_DECLARE_SIZED() | |
| 131 | * @see CX_ARRAY_DECLARE() | |
|
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 | #define cx_array_initialize(array, capacity) \ |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
134 | array##_capacity = capacity; \ |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
135 | array##_size = 0; \ |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
136 | array = malloc(sizeof(array[0]) * capacity) |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
137 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
138 | /** |
| 852 | 139 | * Initializes an array with the given capacity using the specified allocator. |
| 140 | * | |
| 141 | * @par Example | |
| 142 | * @code | |
| 143 | * CX_ARRAY_DECLARE(int, myarray) | |
| 144 | * | |
| 145 | * | |
| 146 | * const CxAllocator *al = // ... | |
| 147 | * cx_array_initialize_a(al, myarray, 128); | |
| 148 | * // ... | |
| 149 | * cxFree(al, myarray); // don't forget to free with same allocator | |
| 150 | * @endcode | |
| 151 | * | |
| 152 | * The memory for the array is allocated with stdlib malloc(). | |
| 153 | * @param allocator (@c CxAllocator*) the allocator | |
| 154 | * @param array the name of the array | |
| 155 | * @param capacity the initial capacity | |
| 156 | * @see cx_array_initialize() | |
| 157 | * @see CX_ARRAY_DECLARE_SIZED() | |
| 158 | * @see CX_ARRAY_DECLARE() | |
| 159 | */ | |
| 160 | #define cx_array_initialize_a(allocator, array, capacity) \ | |
| 161 | array##_capacity = capacity; \ | |
| 162 | array##_size = 0; \ | |
| 163 | array = cxMalloc(allocator, sizeof(array[0]) * capacity) | |
| 164 | ||
| 165 | /** | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | * Defines a reallocation mechanism for arrays. |
| 852 | 167 | * You can create your own, use cx_array_reallocator(), or |
| 168 | * use the #cx_array_default_reallocator. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | struct cx_array_reallocator_s { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | /** |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
172 | * Reallocates space for the given array. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | * Implementations are not required to free the original array. |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
175 | * This allows reallocation of static memory by allocating heap memory |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
176 | * and copying the array contents. The information in the custom fields of |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
177 | * the referenced allocator can be used to track the state of the memory |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
178 | * or to transport other additional data. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | * @param array the array to reallocate |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | * @param capacity the new capacity (number of elements) |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | * @param elem_size the size of each element |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | * @param alloc a reference to this allocator |
| 852 | 184 | * @return a pointer to the reallocated memory or @c NULL on failure |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | */ |
| 852 | 186 | cx_attr_nodiscard |
| 187 | cx_attr_nonnull_arg(4) | |
| 188 | cx_attr_allocsize(2, 3) | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | void *(*realloc)( |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | void *array, |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | size_t capacity, |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | size_t elem_size, |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | struct cx_array_reallocator_s *alloc |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | ); |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | * Custom data pointer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | void *ptr1; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | * Custom data pointer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | void *ptr2; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | * Custom data integer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | size_t int1; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | * Custom data integer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | size_t int2; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | }; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | /** |
| 852 | 215 | * Typedef for the array reallocator struct. |
| 216 | */ | |
| 217 | typedef struct cx_array_reallocator_s CxArrayReallocator; | |
| 218 | ||
| 219 | /** | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
220 | * A default stdlib-based array reallocator. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | */ |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
222 | cx_attr_export |
| 852 | 223 | extern CxArrayReallocator *cx_array_default_reallocator; |
| 224 | ||
| 225 | /** | |
| 226 | * Creates a new array reallocator. | |
| 227 | * | |
| 228 | * When @p allocator is @c NULL, the stdlib default allocator will be used. | |
| 229 | * | |
| 230 | * When @p stackmem is not @c NULL, the reallocator is supposed to be used | |
| 231 | * @em only for the specific array that is initially located at @p stackmem. | |
| 232 | * When reallocation is needed, the reallocator checks, if the array is | |
| 233 | * still located at @p stackmem and copies the contents to the heap. | |
| 234 | * | |
| 235 | * @note Invoking this function with both arguments @c NULL will return a | |
| 236 | * reallocator that behaves like #cx_array_default_reallocator. | |
| 237 | * | |
| 238 | * @param allocator the allocator this reallocator shall be based on | |
| 239 | * @param stackmem the address of the array when the array is initially located | |
| 240 | * on the stack or shall not reallocated in place | |
| 241 | * @return an array reallocator | |
| 242 | */ | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
243 | cx_attr_export |
| 852 | 244 | CxArrayReallocator cx_array_reallocator( |
| 245 | const struct cx_allocator_s *allocator, | |
| 246 | const void *stackmem | |
| 247 | ); | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
248 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
249 | /** |
| 852 | 250 | * Reserves memory for additional elements. |
| 251 | * | |
| 252 | * This function checks if the @p capacity of the array is sufficient to hold | |
| 253 | * at least @p size plus @p elem_count elements. If not, a reallocation is | |
| 254 | * performed with the specified @p reallocator. | |
| 255 | * You can create your own reallocator by hand, use #cx_array_default_reallocator, | |
| 256 | * or use the convenience function cx_array_reallocator() to create a custom reallocator. | |
| 257 | * | |
| 258 | * This function can be useful to replace subsequent calls to cx_array_copy() | |
| 259 | * with one single cx_array_reserve() and then - after guaranteeing a | |
| 260 | * sufficient capacity - use simple memmove() or memcpy(). | |
| 261 | * | |
| 262 | * The @p width in bytes refers to the size and capacity. | |
| 263 | * Both must have the same width. | |
| 264 | * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64 bit | |
| 265 | * architecture. If set to zero, the native word width is used. | |
| 266 | * | |
| 267 | * @param array a pointer to the target array | |
| 268 | * @param size a pointer to the size of the array | |
| 269 | * @param capacity a pointer to the capacity of the array | |
| 270 | * @param width the width in bytes for the @p size and @p capacity or zero for default | |
| 271 | * @param elem_size the size of one element | |
| 272 | * @param elem_count the number of expected additional elements | |
| 273 | * @param reallocator the array reallocator to use | |
| 274 | * (@c NULL defaults to #cx_array_default_reallocator) | |
| 275 | * @retval zero success | |
| 276 | * @retval non-zero failure | |
| 277 | * @see cx_array_reallocator() | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
278 | */ |
| 852 | 279 | cx_attr_nonnull_arg(1, 2, 3) |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
280 | cx_attr_export |
| 852 | 281 | int cx_array_reserve( |
| 282 | void **array, | |
| 283 | void *size, | |
| 284 | void *capacity, | |
| 285 | unsigned width, | |
| 286 | size_t elem_size, | |
| 287 | size_t elem_count, | |
| 288 | CxArrayReallocator *reallocator | |
| 289 | ); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | * Copies elements from one array to another. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | * |
| 852 | 294 | * The elements are copied to the @p target array at the specified @p index, |
| 295 | * overwriting possible elements. The @p index does not need to be in range of | |
| 296 | * the current array @p size. If the new index plus the number of elements added | |
| 297 | * would extend the array's size, the remaining @p capacity is used. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | * |
| 852 | 299 | * If the @p capacity is also insufficient to hold the new data, a reallocation |
| 300 | * attempt is made with the specified @p reallocator. | |
| 301 | * You can create your own reallocator by hand, use #cx_array_default_reallocator, | |
| 302 | * or use the convenience function cx_array_reallocator() to create a custom reallocator. | |
| 303 | * | |
| 304 | * The @p width in bytes refers to the size and capacity. | |
| 305 | * Both must have the same width. | |
| 306 | * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64 bit | |
| 307 | * architecture. If set to zero, the native word width is used. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | * |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
309 | * @param target a pointer to the target array |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | * @param size a pointer to the size of the target array |
| 852 | 311 | * @param capacity a pointer to the capacity of the target array |
| 312 | * @param width the width in bytes for the @p size and @p capacity or zero for default | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | * @param index the index where the copied elements shall be placed |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | * @param src the source array |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | * @param elem_size the size of one element |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | * @param elem_count the number of elements to copy |
| 852 | 317 | * @param reallocator the array reallocator to use |
| 318 | * (@c NULL defaults to #cx_array_default_reallocator) | |
| 319 | * @retval zero success | |
| 320 | * @retval non-zero failure | |
| 321 | * @see cx_array_reallocator() | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | */ |
| 852 | 323 | cx_attr_nonnull_arg(1, 2, 3, 6) |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
324 | cx_attr_export |
| 852 | 325 | int cx_array_copy( |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326 | void **target, |
| 852 | 327 | void *size, |
| 328 | void *capacity, | |
| 329 | unsigned width, | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | size_t index, |
| 852 | 331 | const void *src, |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | size_t elem_size, |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | size_t elem_count, |
| 852 | 334 | CxArrayReallocator *reallocator |
| 335 | ); | |
| 336 | ||
| 337 | /** | |
| 338 | * Convenience macro that uses cx_array_copy() with a default layout and | |
| 339 | * the specified reallocator. | |
| 340 | * | |
| 341 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 342 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 343 | * @param index (@c size_t) the index where the copied elements shall be placed | |
| 344 | * @param src (@c void*) the source array | |
| 345 | * @param count (@c size_t) the number of elements to copy | |
| 346 | * @retval zero success | |
| 347 | * @retval non-zero failure | |
| 348 | * @see CX_ARRAY_DECLARE() | |
| 349 | * @see cx_array_simple_copy() | |
| 350 | */ | |
| 351 | #define cx_array_simple_copy_a(reallocator, array, index, src, count) \ | |
| 352 | cx_array_copy((void**)&(array), &(array##_size), &(array##_capacity), \ | |
| 353 | sizeof(array##_size), index, src, sizeof((array)[0]), count, \ | |
| 354 | reallocator) | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
356 | /** |
| 852 | 357 | * Convenience macro that uses cx_array_copy() with a default layout and |
| 358 | * the default reallocator. | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
359 | * |
| 852 | 360 | * @param array the name of the array (NOT a pointer or alias to the array) |
| 361 | * @param index (@c size_t) the index where the copied elements shall be placed | |
| 362 | * @param src (@c void*) the source array | |
| 363 | * @param count (@c size_t) the number of elements to copy | |
| 364 | * @retval zero success | |
| 365 | * @retval non-zero failure | |
| 366 | * @see CX_ARRAY_DECLARE() | |
| 367 | * @see cx_array_simple_copy_a() | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
368 | */ |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
369 | #define cx_array_simple_copy(array, index, src, count) \ |
| 852 | 370 | cx_array_simple_copy_a(NULL, array, index, src, count) |
| 371 | ||
| 372 | /** | |
| 373 | * Convenience macro that uses cx_array_reserve() with a default layout and | |
| 374 | * the specified reallocator. | |
| 375 | * | |
| 376 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 377 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 378 | * @param count (@c size_t) the number of expected @em additional elements | |
| 379 | * @retval zero success | |
| 380 | * @retval non-zero failure | |
| 381 | * @see CX_ARRAY_DECLARE() | |
| 382 | * @see cx_array_simple_reserve() | |
| 383 | */ | |
| 384 | #define cx_array_simple_reserve_a(reallocator, array, count) \ | |
| 385 | cx_array_reserve((void**)&(array), &(array##_size), &(array##_capacity), \ | |
| 386 | sizeof(array##_size), sizeof((array)[0]), count, \ | |
| 387 | reallocator) | |
| 388 | ||
| 389 | /** | |
| 390 | * Convenience macro that uses cx_array_reserve() with a default layout and | |
| 391 | * the default reallocator. | |
| 392 | * | |
| 393 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 394 | * @param count (@c size_t) the number of expected additional elements | |
| 395 | * @retval zero success | |
| 396 | * @retval non-zero failure | |
| 397 | * @see CX_ARRAY_DECLARE() | |
| 398 | * @see cx_array_simple_reserve_a() | |
| 399 | */ | |
| 400 | #define cx_array_simple_reserve(array, count) \ | |
| 401 | cx_array_simple_reserve_a(NULL, array, count) | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
402 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
403 | /** |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
404 | * Adds an element to an array with the possibility of allocating more space. |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
405 | * |
| 852 | 406 | * The element @p elem is added to the end of the @p target array which contains |
| 407 | * @p size elements, already. The @p capacity must point to a variable denoting | |
| 408 | * the current maximum number of elements the array can hold. | |
| 409 | * | |
| 410 | * If the capacity is insufficient to hold the new element, an attempt to | |
| 411 | * increase the @p capacity is made and the new capacity is written back. | |
| 412 | * | |
| 413 | * The \@ SIZE_TYPE is flexible and can be any unsigned integer type. | |
| 414 | * It is important, however, that @p size and @p capacity are pointers to | |
| 415 | * variables of the same type. | |
| 416 | * | |
| 417 | * @param target (@c void**) a pointer to the target array | |
| 418 | * @param size (@c SIZE_TYPE*) a pointer to the size of the target array | |
| 419 | * @param capacity (@c SIZE_TYPE*) a pointer to the capacity of the target array | |
| 420 | * @param elem_size (@c size_t) the size of one element | |
| 421 | * @param elem (@c void*) a pointer to the element to add | |
| 422 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 423 | * @retval zero success | |
| 424 | * @retval non-zero failure | |
| 425 | */ | |
| 426 | #define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \ | |
| 427 | cx_array_copy((void**)(target), size, capacity, sizeof(*(size)), \ | |
| 428 | *(size), elem, elem_size, 1, reallocator) | |
| 429 | ||
| 430 | /** | |
| 431 | * Convenience macro that uses cx_array_add() with a default layout and | |
| 432 | * the specified reallocator. | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
433 | * |
| 852 | 434 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use |
| 435 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 436 | * @param elem the element to add (NOT a pointer, address is automatically taken) | |
| 437 | * @retval zero success | |
| 438 | * @retval non-zero failure | |
| 439 | * @see CX_ARRAY_DECLARE() | |
| 440 | * @see cx_array_simple_add() | |
| 441 | */ | |
| 442 | #define cx_array_simple_add_a(reallocator, array, elem) \ | |
| 443 | cx_array_simple_copy_a(reallocator, array, array##_size, &(elem), 1) | |
| 444 | ||
| 445 | /** | |
| 446 | * Convenience macro that uses cx_array_add() with a default layout and | |
| 447 | * the default reallocator. | |
| 448 | * | |
| 449 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 450 | * @param elem the element to add (NOT a pointer, address is automatically taken) | |
| 451 | * @retval zero success | |
| 452 | * @retval non-zero failure | |
| 453 | * @see CX_ARRAY_DECLARE() | |
| 454 | * @see cx_array_simple_add_a() | |
| 455 | */ | |
| 456 | #define cx_array_simple_add(array, elem) \ | |
| 457 | cx_array_simple_add_a(cx_array_default_reallocator, array, elem) | |
| 458 | ||
| 459 | /** | |
| 460 | * Inserts a sorted array into another sorted array. | |
| 461 | * | |
| 462 | * If either the target or the source array is not already sorted with respect | |
| 463 | * to the specified @p cmp_func, the behavior is undefined. | |
| 464 | * | |
| 465 | * If the capacity is insufficient to hold the new data, a reallocation | |
| 466 | * attempt is made. | |
| 467 | * You can create your own reallocator by hand, use #cx_array_default_reallocator, | |
| 468 | * or use the convenience function cx_array_reallocator() to create a custom reallocator. | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
469 | * |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
470 | * @param target a pointer to the target array |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
471 | * @param size a pointer to the size of the target array |
| 852 | 472 | * @param capacity a pointer to the capacity of the target array |
| 473 | * @param cmp_func the compare function for the elements | |
| 474 | * @param src the source array | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
475 | * @param elem_size the size of one element |
| 852 | 476 | * @param elem_count the number of elements to insert |
| 477 | * @param reallocator the array reallocator to use | |
| 478 | * (@c NULL defaults to #cx_array_default_reallocator) | |
| 479 | * @retval zero success | |
| 480 | * @retval non-zero failure | |
| 481 | */ | |
| 482 | cx_attr_nonnull_arg(1, 2, 3, 5) | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
483 | cx_attr_export |
| 852 | 484 | int cx_array_insert_sorted( |
| 485 | void **target, | |
| 486 | size_t *size, | |
| 487 | size_t *capacity, | |
| 488 | cx_compare_func cmp_func, | |
| 489 | const void *src, | |
| 490 | size_t elem_size, | |
| 491 | size_t elem_count, | |
| 492 | CxArrayReallocator *reallocator | |
| 493 | ); | |
| 494 | ||
| 495 | /** | |
| 496 | * Inserts an element into a sorted array. | |
| 497 | * | |
| 498 | * If the target array is not already sorted with respect | |
| 499 | * to the specified @p cmp_func, the behavior is undefined. | |
| 500 | * | |
| 501 | * If the capacity is insufficient to hold the new data, a reallocation | |
| 502 | * attempt is made. | |
| 503 | * | |
| 504 | * The \@ SIZE_TYPE is flexible and can be any unsigned integer type. | |
| 505 | * It is important, however, that @p size and @p capacity are pointers to | |
| 506 | * variables of the same type. | |
| 507 | * | |
| 508 | * @param target (@c void**) a pointer to the target array | |
| 509 | * @param size (@c SIZE_TYPE*) a pointer to the size of the target array | |
| 510 | * @param capacity (@c SIZE_TYPE*) a pointer to the capacity of the target array | |
| 511 | * @param elem_size (@c size_t) the size of one element | |
| 512 | * @param elem (@c void*) a pointer to the element to add | |
| 513 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 514 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 515 | * @retval zero success | |
| 516 | * @retval non-zero failure | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
517 | */ |
| 852 | 518 | #define cx_array_add_sorted(target, size, capacity, elem_size, elem, cmp_func, reallocator) \ |
| 519 | cx_array_insert_sorted((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator) | |
| 520 | ||
| 521 | /** | |
| 522 | * Convenience macro for cx_array_add_sorted() with a default | |
| 523 | * layout and the specified reallocator. | |
| 524 | * | |
| 525 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 526 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 527 | * @param elem the element to add (NOT a pointer, address is automatically taken) | |
| 528 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 529 | * @retval zero success | |
| 530 | * @retval non-zero failure | |
| 531 | * @see CX_ARRAY_DECLARE() | |
| 532 | * @see cx_array_simple_add_sorted() | |
| 533 | */ | |
| 534 | #define cx_array_simple_add_sorted_a(reallocator, array, elem, cmp_func) \ | |
| 535 | cx_array_add_sorted(&array, &(array##_size), &(array##_capacity), \ | |
| 536 | sizeof((array)[0]), &(elem), cmp_func, reallocator) | |
| 537 | ||
| 538 | /** | |
| 539 | * Convenience macro for cx_array_add_sorted() with a default | |
| 540 | * layout and the default reallocator. | |
| 541 | * | |
| 542 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 543 | * @param elem the element to add (NOT a pointer, address is automatically taken) | |
| 544 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 545 | * @retval zero success | |
| 546 | * @retval non-zero failure | |
| 547 | * @see CX_ARRAY_DECLARE() | |
| 548 | * @see cx_array_simple_add_sorted_a() | |
| 549 | */ | |
| 550 | #define cx_array_simple_add_sorted(array, elem, cmp_func) \ | |
| 551 | cx_array_simple_add_sorted_a(NULL, array, elem, cmp_func) | |
| 552 | ||
| 553 | /** | |
| 554 | * Convenience macro for cx_array_insert_sorted() with a default | |
| 555 | * layout and the specified reallocator. | |
| 556 | * | |
| 557 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 558 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 559 | * @param src (@c void*) pointer to the source array | |
| 560 | * @param n (@c size_t) number of elements in the source array | |
| 561 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 562 | * @retval zero success | |
| 563 | * @retval non-zero failure | |
| 564 | * @see CX_ARRAY_DECLARE() | |
| 565 | * @see cx_array_simple_insert_sorted() | |
| 566 | */ | |
| 567 | #define cx_array_simple_insert_sorted_a(reallocator, array, src, n, cmp_func) \ | |
| 568 | cx_array_insert_sorted((void**)(&array), &(array##_size), &(array##_capacity), \ | |
| 569 | cmp_func, src, sizeof((array)[0]), n, reallocator) | |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
570 | |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
571 | /** |
| 852 | 572 | * Convenience macro for cx_array_insert_sorted() with a default |
| 573 | * layout and the default reallocator. | |
| 574 | * | |
| 575 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 576 | * @param src (@c void*) pointer to the source array | |
| 577 | * @param n (@c size_t) number of elements in the source array | |
| 578 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 579 | * @retval zero success | |
| 580 | * @retval non-zero failure | |
| 581 | * @see CX_ARRAY_DECLARE() | |
| 582 | * @see cx_array_simple_insert_sorted_a() | |
| 583 | */ | |
| 584 | #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \ | |
| 585 | cx_array_simple_insert_sorted_a(NULL, array, src, n, cmp_func) | |
| 586 | ||
| 587 | /** | |
| 588 | * Searches the largest lower bound in a sorted array. | |
| 589 | * | |
| 590 | * In other words, this function returns the index of the largest element | |
| 591 | * in @p arr that is less or equal to @p elem with respect to @p cmp_func. | |
| 592 | * When no such element exists, @p size is returned. | |
| 593 | * | |
| 594 | * If @p elem is contained in the array, this is identical to | |
| 595 | * #cx_array_binary_search(). | |
| 596 | * | |
| 597 | * If the array is not sorted with respect to the @p cmp_func, the behavior | |
| 598 | * is undefined. | |
| 599 | * | |
| 600 | * @param arr the array to search | |
| 601 | * @param size the size of the array | |
| 602 | * @param elem_size the size of one element | |
| 603 | * @param elem the element to find | |
| 604 | * @param cmp_func the compare function | |
| 605 | * @return the index of the largest lower bound, or @p size | |
| 606 | * @see cx_array_binary_search_sup() | |
| 607 | * @see cx_array_binary_search() | |
| 608 | */ | |
| 609 | cx_attr_nonnull | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
610 | cx_attr_export |
| 852 | 611 | size_t cx_array_binary_search_inf( |
| 612 | const void *arr, | |
| 613 | size_t size, | |
| 614 | size_t elem_size, | |
| 615 | const void *elem, | |
| 616 | cx_compare_func cmp_func | |
| 617 | ); | |
| 618 | ||
| 619 | /** | |
| 620 | * 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
|
621 | * |
| 852 | 622 | * If the array is not sorted with respect to the @p cmp_func, the behavior |
| 623 | * is undefined. | |
| 624 | * | |
| 625 | * @param arr the array to search | |
| 626 | * @param size the size of the array | |
| 627 | * @param elem_size the size of one element | |
| 628 | * @param elem the element to find | |
| 629 | * @param cmp_func the compare function | |
| 630 | * @return the index of the element in the array, or @p size if the element | |
| 631 | * cannot be found | |
| 632 | * @see cx_array_binary_search_inf() | |
| 633 | * @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
|
634 | */ |
| 852 | 635 | cx_attr_nonnull |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
636 | cx_attr_export |
| 852 | 637 | size_t cx_array_binary_search( |
| 638 | const void *arr, | |
| 639 | size_t size, | |
| 640 | size_t elem_size, | |
| 641 | const void *elem, | |
| 642 | cx_compare_func cmp_func | |
| 643 | ); | |
| 644 | ||
| 645 | /** | |
| 646 | * Searches the smallest upper bound in a sorted array. | |
| 647 | * | |
| 648 | * In other words, this function returns the index of the smallest element | |
| 649 | * in @p arr that is greater or equal to @p elem with respect to @p cmp_func. | |
| 650 | * When no such element exists, @p size is returned. | |
| 651 | * | |
| 652 | * If @p elem is contained in the array, this is identical to | |
| 653 | * #cx_array_binary_search(). | |
| 654 | * | |
| 655 | * If the array is not sorted with respect to the @p cmp_func, the behavior | |
| 656 | * is undefined. | |
| 657 | * | |
| 658 | * @param arr the array to search | |
| 659 | * @param size the size of the array | |
| 660 | * @param elem_size the size of one element | |
| 661 | * @param elem the element to find | |
| 662 | * @param cmp_func the compare function | |
| 663 | * @return the index of the smallest upper bound, or @p size | |
| 664 | * @see cx_array_binary_search_inf() | |
| 665 | * @see cx_array_binary_search() | |
| 666 | */ | |
| 667 | cx_attr_nonnull | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
668 | cx_attr_export |
| 852 | 669 | size_t cx_array_binary_search_sup( |
| 670 | const void *arr, | |
| 671 | size_t size, | |
| 672 | size_t elem_size, | |
| 673 | const void *elem, | |
| 674 | cx_compare_func cmp_func | |
| 675 | ); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
676 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
677 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
678 | * 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
|
679 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
680 | * @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
|
681 | * @param elem_size the element size |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
682 | * @param idx1 index of first element |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
683 | * @param idx2 index of second element |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
684 | */ |
| 852 | 685 | cx_attr_nonnull |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
686 | cx_attr_export |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687 | void cx_array_swap( |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
688 | void *arr, |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689 | size_t elem_size, |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690 | size_t idx1, |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | size_t idx2 |
| 852 | 692 | ); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | /** |
| 852 | 695 | * 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
|
696 | * |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
697 | * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
698 | * copies of the added elements and the compare function will be automatically set |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
699 | * to cx_cmp_ptr(), if none is given. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701 | * @param allocator the allocator for allocating the list memory |
| 852 | 702 | * (if @c NULL, a default stdlib allocator will be used) |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
703 | * @param comparator the comparator for the elements |
| 852 | 704 | * (if @c NULL, and the list is not storing pointers, sort and find |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
705 | * functions will not work) |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
706 | * @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
|
707 | * @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
|
708 | * @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
|
709 | */ |
| 852 | 710 | cx_attr_nodiscard |
| 711 | cx_attr_malloc | |
| 712 | cx_attr_dealloc(cxListFree, 1) | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
713 | cx_attr_export |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
714 | CxList *cxArrayListCreate( |
| 852 | 715 | const CxAllocator *allocator, |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
716 | cx_compare_func comparator, |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
717 | size_t elem_size, |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
718 | size_t initial_capacity |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
719 | ); |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721 | /** |
| 852 | 722 | * 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
|
723 | * |
| 852 | 724 | * The list will use the cxDefaultAllocator and @em NO compare function. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
725 | * If you want to call functions that need a compare function, you have to |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
726 | * set it immediately after creation or use cxArrayListCreate(). |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
727 | * |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
728 | * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
729 | * copies of the added elements and the compare function will be automatically set |
|
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
730 | * to cx_cmp_ptr(), if none is given. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
731 | * |
| 852 | 732 | * @param elem_size (@c size_t) the size of each element in bytes |
| 733 | * @param initial_capacity (@c size_t) the initial number of elements the array can store | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
734 | * @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
|
735 | */ |
|
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
736 | #define cxArrayListCreateSimple(elem_size, initial_capacity) \ |
|
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
747
diff
changeset
|
737 | cxArrayListCreate(NULL, NULL, elem_size, 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
|
738 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739 | #ifdef __cplusplus |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
740 | } // extern "C" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
743 | #endif // UCX_ARRAY_LIST_H |