Tue, 09 Dec 2025 12:13:43 +0100
add first tests
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
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 |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 16 | 29 | * @file array_list.h |
| 30 | * @brief Array list implementation. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #ifndef UCX_ARRAY_LIST_H |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #define UCX_ARRAY_LIST_H |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "list.h" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #ifdef __cplusplus |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | extern "C" { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #endif |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | /** |
| 22 | 47 | * The maximum item size in an array list that fits into |
| 48 | * a stack buffer when swapped. | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | */ |
| 22 | 50 | CX_EXPORT extern const unsigned cx_array_swap_sbo_size; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | * Declares variables for an array that can be used with the convenience macros. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | * |
| 16 | 55 | * @par Examples |
| 56 | * @code | |
| 57 | * // integer array with at most 255 elements | |
| 58 | * CX_ARRAY_DECLARE_SIZED(int, myarray, uint8_t) | |
| 59 | * | |
| 60 | * // array of MyObject* pointers where size and capacity are stored as unsigned int | |
| 61 | * CX_ARRAY_DECLARE_SIZED(MyObject*, objects, unsigned int) | |
| 62 | * | |
| 63 | * // initializing code | |
| 64 | * cx_array_initialize(myarray, 16); // reserve space for 16 | |
| 65 | * cx_array_initialize(objects, 100); // reserve space for 100 | |
| 66 | * @endcode | |
| 67 | * | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
68 | * @param type the type of the data |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
69 | * @param name the name of the array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
70 | * @param size_type the type of the size (should be uint8_t, uint16_t, uint32_t, or size_t) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
71 | * |
| 16 | 72 | * @see cx_array_initialize() |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | * @see cx_array_simple_add() |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | * @see cx_array_simple_copy() |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
75 | * @see cx_array_simple_add_sorted() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
76 | * @see cx_array_simple_insert_sorted() |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
78 | #define CX_ARRAY_DECLARE_SIZED(type, name, size_type) \ |
| 16 | 79 | type * name; \ |
| 80 | /** Array size. */ size_type name##_size; \ | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
81 | /** Array capacity. */ size_type name##_capacity |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
82 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
83 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
84 | * Declares variables for an array that can be used with the convenience macros. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
85 | * |
| 22 | 86 | * The size and capacity variables will have type @c size_t. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
87 | * Use #CX_ARRAY_DECLARE_SIZED() to specify a different type. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
88 | * |
| 16 | 89 | * @par Examples |
| 90 | * @code | |
| 91 | * // int array | |
| 92 | * CX_ARRAY_DECLARE(int, myarray) | |
| 93 | * | |
| 94 | * // initializing code | |
| 95 | * cx_array_initialize(myarray, 32); // reserve space for 32 | |
| 96 | * @endcode | |
| 97 | * | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
98 | * @param type the type of the data |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
99 | * @param name the name of the array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
100 | * |
| 16 | 101 | * @see cx_array_initialize() |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
102 | * @see cx_array_simple_add() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
103 | * @see cx_array_simple_copy() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
104 | * @see cx_array_simple_add_sorted() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
105 | * @see cx_array_simple_insert_sorted() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
106 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
107 | #define CX_ARRAY_DECLARE(type, name) CX_ARRAY_DECLARE_SIZED(type, name, size_t) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | /** |
| 16 | 110 | * Initializes an array with the given capacity. |
| 111 | * | |
| 112 | * The type of the capacity depends on the type used during declaration. | |
| 113 | * | |
| 114 | * @par Examples | |
| 115 | * @code | |
| 116 | * CX_ARRAY_DECLARE_SIZED(int, arr1, uint8_t) | |
| 117 | * CX_ARRAY_DECLARE(int, arr2) // size and capacity are implicitly size_t | |
| 118 | * | |
| 119 | * // initializing code | |
| 120 | * cx_array_initialize(arr1, 500); // error: maximum for uint8_t is 255 | |
| 121 | * cx_array_initialize(arr2, 500); // OK | |
| 122 | * @endcode | |
| 123 | * | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | * |
| 21 | 125 | * The memory for the array is allocated with the cxDefaultAllocator. |
| 126 | * | |
| 16 | 127 | * @param array the name of the array |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | * @param capacity the initial capacity |
| 16 | 129 | * @see cx_array_initialize_a() |
| 130 | * @see CX_ARRAY_DECLARE_SIZED() | |
| 131 | * @see CX_ARRAY_DECLARE() | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | #define cx_array_initialize(array, capacity) \ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | array##_capacity = capacity; \ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | array##_size = 0; \ |
| 21 | 136 | array = cxMallocDefault(sizeof(array[0]) * capacity) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | /** |
| 16 | 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 | * | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
145 | * |
| 16 | 146 | * const CxAllocator *al = // ... |
| 147 | * cx_array_initialize_a(al, myarray, 128); | |
| 148 | * // ... | |
| 22 | 149 | * cxFree(al, myarray); // remember to free with the same allocator |
| 16 | 150 | * @endcode |
| 151 | * | |
| 152 | * @param allocator (@c CxAllocator*) the allocator | |
| 153 | * @param array the name of the array | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
154 | * @param capacity the initial capacity |
| 16 | 155 | * @see cx_array_initialize() |
| 156 | * @see CX_ARRAY_DECLARE_SIZED() | |
| 157 | * @see CX_ARRAY_DECLARE() | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
158 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
159 | #define cx_array_initialize_a(allocator, array, capacity) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
160 | array##_capacity = capacity; \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
161 | array##_size = 0; \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
162 | array = cxMalloc(allocator, sizeof(array[0]) * capacity) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
163 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
164 | /** |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | * Defines a reallocation mechanism for arrays. |
| 16 | 166 | * You can create your own, use cx_array_reallocator(), or |
| 167 | * use the #cx_array_default_reallocator. | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | struct cx_array_reallocator_s { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | * Reallocates space for the given array. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | * Implementations are not required to free the original array. |
| 22 | 174 | * This allows reallocation of static or stack memory by allocating heap memory |
| 175 | * and copying the array contents; namely when @c stack_ptr in this struct | |
| 176 | * is not @c NULL and @p array equals @c stack_ptr. | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | * @param array the array to reallocate |
| 21 | 179 | * @param old_capacity the old number of elements |
| 180 | * @param new_capacity the new number of elements | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | * @param elem_size the size of each element |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | * @param alloc a reference to this allocator |
| 16 | 183 | * @return a pointer to the reallocated memory or @c NULL on failure |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | */ |
| 22 | 185 | void *(*realloc)( void *array, size_t old_capacity, size_t new_capacity, |
| 186 | size_t elem_size, struct cx_array_reallocator_s *alloc); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | /** |
| 22 | 189 | * The allocator that shall be used for the reallocations. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | */ |
| 22 | 191 | const CxAllocator *allocator; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | /** |
| 22 | 193 | * Optional pointer to stack memory |
| 194 | * if the array is originally located on the stack. | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | */ |
| 22 | 196 | const void *stack_ptr; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | }; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | /** |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
200 | * Typedef for the array reallocator struct. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
201 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
202 | typedef struct cx_array_reallocator_s CxArrayReallocator; |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
203 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
204 | /** |
| 21 | 205 | * A default array reallocator that is based on the cxDefaultAllocator. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | */ |
| 22 | 207 | CX_EXPORT extern CxArrayReallocator *cx_array_default_reallocator; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | /** |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
210 | * Creates a new array reallocator. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
211 | * |
| 21 | 212 | * When @p allocator is @c NULL, the cxDefaultAllocator will be used. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
213 | * |
| 22 | 214 | * When @p stack_ptr is not @c NULL, the reallocator is supposed to be used |
| 215 | * @em only for the specific array initially located at @p stack_ptr. | |
| 216 | * When reallocation is needed, the reallocator checks if the array is | |
| 217 | * still located at @p stack_ptr and copies the contents to the heap. | |
| 16 | 218 | * |
| 22 | 219 | * @note Invoking this function with both arguments being @c NULL will return a |
| 16 | 220 | * reallocator that behaves like #cx_array_default_reallocator. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
221 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
222 | * @param allocator the allocator this reallocator shall be based on |
| 22 | 223 | * @param stack_ptr the address of the array when the array is initially located |
| 224 | * on the stack or shall not reallocate in place | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
225 | * @return an array reallocator |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | */ |
| 22 | 227 | CX_EXPORT CxArrayReallocator cx_array_reallocator( |
| 228 | const struct cx_allocator_s *allocator, const void *stack_ptr); | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
229 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
230 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
231 | * Reserves memory for additional elements. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
232 | * |
| 16 | 233 | * This function checks if the @p capacity of the array is sufficient to hold |
| 234 | * at least @p size plus @p elem_count elements. If not, a reallocation is | |
| 235 | * performed with the specified @p reallocator. | |
| 236 | * You can create your own reallocator by hand, use #cx_array_default_reallocator, | |
| 237 | * or use the convenience function cx_array_reallocator() to create a custom reallocator. | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
238 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
239 | * This function can be useful to replace subsequent calls to cx_array_copy() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
240 | * with one single cx_array_reserve() and then - after guaranteeing a |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
241 | * sufficient capacity - use simple memmove() or memcpy(). |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
242 | * |
| 16 | 243 | * The @p width in bytes refers to the size and capacity. |
| 244 | * Both must have the same width. | |
| 22 | 245 | * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64-bit |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
246 | * architecture. If set to zero, the native word width is used. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
247 | * |
| 22 | 248 | * @note This function will reserve the minimum required capacity to hold |
| 249 | * the additional elements and does not perform an overallocation. | |
| 250 | * | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
251 | * @param array a pointer to the target array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
252 | * @param size a pointer to the size of the array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
253 | * @param capacity a pointer to the capacity of the array |
| 16 | 254 | * @param width the width in bytes for the @p size and @p capacity or zero for default |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
255 | * @param elem_size the size of one element |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
256 | * @param elem_count the number of expected additional elements |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
257 | * @param reallocator the array reallocator to use |
| 16 | 258 | * (@c NULL defaults to #cx_array_default_reallocator) |
| 259 | * @retval zero success | |
| 260 | * @retval non-zero failure | |
| 261 | * @see cx_array_reallocator() | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
262 | */ |
| 16 | 263 | cx_attr_nonnull_arg(1, 2, 3) |
| 22 | 264 | CX_EXPORT int cx_array_reserve(void **array, void *size, void *capacity, |
| 265 | unsigned width, size_t elem_size, size_t elem_count, | |
| 266 | CxArrayReallocator *reallocator); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | * Copies elements from one array to another. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | * |
| 16 | 271 | * The elements are copied to the @p target array at the specified @p index, |
| 272 | * overwriting possible elements. The @p index does not need to be in range of | |
| 273 | * the current array @p size. If the new index plus the number of elements added | |
| 22 | 274 | * extends the array's size, the remaining @p capacity is used. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | * |
| 16 | 276 | * If the @p capacity is also insufficient to hold the new data, a reallocation |
| 277 | * attempt is made with the specified @p reallocator. | |
| 278 | * You can create your own reallocator by hand, use #cx_array_default_reallocator, | |
| 279 | * or use the convenience function cx_array_reallocator() to create a custom reallocator. | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
280 | * |
| 16 | 281 | * The @p width in bytes refers to the size and capacity. |
| 282 | * Both must have the same width. | |
| 22 | 283 | * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64-bit |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
284 | * architecture. If set to zero, the native word width is used. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | * |
| 22 | 286 | * @note When this function does reallocate the array, it may allocate more |
| 287 | * space than required to avoid further allocations in the near future. | |
| 288 | * | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | * @param target a pointer to the target array |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | * @param size a pointer to the size of the target array |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
291 | * @param capacity a pointer to the capacity of the target array |
| 16 | 292 | * @param width the width in bytes for the @p size and @p capacity or zero for default |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | * @param index the index where the copied elements shall be placed |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | * @param src the source array |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | * @param elem_size the size of one element |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | * @param elem_count the number of elements to copy |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
297 | * @param reallocator the array reallocator to use |
| 16 | 298 | * (@c NULL defaults to #cx_array_default_reallocator) |
| 299 | * @retval zero success | |
| 300 | * @retval non-zero failure | |
| 301 | * @see cx_array_reallocator() | |
| 22 | 302 | * @see cx_array_reserve() |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | */ |
| 16 | 304 | cx_attr_nonnull_arg(1, 2, 3, 6) |
| 22 | 305 | CX_EXPORT int cx_array_copy(void **target, void *size, void *capacity, unsigned width, |
| 306 | size_t index, const void *src, size_t elem_size, size_t elem_count, | |
| 307 | CxArrayReallocator *reallocator); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | /** |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
310 | * Convenience macro that uses cx_array_copy() with a default layout and |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
311 | * the specified reallocator. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
312 | * |
| 16 | 313 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use |
| 314 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 315 | * @param index (@c size_t) the index where the copied elements shall be placed | |
| 316 | * @param src (@c void*) the source array | |
| 317 | * @param count (@c size_t) the number of elements to copy | |
| 318 | * @retval zero success | |
| 319 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
320 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
321 | * @see cx_array_simple_copy() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
322 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
323 | #define cx_array_simple_copy_a(reallocator, array, index, src, count) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
324 | cx_array_copy((void**)&(array), &(array##_size), &(array##_capacity), \ |
| 16 | 325 | sizeof(array##_size), index, src, sizeof((array)[0]), count, \ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
326 | reallocator) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
327 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
328 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
329 | * Convenience macro that uses cx_array_copy() with a default layout and |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
330 | * the default reallocator. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | * |
| 16 | 332 | * @param array the name of the array (NOT a pointer or alias to the array) |
| 333 | * @param index (@c size_t) the index where the copied elements shall be placed | |
| 334 | * @param src (@c void*) the source array | |
| 335 | * @param count (@c size_t) the number of elements to copy | |
| 336 | * @retval zero success | |
| 337 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
338 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
339 | * @see cx_array_simple_copy_a() |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | #define cx_array_simple_copy(array, index, src, count) \ |
| 16 | 342 | cx_array_simple_copy_a(NULL, array, index, src, count) |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
343 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
344 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
345 | * Convenience macro that uses cx_array_reserve() with a default layout and |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
346 | * the specified reallocator. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
347 | * |
| 16 | 348 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use |
| 349 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 350 | * @param count (@c size_t) the number of expected @em additional elements | |
| 351 | * @retval zero success | |
| 352 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
353 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
354 | * @see cx_array_simple_reserve() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
355 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
356 | #define cx_array_simple_reserve_a(reallocator, array, count) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
357 | cx_array_reserve((void**)&(array), &(array##_size), &(array##_capacity), \ |
| 16 | 358 | sizeof(array##_size), sizeof((array)[0]), count, \ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
359 | reallocator) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
360 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
361 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
362 | * Convenience macro that uses cx_array_reserve() with a default layout and |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
363 | * the default reallocator. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
364 | * |
| 16 | 365 | * @param array the name of the array (NOT a pointer or alias to the array) |
| 366 | * @param count (@c size_t) the number of expected additional elements | |
| 367 | * @retval zero success | |
| 368 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
369 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
370 | * @see cx_array_simple_reserve_a() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
371 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
372 | #define cx_array_simple_reserve(array, count) \ |
| 16 | 373 | cx_array_simple_reserve_a(NULL, array, count) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
375 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | * Adds an element to an array with the possibility of allocating more space. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | * |
| 16 | 378 | * The element @p elem is added to the end of the @p target array which contains |
| 379 | * @p size elements, already. The @p capacity must point to a variable denoting | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
380 | * the current maximum number of elements the array can hold. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
381 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
382 | * If the capacity is insufficient to hold the new element, an attempt to |
| 16 | 383 | * increase the @p capacity is made and the new capacity is written back. |
| 384 | * | |
| 385 | * The \@ SIZE_TYPE is flexible and can be any unsigned integer type. | |
| 386 | * It is important, however, that @p size and @p capacity are pointers to | |
| 387 | * variables of the same type. | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
388 | * |
| 16 | 389 | * @param target (@c void**) a pointer to the target array |
| 390 | * @param size (@c SIZE_TYPE*) a pointer to the size of the target array | |
| 391 | * @param capacity (@c SIZE_TYPE*) a pointer to the capacity of the target array | |
| 392 | * @param elem_size (@c size_t) the size of one element | |
| 393 | * @param elem (@c void*) a pointer to the element to add | |
| 394 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 395 | * @retval zero success | |
| 396 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
397 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
398 | #define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \ |
| 16 | 399 | cx_array_copy((void**)(target), size, capacity, sizeof(*(size)), \ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
400 | *(size), elem, elem_size, 1, reallocator) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
401 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
402 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
403 | * Convenience macro that uses cx_array_add() with a default layout and |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
404 | * the specified reallocator. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
405 | * |
| 16 | 406 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use |
| 407 | * @param array the name of the array (NOT a pointer or alias to the array) | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
408 | * @param elem the element to add (NOT a pointer, address is automatically taken) |
| 16 | 409 | * @retval zero success |
| 410 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
411 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
412 | * @see cx_array_simple_add() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
413 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
414 | #define cx_array_simple_add_a(reallocator, array, elem) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
415 | cx_array_simple_copy_a(reallocator, array, array##_size, &(elem), 1) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
416 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
417 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
418 | * Convenience macro that uses cx_array_add() with a default layout and |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
419 | * the default reallocator. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
420 | * |
| 16 | 421 | * @param array the name of the array (NOT a pointer or alias to the array) |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
422 | * @param elem the element to add (NOT a pointer, address is automatically taken) |
| 16 | 423 | * @retval zero success |
| 424 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
425 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
426 | * @see cx_array_simple_add_a() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
427 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
428 | #define cx_array_simple_add(array, elem) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
429 | cx_array_simple_add_a(cx_array_default_reallocator, array, elem) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
430 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
431 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
432 | * Inserts a sorted array into another sorted array. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
433 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
434 | * If either the target or the source array is not already sorted with respect |
| 16 | 435 | * to the specified @p cmp_func, the behavior is undefined. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
436 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
437 | * If the capacity is insufficient to hold the new data, a reallocation |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
438 | * attempt is made. |
| 16 | 439 | * You can create your own reallocator by hand, use #cx_array_default_reallocator, |
| 440 | * or use the convenience function cx_array_reallocator() to create a custom reallocator. | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
441 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
442 | * @param target a pointer to the target array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
443 | * @param size a pointer to the size of the target array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
444 | * @param capacity a pointer to the capacity of the target array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
445 | * @param cmp_func the compare function for the elements |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
446 | * @param src the source array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
447 | * @param elem_size the size of one element |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
448 | * @param elem_count the number of elements to insert |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
449 | * @param reallocator the array reallocator to use |
| 16 | 450 | * (@c NULL defaults to #cx_array_default_reallocator) |
| 451 | * @retval zero success | |
| 452 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
453 | */ |
| 16 | 454 | cx_attr_nonnull_arg(1, 2, 3, 5) |
| 22 | 455 | CX_EXPORT int cx_array_insert_sorted(void **target, size_t *size, size_t *capacity, |
| 456 | cx_compare_func cmp_func, const void *src, size_t elem_size, size_t elem_count, | |
| 457 | CxArrayReallocator *reallocator); | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
458 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
459 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
460 | * Inserts an element into a sorted array. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
461 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
462 | * If the target array is not already sorted with respect |
| 16 | 463 | * to the specified @p cmp_func, the behavior is undefined. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
464 | * |
| 22 | 465 | * If the capacity is not enough to hold the new data, a reallocation |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
466 | * attempt is made. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | * |
| 16 | 468 | * The \@ SIZE_TYPE is flexible and can be any unsigned integer type. |
| 469 | * It is important, however, that @p size and @p capacity are pointers to | |
| 470 | * variables of the same type. | |
| 471 | * | |
| 472 | * @param target (@c void**) a pointer to the target array | |
| 473 | * @param size (@c SIZE_TYPE*) a pointer to the size of the target array | |
| 474 | * @param capacity (@c SIZE_TYPE*) a pointer to the capacity of the target array | |
| 475 | * @param elem_size (@c size_t) the size of one element | |
| 476 | * @param elem (@c void*) a pointer to the element to add | |
| 477 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 478 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 479 | * @retval zero success | |
| 480 | * @retval non-zero failure | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
482 | #define cx_array_add_sorted(target, size, capacity, elem_size, elem, cmp_func, reallocator) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
483 | cx_array_insert_sorted((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
485 | /** |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
486 | * Convenience macro for cx_array_add_sorted() with a default |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
487 | * layout and the specified reallocator. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
488 | * |
| 16 | 489 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use |
| 490 | * @param array the name of the array (NOT a pointer or alias to the array) | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
491 | * @param elem the element to add (NOT a pointer, address is automatically taken) |
| 16 | 492 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements |
| 493 | * @retval zero success | |
| 494 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
495 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
496 | * @see cx_array_simple_add_sorted() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
497 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
498 | #define cx_array_simple_add_sorted_a(reallocator, array, elem, cmp_func) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
499 | cx_array_add_sorted(&array, &(array##_size), &(array##_capacity), \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
500 | sizeof((array)[0]), &(elem), cmp_func, reallocator) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
501 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
502 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
503 | * Convenience macro for cx_array_add_sorted() with a default |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
504 | * layout and the default reallocator. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505 | * |
| 16 | 506 | * @param array the name of the array (NOT a pointer or alias to the array) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
507 | * @param elem the element to add (NOT a pointer, address is automatically taken) |
| 16 | 508 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements |
| 509 | * @retval zero success | |
| 510 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
511 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
512 | * @see cx_array_simple_add_sorted_a() |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
514 | #define cx_array_simple_add_sorted(array, elem, cmp_func) \ |
| 16 | 515 | cx_array_simple_add_sorted_a(NULL, array, elem, cmp_func) |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
516 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
517 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
518 | * Convenience macro for cx_array_insert_sorted() with a default |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
519 | * layout and the specified reallocator. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
520 | * |
| 16 | 521 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use |
| 522 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 523 | * @param src (@c void*) pointer to the source array | |
| 524 | * @param n (@c size_t) number of elements in the source array | |
| 525 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 526 | * @retval zero success | |
| 527 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
528 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
529 | * @see cx_array_simple_insert_sorted() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
530 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
531 | #define cx_array_simple_insert_sorted_a(reallocator, array, src, n, cmp_func) \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
532 | cx_array_insert_sorted((void**)(&array), &(array##_size), &(array##_capacity), \ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
533 | cmp_func, src, sizeof((array)[0]), n, reallocator) |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
534 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
535 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
536 | * Convenience macro for cx_array_insert_sorted() with a default |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
537 | * layout and the default reallocator. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
538 | * |
| 16 | 539 | * @param array the name of the array (NOT a pointer or alias to the array) |
| 540 | * @param src (@c void*) pointer to the source array | |
| 541 | * @param n (@c size_t) number of elements in the source array | |
| 542 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 543 | * @retval zero success | |
| 544 | * @retval non-zero failure | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
545 | * @see CX_ARRAY_DECLARE() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
546 | * @see cx_array_simple_insert_sorted_a() |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
547 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
548 | #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \ |
| 16 | 549 | cx_array_simple_insert_sorted_a(NULL, array, src, n, cmp_func) |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
550 | |
| 22 | 551 | |
| 552 | /** | |
| 553 | * Inserts a sorted array into another sorted array, avoiding duplicates. | |
| 554 | * | |
| 555 | * If either the target or the source array is not already sorted with respect | |
| 556 | * to the specified @p cmp_func, the behavior is undefined. | |
| 557 | * | |
| 558 | * If the capacity is insufficient to hold the new data, a reallocation | |
| 559 | * attempt is made. | |
| 560 | * You can create your own reallocator by hand, use #cx_array_default_reallocator, | |
| 561 | * or use the convenience function cx_array_reallocator() to create a custom reallocator. | |
| 562 | * | |
| 563 | * @param target a pointer to the target array | |
| 564 | * @param size a pointer to the size of the target array | |
| 565 | * @param capacity a pointer to the capacity of the target array | |
| 566 | * @param cmp_func the compare function for the elements | |
| 567 | * @param src the source array | |
| 568 | * @param elem_size the size of one element | |
| 569 | * @param elem_count the number of elements to insert | |
| 570 | * @param reallocator the array reallocator to use | |
| 571 | * (@c NULL defaults to #cx_array_default_reallocator) | |
| 572 | * @retval zero success | |
| 573 | * @retval non-zero failure | |
| 574 | */ | |
| 575 | cx_attr_nonnull_arg(1, 2, 3, 5) | |
| 576 | CX_EXPORT int cx_array_insert_unique(void **target, size_t *size, size_t *capacity, | |
| 577 | cx_compare_func cmp_func, const void *src, size_t elem_size, size_t elem_count, | |
| 578 | CxArrayReallocator *reallocator); | |
| 579 | ||
| 580 | /** | |
| 581 | * Inserts an element into a sorted array if it does not exist. | |
| 582 | * | |
| 583 | * If the target array is not already sorted with respect | |
| 584 | * to the specified @p cmp_func, the behavior is undefined. | |
| 585 | * | |
| 586 | * If the capacity is insufficient to hold the new data, a reallocation | |
| 587 | * attempt is made. | |
| 588 | * | |
| 589 | * The \@ SIZE_TYPE is flexible and can be any unsigned integer type. | |
| 590 | * It is important, however, that @p size and @p capacity are pointers to | |
| 591 | * variables of the same type. | |
| 592 | * | |
| 593 | * @param target (@c void**) a pointer to the target array | |
| 594 | * @param size (@c SIZE_TYPE*) a pointer to the size of the target array | |
| 595 | * @param capacity (@c SIZE_TYPE*) a pointer to the capacity of the target array | |
| 596 | * @param elem_size (@c size_t) the size of one element | |
| 597 | * @param elem (@c void*) a pointer to the element to add | |
| 598 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 599 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 600 | * @retval zero success (also when the element was already present) | |
| 601 | * @retval non-zero failure | |
| 602 | */ | |
| 603 | #define cx_array_add_unique(target, size, capacity, elem_size, elem, cmp_func, reallocator) \ | |
| 604 | cx_array_insert_unique((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator) | |
| 605 | ||
| 606 | /** | |
| 607 | * Convenience macro for cx_array_add_unique() with a default | |
| 608 | * layout and the specified reallocator. | |
| 609 | * | |
| 610 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 611 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 612 | * @param elem the element to add (NOT a pointer, address is automatically taken) | |
| 613 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 614 | * @retval zero success | |
| 615 | * @retval non-zero failure | |
| 616 | * @see CX_ARRAY_DECLARE() | |
| 617 | * @see cx_array_simple_add_unique() | |
| 618 | */ | |
| 619 | #define cx_array_simple_add_unique_a(reallocator, array, elem, cmp_func) \ | |
| 620 | cx_array_add_unique(&array, &(array##_size), &(array##_capacity), \ | |
| 621 | sizeof((array)[0]), &(elem), cmp_func, reallocator) | |
| 622 | ||
| 623 | /** | |
| 624 | * Convenience macro for cx_array_add_unique() with a default | |
| 625 | * layout and the default reallocator. | |
| 626 | * | |
| 627 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 628 | * @param elem the element to add (NOT a pointer, address is automatically taken) | |
| 629 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 630 | * @retval zero success | |
| 631 | * @retval non-zero failure | |
| 632 | * @see CX_ARRAY_DECLARE() | |
| 633 | * @see cx_array_simple_add_unique_a() | |
| 634 | */ | |
| 635 | #define cx_array_simple_add_unique(array, elem, cmp_func) \ | |
| 636 | cx_array_simple_add_unique_a(NULL, array, elem, cmp_func) | |
| 637 | ||
| 638 | /** | |
| 639 | * Convenience macro for cx_array_insert_unique() with a default | |
| 640 | * layout and the specified reallocator. | |
| 641 | * | |
| 642 | * @param reallocator (@c CxArrayReallocator*) the array reallocator to use | |
| 643 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 644 | * @param src (@c void*) pointer to the source array | |
| 645 | * @param n (@c size_t) number of elements in the source array | |
| 646 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 647 | * @retval zero success | |
| 648 | * @retval non-zero failure | |
| 649 | * @see CX_ARRAY_DECLARE() | |
| 650 | * @see cx_array_simple_insert_unique() | |
| 651 | */ | |
| 652 | #define cx_array_simple_insert_unique_a(reallocator, array, src, n, cmp_func) \ | |
| 653 | cx_array_insert_unique((void**)(&array), &(array##_size), &(array##_capacity), \ | |
| 654 | cmp_func, src, sizeof((array)[0]), n, reallocator) | |
| 655 | ||
| 656 | /** | |
| 657 | * Convenience macro for cx_array_insert_unique() with a default | |
| 658 | * layout and the default reallocator. | |
| 659 | * | |
| 660 | * @param array the name of the array (NOT a pointer or alias to the array) | |
| 661 | * @param src (@c void*) pointer to the source array | |
| 662 | * @param n (@c size_t) number of elements in the source array | |
| 663 | * @param cmp_func (@c cx_cmp_func) the compare function for the elements | |
| 664 | * @retval zero success | |
| 665 | * @retval non-zero failure | |
| 666 | * @see CX_ARRAY_DECLARE() | |
| 667 | * @see cx_array_simple_insert_unique_a() | |
| 668 | */ | |
| 669 | #define cx_array_simple_insert_unique(array, src, n, cmp_func) \ | |
| 670 | cx_array_simple_insert_unique_a(NULL, array, src, n, cmp_func) | |
| 671 | ||
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
672 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
673 | * Searches the largest lower bound in a sorted array. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
674 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
675 | * In other words, this function returns the index of the largest element |
| 16 | 676 | * in @p arr that is less or equal to @p elem with respect to @p cmp_func. |
| 677 | * When no such element exists, @p size is returned. | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
678 | * |
| 23 | 679 | * When such an element exists more than once, the largest index of all those |
| 680 | * elements is returned. | |
| 681 | * | |
| 16 | 682 | * If @p elem is contained in the array, this is identical to |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
683 | * #cx_array_binary_search(). |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
684 | * |
| 16 | 685 | * If the array is not sorted with respect to the @p cmp_func, the behavior |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
686 | * is undefined. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
687 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
688 | * @param arr the array to search |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
689 | * @param size the size of the array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
690 | * @param elem_size the size of one element |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
691 | * @param elem the element to find |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
692 | * @param cmp_func the compare function |
| 16 | 693 | * @return the index of the largest lower bound, or @p size |
| 694 | * @see cx_array_binary_search_sup() | |
| 695 | * @see cx_array_binary_search() | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
696 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
697 | cx_attr_nonnull |
| 22 | 698 | CX_EXPORT size_t cx_array_binary_search_inf(const void *arr, size_t size, |
| 699 | size_t elem_size, const void *elem, cx_compare_func cmp_func); | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
700 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
701 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
702 | * Searches an item in a sorted array. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
703 | * |
| 23 | 704 | * When such an element exists more than once, the largest index of all those |
| 705 | * elements is returned. | |
| 706 | * | |
| 16 | 707 | * If the array is not sorted with respect to the @p cmp_func, the behavior |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
708 | * is undefined. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
709 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
710 | * @param arr the array to search |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
711 | * @param size the size of the array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
712 | * @param elem_size the size of one element |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
713 | * @param elem the element to find |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
714 | * @param cmp_func the compare function |
| 16 | 715 | * @return the index of the element in the array, or @p size if the element |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
716 | * cannot be found |
| 16 | 717 | * @see cx_array_binary_search_inf() |
| 718 | * @see cx_array_binary_search_sup() | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
719 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
720 | cx_attr_nonnull |
| 22 | 721 | CX_EXPORT size_t cx_array_binary_search(const void *arr, size_t size, |
| 722 | size_t elem_size, const void *elem, cx_compare_func cmp_func); | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
723 | |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
724 | /** |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
725 | * Searches the smallest upper bound in a sorted array. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
726 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
727 | * In other words, this function returns the index of the smallest element |
| 16 | 728 | * in @p arr that is greater or equal to @p elem with respect to @p cmp_func. |
| 729 | * When no such element exists, @p size is returned. | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
730 | * |
| 23 | 731 | * When such an element exists more than once, the smallest index of all those |
| 732 | * elements is returned. | |
| 733 | * | |
| 16 | 734 | * If @p elem is contained in the array, this is identical to |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
735 | * #cx_array_binary_search(). |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
736 | * |
| 16 | 737 | * If the array is not sorted with respect to the @p cmp_func, the behavior |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
738 | * is undefined. |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
739 | * |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
740 | * @param arr the array to search |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
741 | * @param size the size of the array |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
742 | * @param elem_size the size of one element |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
743 | * @param elem the element to find |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
744 | * @param cmp_func the compare function |
| 16 | 745 | * @return the index of the smallest upper bound, or @p size |
| 746 | * @see cx_array_binary_search_inf() | |
| 747 | * @see cx_array_binary_search() | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
748 | */ |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
749 | cx_attr_nonnull |
| 22 | 750 | CX_EXPORT size_t cx_array_binary_search_sup(const void *arr, size_t size, |
| 751 | size_t elem_size, const void *elem, cx_compare_func cmp_func); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
752 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
753 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754 | * Swaps two array elements. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
755 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756 | * @param arr the array |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
757 | * @param elem_size the element size |
| 22 | 758 | * @param idx1 index of the first element |
| 759 | * @param idx2 index of the second element | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
760 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
761 | cx_attr_nonnull |
| 22 | 762 | CX_EXPORT void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
763 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
764 | /** |
| 16 | 765 | * Allocates an array list for storing elements with @p elem_size bytes each. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
766 | * |
| 16 | 767 | * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
| 22 | 768 | * copies of the added elements, and the compare function will be automatically set |
| 16 | 769 | * to cx_cmp_ptr(), if none is given. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
771 | * @param allocator the allocator for allocating the list memory |
| 21 | 772 | * (if @c NULL, the cxDefaultAllocator will be used) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
773 | * @param comparator the comparator for the elements |
| 16 | 774 | * (if @c NULL, and the list is not storing pointers, sort and find |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | * functions will not work) |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776 | * @param elem_size the size of each element in bytes |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777 | * @param initial_capacity the initial number of elements the array can store |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778 | * @return the created list |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
779 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
780 | cx_attr_nodiscard |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
781 | cx_attr_malloc |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
782 | cx_attr_dealloc(cxListFree, 1) |
| 22 | 783 | CX_EXPORT CxList *cxArrayListCreate(const CxAllocator *allocator, |
| 784 | cx_compare_func comparator, size_t elem_size, size_t initial_capacity); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
785 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
786 | /** |
| 16 | 787 | * Allocates an array list for storing elements with @p elem_size bytes each. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
788 | * |
| 16 | 789 | * The list will use the cxDefaultAllocator and @em NO compare function. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
790 | * If you want to call functions that need a compare function, you have to |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791 | * set it immediately after creation or use cxArrayListCreate(). |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
792 | * |
| 16 | 793 | * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
| 794 | * copies of the added elements and the compare function will be automatically set | |
| 21 | 795 | * to cx_cmp_ptr(). |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
796 | * |
| 16 | 797 | * @param elem_size (@c size_t) the size of each element in bytes |
| 798 | * @param initial_capacity (@c size_t) the initial number of elements the array can store | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
799 | * @return the created list |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
800 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
801 | #define cxArrayListCreateSimple(elem_size, initial_capacity) \ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
802 | cxArrayListCreate(NULL, NULL, elem_size, initial_capacity) |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
803 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
804 | #ifdef __cplusplus |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
805 | } // extern "C" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
806 | #endif |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
807 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
808 | #endif // UCX_ARRAY_LIST_H |