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