Fri, 19 Dec 2025 17:22:03 +0100
update ucx
|
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 map.h |
| 30 | * @brief Interface for map implementations. | |
| 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 | #ifndef UCX_MAP_H |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #define UCX_MAP_H |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "common.h" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "collection.h" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include "string.h" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #include "hash_key.h" |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
| 22 | 44 | #ifndef UCX_LIST_H |
| 45 | // forward-declare CxList | |
| 46 | typedef struct cx_list_s CxList; | |
| 47 | #endif | |
| 48 | ||
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | #ifdef __cplusplus |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | extern "C" { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | #endif |
|
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 | /** Type for the UCX map. */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | typedef struct cx_map_s CxMap; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | /** Type for a map entry. */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | typedef struct cx_map_entry_s CxMapEntry; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
| 16 | 59 | /** Type for a map iterator. */ |
| 60 | typedef struct cx_map_iterator_s CxMapIterator; | |
| 61 | ||
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | /** Type for map class definitions. */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | typedef struct cx_map_class_s cx_map_class; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | /** Structure for the UCX map. */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | struct cx_map_s { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | * Base attributes. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | CX_COLLECTION_BASE; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | /** The map class definition. */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | cx_map_class *cl; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | }; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | /** |
| 16 | 76 | * A map entry. |
| 77 | */ | |
| 78 | struct cx_map_entry_s { | |
| 79 | /** | |
| 80 | * A pointer to the key. | |
| 81 | */ | |
| 82 | const CxHashKey *key; | |
| 83 | /** | |
| 84 | * A pointer to the value. | |
| 85 | */ | |
| 86 | void *value; | |
| 87 | }; | |
| 88 | ||
| 89 | /** | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | * The type of iterator for a map. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | enum cx_map_iterator_type { |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | * Iterates over key/value pairs. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | CX_MAP_ITERATOR_PAIRS, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | * Iterates over keys only. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | CX_MAP_ITERATOR_KEYS, |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | * Iterates over values only. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | CX_MAP_ITERATOR_VALUES |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | }; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | /** |
| 16 | 108 | * Internal iterator struct - use CxMapIterator. |
| 109 | */ | |
| 110 | struct cx_map_iterator_s { | |
| 111 | /** | |
| 112 | * Inherited common data for all iterators. | |
| 113 | */ | |
| 114 | CX_ITERATOR_BASE; | |
| 115 | ||
| 116 | /** | |
| 117 | * Handle for the source map. | |
| 118 | */ | |
| 22 | 119 | CxMap *map; |
| 16 | 120 | |
| 121 | /** | |
| 122 | * Handle for the current element. | |
| 123 | * | |
| 124 | * @attention Depends on the map implementation, do not assume a type (better: do not use!). | |
| 125 | */ | |
| 126 | void *elem; | |
| 127 | ||
| 128 | /** | |
| 129 | * Reserved memory for a map entry. | |
| 130 | * | |
| 131 | * If a map implementation uses an incompatible layout, the iterator needs something | |
| 132 | * to point to during iteration which @em is compatible. | |
| 133 | */ | |
| 134 | CxMapEntry entry; | |
| 135 | ||
| 136 | /** | |
| 137 | * Field for storing the current slot number. | |
| 138 | * | |
| 139 | * (Used internally) | |
| 140 | */ | |
| 141 | size_t slot; | |
| 142 | ||
| 143 | /** | |
| 144 | * Counts the elements successfully. | |
| 145 | * It usually does not denote a stable index within the map as it would be for arrays. | |
| 146 | */ | |
| 147 | size_t index; | |
| 148 | ||
| 149 | /** | |
| 150 | * The size of a value stored in this map. | |
| 151 | */ | |
| 152 | size_t elem_size; | |
| 153 | ||
| 154 | /** | |
| 155 | * May contain the total number of elements, if known. | |
| 156 | * Set to @c SIZE_MAX when the total number is unknown during iteration. | |
| 157 | * | |
| 158 | * @remark The UCX implementations of #CxMap always know the number of elements they store. | |
| 159 | */ | |
| 160 | size_t elem_count; | |
| 161 | ||
| 162 | /** | |
| 163 | * The type of this iterator. | |
| 164 | */ | |
| 165 | enum cx_map_iterator_type type; | |
| 166 | }; | |
| 167 | ||
| 168 | /** | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | * The class definition for arbitrary maps. |
|
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 | struct cx_map_class_s { |
|
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 | * Deallocates the entire memory. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
175 | void (*deallocate)(struct cx_map_s *map); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | |
|
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 | * Removes all elements. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | */ |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | void (*clear)(struct cx_map_s *map); |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | * Add or overwrite an element. |
| 22 | 184 | * If the @p value is @c NULL, the implementation |
| 185 | * shall only allocate memory instead of adding an existing value to the map. | |
| 31 | 186 | * Returns a map entry where the pointer to the key is @c NULL if allocation fails. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | */ |
| 31 | 188 | CxMapEntry (*put)(CxMap *map, CxHashKey key, void *value); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | * Returns an element. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | */ |
| 22 | 193 | void *(*get)(const CxMap *map, CxHashKey key); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | * Removes an element. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
197 | * |
| 16 | 198 | * Implementations SHALL check if @p targetbuf is set and copy the elements |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
199 | * to the buffer without invoking any destructor. |
| 16 | 200 | * When @p targetbuf is not set, the destructors SHALL be invoked. |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
201 | * |
| 16 | 202 | * The function SHALL return zero when the @p key was found and |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
203 | * non-zero, otherwise. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | */ |
| 22 | 205 | int (*remove)(CxMap *map, CxHashKey key, void *targetbuf); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | * Creates an iterator for this map. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | */ |
| 16 | 210 | CxMapIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | }; |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | * A shared instance of an empty map. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | * |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
216 | * Writing to that map is not allowed. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | * |
| 22 | 218 | * You can use this as a placeholder for initializing CxMap pointers |
| 16 | 219 | * for which you do not want to reserve memory right from the beginning. |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | */ |
| 22 | 221 | CX_EXPORT extern CxMap *const cxEmptyMap; |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | * Deallocates the memory of the specified map. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | * |
| 16 | 226 | * Also calls the content destructor functions for each element, if specified. |
| 227 | * | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
228 | * @param map the map to be freed |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | */ |
| 22 | 230 | CX_EXPORT void cxMapFree(CxMap *map); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | * Clears a map by removing all elements. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | * |
| 16 | 236 | * Also calls the content destructor functions for each element, if specified. |
| 237 | * | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | * @param map the map to be cleared |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
240 | cx_attr_nonnull |
| 22 | 241 | CX_EXPORT void cxMapClear(CxMap *map); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | * Returns the number of elements in this map. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | * |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | * @param map the map |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | * @return the number of stored elements |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
249 | cx_attr_nonnull |
| 22 | 250 | CX_EXPORT size_t cxMapSize(const CxMap *map); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | * Creates a value iterator for a map. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | * |
| 16 | 255 | * When the map is storing pointers, those pointers are returned. |
| 256 | * Otherwise, the iterator iterates over pointers to the memory within the map where the | |
| 257 | * respective elements are stored. | |
| 258 | * | |
| 259 | * @note An iterator iterates over all elements successively. Therefore, the order | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | * |
| 22 | 262 | * @param map the map to create the iterator for (can be @c NULL) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | * @return an iterator for the currently stored values |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
265 | cx_attr_nodiscard |
| 22 | 266 | CX_EXPORT CxMapIterator cxMapIteratorValues(const CxMap *map); |
|
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 | * Creates a key iterator for a map. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | * |
| 22 | 271 | * The elements of the iterator are keys of type CxHashKey, and the pointer returned |
| 16 | 272 | * during iterator shall be treated as @c const @c CxHashKey* . |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | * |
| 16 | 274 | * @note An iterator iterates over all elements successively. Therefore, the order |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | * |
| 22 | 277 | * @param map the map to create the iterator for (can be @c NULL) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | * @return an iterator for the currently stored keys |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
280 | cx_attr_nodiscard |
| 22 | 281 | CX_EXPORT CxMapIterator cxMapIteratorKeys(const CxMap *map); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | * Creates an iterator for a map. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | * |
| 22 | 286 | * The elements of the iterator are key/value pairs of type CxMapEntry, and the pointer returned |
| 16 | 287 | * during iterator shall be treated as @c const @c CxMapEntry* . |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | * |
| 16 | 289 | * @note An iterator iterates over all elements successively. Therefore, the order |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | * |
| 22 | 292 | * @param map the map to create the iterator for (can be @c NULL) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | * @return an iterator for the currently stored entries |
| 22 | 294 | * @see cxMapIteratorKeys() |
| 295 | * @see cxMapIteratorValues() | |
| 296 | */ | |
| 297 | cx_attr_nodiscard | |
| 298 | CX_EXPORT CxMapIterator cxMapIterator(const CxMap *map); | |
| 299 | ||
| 300 | /** | |
| 301 | * Puts a key/value-pair into the map. | |
| 302 | * | |
| 303 | * A possible existing value will be overwritten. | |
| 304 | * If destructor functions are specified, they are called for | |
| 305 | * the overwritten element. | |
| 306 | * | |
| 307 | * If this map is storing pointers, the @p value pointer is written | |
| 308 | * to the map. Otherwise, the memory is copied from @p value with | |
| 309 | * memcpy(). | |
| 310 | * | |
| 311 | * The @p key is always copied. | |
| 312 | * | |
| 313 | * @param map the map | |
| 314 | * @param key the key | |
| 315 | * @param value the value | |
| 316 | * @retval zero success | |
| 317 | * @retval non-zero value on memory allocation failure | |
| 318 | * @see cxMapPut() | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
320 | cx_attr_nonnull |
| 22 | 321 | CX_EXPORT int cx_map_put(CxMap *map, CxHashKey key, void *value); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | * Puts a key/value-pair into the map. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | * |
| 16 | 326 | * A possible existing value will be overwritten. |
| 327 | * If destructor functions are specified, they are called for | |
| 328 | * the overwritten element. | |
| 329 | * | |
| 330 | * If this map is storing pointers, the @p value pointer is written | |
| 331 | * to the map. Otherwise, the memory is copied from @p value with | |
| 332 | * memcpy(). | |
| 333 | * | |
| 334 | * The @p key is always copied. | |
| 335 | * | |
| 336 | * @param map (@c CxMap*) the map | |
| 22 | 337 | * @param key (any supported key type) the key |
| 16 | 338 | * @param value (@c void*) the value |
| 339 | * @retval zero success | |
| 340 | * @retval non-zero value on memory allocation failure | |
| 22 | 341 | * @see CX_HASH_KEY() |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | */ |
| 22 | 343 | #define cxMapPut(map, key, value) cx_map_put(map, CX_HASH_KEY(key), value) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | /** |
| 22 | 346 | * Allocates memory for a value in the map associated with the specified key. |
| 347 | * | |
| 348 | * A possible existing value will be overwritten. | |
| 349 | * If destructor functions are specified, they are called for | |
| 350 | * the overwritten element. | |
| 351 | * | |
| 352 | * If the map is storing pointers, this function returns a @c void** pointer, | |
| 353 | * meaning a pointer to that pointer. | |
| 354 | * | |
| 355 | * The @p key is always copied. | |
| 356 | * | |
| 357 | * @param map the map | |
| 358 | * @param key the key | |
| 359 | * @return the pointer to the allocated memory or @c NULL if allocation fails | |
| 360 | * @see cxMapEmplace() | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361 | */ |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
362 | cx_attr_nonnull |
| 22 | 363 | CX_EXPORT void *cx_map_emplace(CxMap *map, CxHashKey key); |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | /** |
| 22 | 366 | * Allocates memory for a value in the map associated with the specified key. |
| 367 | * | |
| 368 | * A possible existing value will be overwritten. | |
| 369 | * If destructor functions are specified, they are called for | |
| 370 | * the overwritten element. | |
| 371 | * | |
| 372 | * If the map is storing pointers, this function returns a @c void** pointer, | |
| 373 | * meaning a pointer to that pointer. | |
| 374 | * | |
| 375 | * The @p key is always copied. | |
| 376 | * | |
| 377 | * @param map (@c CxMap*) the map | |
| 378 | * @param key (any supported key type) the key | |
| 379 | * @return the pointer to the allocated memory or @c NULL if allocation fails | |
| 380 | * @see CX_HASH_KEY() | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | */ |
| 22 | 382 | #define cxMapEmplace(map, key) cx_map_emplace(map, CX_HASH_KEY(key)) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | /** |
| 22 | 385 | * Retrieves a value by using a key. |
| 386 | * | |
| 387 | * If this map is storing pointers, the stored pointer is returned. | |
| 388 | * Otherwise, a pointer to the element within the map's memory | |
| 389 | * is returned (which is valid as long as the element stays in the map). | |
| 390 | * | |
| 391 | * @param map the map | |
| 392 | * @param key the key | |
| 393 | * @return the value | |
| 394 | * @see cxMapGet() | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395 | */ |
| 22 | 396 | cx_attr_nonnull cx_attr_nodiscard |
| 397 | CX_EXPORT void *cx_map_get(const CxMap *map, CxHashKey key); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | * Retrieves a value by using a key. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | * |
| 16 | 402 | * If this map is storing pointers, the stored pointer is returned. |
| 403 | * Otherwise, a pointer to the element within the map's memory | |
| 404 | * is returned (which is valid as long as the element stays in the map). | |
| 405 | * | |
| 406 | * @param map (@c CxMap*) the map | |
| 22 | 407 | * @param key (any supported key type) the key |
| 408 | * @return (@c void*) the value or @c NULL when no value with that @p key exists | |
| 409 | * @see CX_HASH_KEY() | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | */ |
| 22 | 411 | #define cxMapGet(map, key) cx_map_get(map, CX_HASH_KEY(key)) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | /** |
| 22 | 414 | * Checks if a map contains a specific key. |
| 415 | * | |
| 416 | * @param map (@c CxMap*) the map | |
| 417 | * @param key (any supported key type) the key | |
| 418 | * @retval true if the key exists in the map | |
| 419 | * @retval false if the key does not exist in the map | |
| 420 | * @see CX_HASH_KEY() | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | */ |
| 22 | 422 | #define cxMapContains(map, key) (cxMapGet(map, key) != NULL) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | * Removes a key/value-pair from the map by using the key. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426 | * |
| 22 | 427 | * Invokes the destructor functions, if any, on the removed element if and only if the |
| 428 | * @p targetbuf is @c NULL. | |
| 429 | * | |
| 430 | * @param map the map | |
| 431 | * @param key the key | |
| 432 | * @param targetbuf the optional buffer where the removed element shall be copied to | |
| 433 | * @retval zero success | |
| 434 | * @retval non-zero the key was not found | |
| 435 | * | |
| 436 | * @see cxMapRemove() | |
| 437 | * @see cxMapRemoveAndGet() | |
| 438 | */ | |
| 439 | cx_attr_nonnull_arg(1) | |
| 440 | CX_EXPORT int cx_map_remove(CxMap *map, CxHashKey key, void *targetbuf); | |
| 441 | ||
| 442 | /** | |
| 443 | * Removes a key/value-pair from the map by using the key. | |
| 444 | * | |
| 445 | * Always invokes the destructor functions, if any, on the removed element. | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446 | * |
| 16 | 447 | * @param map (@c CxMap*) the map |
| 22 | 448 | * @param key (any supported key type) the key |
| 16 | 449 | * @retval zero success |
| 450 | * @retval non-zero the key was not found | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
451 | * |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | * @see cxMapRemoveAndGet() |
| 22 | 453 | * @see CX_HASH_KEY() |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454 | */ |
| 22 | 455 | #define cxMapRemove(map, key) cx_map_remove(map, CX_HASH_KEY(key), NULL) |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457 | /** |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | * Removes a key/value-pair from the map by using the key. |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | * |
| 16 | 460 | * This function will copy the contents of the removed element |
| 461 | * to the target buffer, which must be guaranteed to be large enough | |
| 462 | * to hold the element (the map's element size). | |
| 463 | * The destructor functions, if any, will @em not be called. | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | * |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
465 | * If this map is storing pointers, the element is the pointer itself |
|
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
466 | * and not the object it points to. |
|
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 | * @param map (@c CxMap*) the map |
| 22 | 469 | * @param key (any supported key type) the key |
| 16 | 470 | * @param targetbuf (@c void*) the buffer where the element shall be copied to |
| 471 | * @retval zero success | |
| 472 | * @retval non-zero the key was not found | |
| 473 | * | |
|
11
0aa8cbd7912e
refactor dbuObjectExecuteQuery: replace multiple lists with a single ll list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
474 | * @see cxMapRemove() |
| 22 | 475 | * @see CX_HASH_KEY() |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | */ |
| 22 | 477 | #define cxMapRemoveAndGet(map, key, targetbuf) cx_map_remove(map, CX_HASH_KEY(key), targetbuf) |
| 478 | ||
| 479 | ||
| 480 | /** | |
| 481 | * Performs a deep clone of one map into another. | |
| 482 | * | |
| 483 | * If the destination map already contains entries, the cloned entries | |
| 484 | * are added to that map, possibly overwriting existing elements when | |
| 485 | * the keys already exist. | |
| 486 | * | |
| 487 | * When elements in the destination map need to be replaced, any destructor | |
| 488 | * function is called on the replaced elements before replacing them. | |
| 489 | * | |
| 490 | * @attention If the cloned elements need to be destroyed by a destructor | |
| 491 | * function, you must make sure that the destination map also uses this | |
| 492 | * destructor function. | |
| 493 | * | |
| 494 | * @param dst the destination map | |
| 495 | * @param src the source map | |
| 496 | * @param clone_func the clone function for the values | |
| 497 | * @param clone_allocator the allocator that is passed to the clone function | |
| 498 | * @param data optional additional data that is passed to the clone function | |
| 499 | * @retval zero when all elements were successfully cloned | |
| 500 | * @retval non-zero when an allocation error occurred | |
| 501 | */ | |
| 502 | cx_attr_nonnull_arg(1, 2, 3) | |
| 503 | CX_EXPORT int cxMapClone(CxMap *dst, const CxMap *src, | |
| 504 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 505 | ||
| 506 | ||
| 507 | /** | |
| 508 | * Clones entries of a map if their key is not present in another map. | |
| 509 | * | |
| 510 | * @param dst the destination map | |
| 511 | * @param minuend the map to subtract the entries from | |
| 512 | * @param subtrahend the map containing the elements to be subtracted | |
| 513 | * @param clone_func the clone function for the values | |
| 514 | * @param clone_allocator the allocator that is passed to the clone function | |
| 515 | * @param data optional additional data that is passed to the clone function | |
| 516 | * @retval zero when the elements were successfully cloned | |
| 517 | * @retval non-zero when an allocation error occurred | |
| 518 | */ | |
| 519 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 520 | CX_EXPORT int cxMapDifference(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend, | |
| 521 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 522 | ||
| 523 | /** | |
| 524 | * Clones entries of a map if their key is not present in a list. | |
| 525 | * | |
| 526 | * Note that the list must contain keys of type @c CxKey | |
| 527 | * (or pointers to such keys) and must use @c cx_hash_key_cmp | |
| 528 | * as the compare function. | |
| 529 | * Generic key types cannot be processed in this case. | |
| 530 | * | |
| 531 | * @param dst the destination map | |
| 532 | * @param src the source map | |
| 533 | * @param keys the list of @c CxKey items | |
| 534 | * @param clone_func the clone function for the values | |
| 535 | * @param clone_allocator the allocator that is passed to the clone function | |
| 536 | * @param data optional additional data that is passed to the clone function | |
| 537 | * @retval zero when the elements were successfully cloned | |
| 538 | * @retval non-zero when an allocation error occurred | |
| 539 | */ | |
| 540 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 541 | CX_EXPORT int cxMapListDifference(CxMap *dst, const CxMap *src, const CxList *keys, | |
| 542 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 543 | ||
| 544 | ||
| 545 | /** | |
| 546 | * Clones entries of a map only if their key is present in another map. | |
| 547 | * | |
| 548 | * @param dst the destination map | |
| 549 | * @param src the map to clone the entries from | |
| 550 | * @param other the map to check for existence of the keys | |
| 551 | * @param clone_func the clone function for the values | |
| 552 | * @param clone_allocator the allocator that is passed to the clone function | |
| 553 | * @param data optional additional data that is passed to the clone function | |
| 554 | * @retval zero when the elements were successfully cloned | |
| 555 | * @retval non-zero when an allocation error occurred | |
| 556 | */ | |
| 557 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 558 | CX_EXPORT int cxMapIntersection(CxMap *dst, const CxMap *src, const CxMap *other, | |
| 559 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 560 | ||
| 561 | /** | |
| 562 | * Clones entries of a map only if their key is present in a list. | |
| 563 | * | |
| 564 | * Note that the list must contain keys of type @c CxKey | |
| 565 | * (or pointers to such keys) and must use @c cx_hash_key_cmp | |
| 566 | * as the compare function. | |
| 567 | * Generic key types cannot be processed in this case. | |
| 568 | * | |
| 569 | * @param dst the destination map | |
| 570 | * @param src the source map | |
| 571 | * @param keys the list of @c CxKey items | |
| 572 | * @param clone_func the clone function for the values | |
| 573 | * @param clone_allocator the allocator that is passed to the clone function | |
| 574 | * @param data optional additional data that is passed to the clone function | |
| 575 | * @retval zero when the elements were successfully cloned | |
| 576 | * @retval non-zero when an allocation error occurred | |
| 577 | */ | |
| 578 | cx_attr_nonnull_arg(1, 2, 3, 4) | |
| 579 | CX_EXPORT int cxMapListIntersection(CxMap *dst, const CxMap *src, const CxList *keys, | |
| 580 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
581 | |
| 22 | 582 | /** |
| 583 | * Clones entries into a map if their key does not exist yet. | |
| 584 | * | |
| 585 | * If you want to calculate the union of two maps into a fresh new map, | |
| 586 | * you can proceed as follows: | |
| 587 | * 1. Clone the first map into a fresh, empty map. | |
| 588 | * 2. Use this function to clone the second map into the result from step 1. | |
| 589 | * | |
| 590 | * @param dst the destination map | |
| 591 | * @param src the map to clone the entries from | |
| 592 | * @param clone_func the clone function for the values | |
| 593 | * @param clone_allocator the allocator that is passed to the clone function | |
| 594 | * @param data optional additional data that is passed to the clone function | |
| 595 | * @retval zero when the elements were successfully cloned | |
| 596 | * @retval non-zero when an allocation error occurred | |
| 597 | */ | |
| 598 | cx_attr_nonnull_arg(1, 2, 3) | |
| 599 | CX_EXPORT int cxMapUnion(CxMap *dst, const CxMap *src, | |
| 600 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); | |
| 601 | ||
| 602 | /** | |
| 603 | * Performs a shallow clone of one map into another. | |
| 604 | * | |
| 605 | * This function uses the default allocator, if needed, and performs | |
| 606 | * shallow clones with @c memcpy(). | |
| 607 | * | |
| 608 | * If the destination map already contains entries, the cloned entries | |
| 609 | * are added to that map, possibly overwriting existing elements when | |
| 610 | * the keys already exist. | |
| 611 | * | |
| 612 | * When elements in the destination map need to be replaced, any destructor | |
| 613 | * function is called on the replaced elements before replacing them. | |
| 614 | * | |
| 615 | * @attention If the cloned elements need to be destroyed by a destructor | |
| 616 | * function, you must make sure that the destination map also uses this | |
| 617 | * destructor function. | |
| 618 | * | |
| 619 | * @param dst the destination map | |
| 620 | * @param src the source map | |
| 621 | * @retval zero when all elements were successfully cloned | |
| 622 | * @retval non-zero when an allocation error occurred | |
| 623 | * @see cxMapClone() | |
| 624 | */ | |
| 625 | cx_attr_nonnull | |
| 31 | 626 | CX_EXPORT int cxMapCloneShallow(CxMap *dst, const CxMap *src); |
| 22 | 627 | |
| 628 | /** | |
| 629 | * Clones entries of a map if their key is not present in another map. | |
| 630 | * | |
| 631 | * This function uses the default allocator, if needed, and performs | |
| 632 | * shallow clones with @c memcpy(). | |
| 633 | * | |
| 634 | * @param dst the destination map | |
| 635 | * @param minuend the map to subtract the entries from | |
| 636 | * @param subtrahend the map containing the elements to be subtracted | |
| 637 | * @retval zero when the elements were successfully cloned | |
| 638 | * @retval non-zero when an allocation error occurred | |
| 639 | */ | |
| 640 | cx_attr_nonnull | |
| 31 | 641 | CX_EXPORT int cxMapDifferenceShallow(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend); |
| 22 | 642 | |
| 643 | /** | |
| 644 | * Clones entries of a map if their key is not present in a list. | |
| 645 | * | |
| 646 | * This function uses the default allocator, if needed, and performs | |
| 647 | * shallow clones with @c memcpy(). | |
| 648 | * | |
| 649 | * Note that the list must contain keys of type @c CxKey | |
| 650 | * (or pointers to such keys) and must use @c cx_hash_key_cmp | |
| 651 | * as the compare function. | |
| 652 | * Generic key types cannot be processed in this case. | |
| 653 | * | |
| 654 | * @param dst the destination map | |
| 655 | * @param src the source map | |
| 656 | * @param keys the list of @c CxKey items | |
| 657 | * @retval zero when the elements were successfully cloned | |
| 658 | * @retval non-zero when an allocation error occurred | |
| 659 | * @see cxMapListDifference() | |
| 660 | */ | |
| 661 | cx_attr_nonnull | |
| 31 | 662 | CX_EXPORT int cxMapListDifferenceShallow(CxMap *dst, const CxMap *src, const CxList *keys); |
| 22 | 663 | |
| 664 | ||
| 665 | /** | |
| 666 | * Clones entries of a map only if their key is present in another map. | |
| 667 | * | |
| 668 | * This function uses the default allocator, if needed, and performs | |
| 669 | * shallow clones with @c memcpy(). | |
| 670 | * | |
| 671 | * @param dst the destination map | |
| 672 | * @param src the map to clone the entries from | |
| 673 | * @param other the map to check for existence of the keys | |
| 674 | * @retval zero when the elements were successfully cloned | |
| 675 | * @retval non-zero when an allocation error occurred | |
| 676 | */ | |
| 677 | cx_attr_nonnull | |
| 31 | 678 | CX_EXPORT int cxMapIntersectionShallow(CxMap *dst, const CxMap *src, const CxMap *other); |
| 22 | 679 | |
| 680 | /** | |
| 681 | * Clones entries of a map only if their key is present in a list. | |
| 682 | * | |
| 683 | * This function uses the default allocator, if needed, and performs | |
| 684 | * shallow clones with @c memcpy(). | |
| 685 | * | |
| 686 | * Note that the list must contain keys of type @c CxKey | |
| 687 | * (or pointers to such keys) and must use @c cx_hash_key_cmp | |
| 688 | * as the compare function. | |
| 689 | * Generic key types cannot be processed in this case. | |
| 690 | * | |
| 691 | * @param dst the destination map | |
| 692 | * @param src the source map | |
| 693 | * @param keys the list of @c CxKey items | |
| 694 | * @retval zero when the elements were successfully cloned | |
| 695 | * @retval non-zero when an allocation error occurred | |
| 696 | */ | |
| 697 | cx_attr_nonnull | |
| 31 | 698 | CX_EXPORT int cxMapListIntersectionShallow(CxMap *dst, const CxMap *src, const CxList *keys); |
| 22 | 699 | |
| 700 | /** | |
| 701 | * Clones entries into a map if their key does not exist yet. | |
| 702 | * | |
| 703 | * This function uses the default allocator, if needed, and performs | |
| 704 | * shallow clones with @c memcpy(). | |
| 705 | * | |
| 706 | * If you want to calculate the union of two maps into a fresh new map, | |
| 707 | * you can proceed as follows: | |
| 708 | * 1. Clone the first map into a fresh, empty map. | |
| 709 | * 2. Use this function to clone the second map into the result from step 1. | |
| 710 | * | |
| 711 | * @param dst the destination map | |
| 712 | * @param src the map to clone the entries from | |
| 713 | * @retval zero when the elements were successfully cloned | |
| 714 | * @retval non-zero when an allocation error occurred | |
| 715 | */ | |
| 716 | cx_attr_nonnull | |
| 31 | 717 | CX_EXPORT int cxMapUnionShallow(CxMap *dst, const CxMap *src); |
| 718 | ||
| 719 | ||
| 720 | /** | |
| 721 | * Compares the entries of two maps. | |
| 722 | * | |
| 723 | * @param map the map | |
| 724 | * @param other the other map that the first map is compared to | |
| 725 | * @retval zero when both maps have the same key sets | |
| 726 | * and the values are pairwise equivalent | |
| 727 | * @retval negative when the first @p map has fewer keys than the @p other map | |
| 728 | * @retval positive when the first @p map has more keys than the @p other map | |
| 729 | * @retval non-zero (unspecified whether positive or negative) when the size | |
| 730 | * of both maps is equal but a key or a value is different | |
| 731 | */ | |
| 732 | cx_attr_nonnull | |
| 733 | CX_EXPORT int cxMapCompare(const CxMap *map, const CxMap *other); | |
| 22 | 734 | |
| 735 | #ifdef __cplusplus | |
| 736 | } // extern "C" | |
| 737 | #endif | |
|
0
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738 | |
|
1a157da63d7c
add API for registering types and simple SQLite proof of concept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739 | #endif // UCX_MAP_H |