Tue, 03 Feb 2026 19:09:53 +0100
use bool instead of WSBool in strreplace
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
d938228c382e
switch from ucx 2 to 3
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 |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 579 | 29 | * @file map.h |
| 30 | * @brief Interface for map implementations. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #ifndef UCX_MAP_H |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #define UCX_MAP_H |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "common.h" |
| 490 | 40 | #include "collection.h" |
| 41 | #include "string.h" | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #include "hash_key.h" |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
| 621 | 44 | #ifndef UCX_LIST_H |
| 45 | // forward-declare CxList | |
| 46 | typedef struct cx_list_s CxList; | |
| 47 | #endif | |
| 48 | ||
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | /** Type for the UCX map. */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | typedef struct cx_map_s CxMap; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | /** Type for a map entry. */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | typedef struct cx_map_entry_s CxMapEntry; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
| 579 | 55 | /** Type for a map iterator. */ |
| 56 | typedef struct cx_map_iterator_s CxMapIterator; | |
| 57 | ||
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | /** Type for map class definitions. */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | typedef struct cx_map_class_s cx_map_class; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | /** Structure for the UCX map. */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | struct cx_map_s { |
| 579 | 63 | /** |
| 64 | * Base attributes. | |
| 65 | */ | |
| 66 | CX_COLLECTION_BASE; | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | /** The map class definition. */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | cx_map_class *cl; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | }; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | /** |
| 579 | 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 | /** | |
| 504 | 86 | * The type of iterator for a map. |
| 87 | */ | |
| 88 | enum cx_map_iterator_type { | |
| 89 | /** | |
| 90 | * Iterates over key/value pairs. | |
| 91 | */ | |
| 92 | CX_MAP_ITERATOR_PAIRS, | |
| 93 | /** | |
| 94 | * Iterates over keys only. | |
| 95 | */ | |
| 96 | CX_MAP_ITERATOR_KEYS, | |
| 97 | /** | |
| 98 | * Iterates over values only. | |
| 99 | */ | |
| 100 | CX_MAP_ITERATOR_VALUES | |
| 101 | }; | |
| 102 | ||
| 103 | /** | |
| 579 | 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 | */ | |
| 621 | 115 | CxMap *map; |
| 579 | 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 | /** | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | * The class definition for arbitrary maps. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | struct cx_map_class_s { |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | * Deallocates the entire memory. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | */ |
| 579 | 171 | void (*deallocate)(struct cx_map_s *map); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | * Removes all elements. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | */ |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | void (*clear)(struct cx_map_s *map); |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | * Add or overwrite an element. |
| 621 | 180 | * If the @p value is @c NULL, the implementation |
| 181 | * shall only allocate memory instead of adding an existing value to the map. | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
182 | * Returns a map entry where the pointer to the key is @c NULL if allocation fails. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | */ |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
184 | CxMapEntry (*put)(CxMap *map, CxHashKey key, void *value); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | * Returns an element. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | */ |
| 621 | 189 | void *(*get)(const CxMap *map, CxHashKey key); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | * Removes an element. |
| 579 | 193 | * |
| 194 | * Implementations SHALL check if @p targetbuf is set and copy the elements | |
| 195 | * to the buffer without invoking any destructor. | |
| 196 | * When @p targetbuf is not set, the destructors SHALL be invoked. | |
| 197 | * | |
| 198 | * The function SHALL return zero when the @p key was found and | |
| 199 | * non-zero, otherwise. | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | */ |
| 621 | 201 | int (*remove)(CxMap *map, CxHashKey key, void *targetbuf); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | /** |
| 504 | 204 | * Creates an iterator for this map. |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | */ |
| 579 | 206 | CxMapIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | }; |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | |
| 490 | 209 | /** |
| 504 | 210 | * A shared instance of an empty map. |
| 211 | * | |
| 579 | 212 | * Writing to that map is not allowed. |
| 490 | 213 | * |
| 621 | 214 | * You can use this as a placeholder for initializing CxMap pointers |
| 579 | 215 | * for which you do not want to reserve memory right from the beginning. |
| 490 | 216 | */ |
| 621 | 217 | CX_EXPORT extern CxMap *const cxEmptyMap; |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | * Deallocates the memory of the specified map. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | * |
| 579 | 222 | * Also calls the content destructor functions for each element, if specified. |
| 223 | * | |
| 224 | * @param map the map to be freed | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | */ |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
226 | CX_EXTERN |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
227 | void cxMapFree(CxMap *map); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | * Clears a map by removing all elements. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | * |
| 579 | 232 | * Also calls the content destructor functions for each element, if specified. |
| 233 | * | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | * @param map the map to be cleared |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | */ |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
236 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
237 | void cxMapClear(CxMap *map); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | |
| 579 | 239 | /** |
| 240 | * Returns the number of elements in this map. | |
| 241 | * | |
| 242 | * @param map the map | |
| 243 | * @return the number of stored elements | |
| 244 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
245 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
246 | size_t cxMapSize(const CxMap *map); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | * Creates a value iterator for a map. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | * |
| 579 | 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 | |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | * |
| 621 | 258 | * @param map the map to create the iterator for (can be @c NULL) |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | * @return an iterator for the currently stored values |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | */ |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
261 | CX_EXTERN CX_NODISCARD |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
262 | CxMapIterator cxMapIteratorValues(const CxMap *map); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | * Creates a key iterator for a map. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | * |
| 621 | 267 | * The elements of the iterator are keys of type CxHashKey, and the pointer returned |
| 579 | 268 | * during iterator shall be treated as @c const @c CxHashKey* . |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | * |
| 579 | 270 | * @note An iterator iterates over all elements successively. Therefore, the order |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | * |
| 621 | 273 | * @param map the map to create the iterator for (can be @c NULL) |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | * @return an iterator for the currently stored keys |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | */ |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
276 | CX_EXTERN CX_NODISCARD |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
277 | CxMapIterator cxMapIteratorKeys(const CxMap *map); |
|
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | /** |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | * Creates an iterator for a map. |
|
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | * |
| 621 | 282 | * The elements of the iterator are key/value pairs of type CxMapEntry, and the pointer returned |
| 579 | 283 | * during iterator shall be treated as @c const @c CxMapEntry* . |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
284 | * |
| 579 | 285 | * @note An iterator iterates over all elements successively. Therefore, the order |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
286 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
|
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
287 | * |
| 621 | 288 | * @param map the map to create the iterator for (can be @c NULL) |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
289 | * @return an iterator for the currently stored entries |
| 621 | 290 | * @see cxMapIteratorKeys() |
| 291 | * @see cxMapIteratorValues() | |
| 292 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
293 | CX_EXTERN CX_NODISCARD |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
294 | CxMapIterator cxMapIterator(const CxMap *map); |
| 621 | 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() | |
|
438
22eca559aded
refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
315 | */ |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
316 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
317 | int cx_map_put(CxMap *map, CxHashKey key, void *value); |
| 490 | 318 | |
| 319 | /** | |
| 320 | * Puts a key/value-pair into the map. | |
| 321 | * | |
| 579 | 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 | |
| 621 | 333 | * @param key (any supported key type) the key |
| 579 | 334 | * @param value (@c void*) the value |
| 335 | * @retval zero success | |
| 336 | * @retval non-zero value on memory allocation failure | |
| 621 | 337 | * @see CX_HASH_KEY() |
| 490 | 338 | */ |
| 621 | 339 | #define cxMapPut(map, key, value) cx_map_put(map, CX_HASH_KEY(key), value) |
| 490 | 340 | |
| 341 | /** | |
| 621 | 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() | |
| 490 | 357 | */ |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
358 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
359 | void *cx_map_emplace(CxMap *map, CxHashKey key); |
| 490 | 360 | |
| 361 | /** | |
| 621 | 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() | |
| 490 | 377 | */ |
| 621 | 378 | #define cxMapEmplace(map, key) cx_map_emplace(map, CX_HASH_KEY(key)) |
| 490 | 379 | |
| 380 | /** | |
| 621 | 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() | |
| 490 | 391 | */ |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
392 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
393 | void *cx_map_get(const CxMap *map, CxHashKey key); |
| 490 | 394 | |
| 395 | /** | |
| 396 | * Retrieves a value by using a key. | |
| 397 | * | |
| 579 | 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 | |
| 621 | 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() | |
| 490 | 406 | */ |
| 621 | 407 | #define cxMapGet(map, key) cx_map_get(map, CX_HASH_KEY(key)) |
| 579 | 408 | |
| 409 | /** | |
| 621 | 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() | |
| 490 | 417 | */ |
| 621 | 418 | #define cxMapContains(map, key) (cxMapGet(map, key) != NULL) |
| 490 | 419 | |
| 420 | /** | |
| 421 | * Removes a key/value-pair from the map by using the key. | |
| 422 | * | |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
435 | CX_EXTERN CX_NONNULL_ARG(1) |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
436 | int cx_map_remove(CxMap *map, CxHashKey key, void *targetbuf); |
| 621 | 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. | |
| 490 | 442 | * |
| 579 | 443 | * @param map (@c CxMap*) the map |
| 621 | 444 | * @param key (any supported key type) the key |
| 579 | 445 | * @retval zero success |
| 446 | * @retval non-zero the key was not found | |
| 447 | * | |
| 490 | 448 | * @see cxMapRemoveAndGet() |
| 621 | 449 | * @see CX_HASH_KEY() |
| 490 | 450 | */ |
| 621 | 451 | #define cxMapRemove(map, key) cx_map_remove(map, CX_HASH_KEY(key), NULL) |
| 490 | 452 | |
| 453 | /** | |
| 454 | * Removes a key/value-pair from the map by using the key. | |
| 455 | * | |
| 579 | 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. | |
| 490 | 460 | * |
| 579 | 461 | * If this map is storing pointers, the element is the pointer itself |
| 462 | * and not the object it points to. | |
| 490 | 463 | * |
| 579 | 464 | * @param map (@c CxMap*) the map |
| 621 | 465 | * @param key (any supported key type) the key |
| 579 | 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 | |
| 490 | 469 | * |
| 579 | 470 | * @see cxMapRemove() |
| 621 | 471 | * @see CX_HASH_KEY() |
| 490 | 472 | */ |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
497 | CX_EXTERN CX_NONNULL_ARG(1, 2, 3) |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
498 | int cxMapClone(CxMap *dst, const CxMap *src, |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
513 | CX_EXTERN CX_NONNULL_ARG(1, 2, 3, 4) |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
514 | int cxMapDifference(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend, |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
534 | CX_EXTERN CX_NONNULL_ARG(1, 2, 3, 4) |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
535 | int cxMapListDifference(CxMap *dst, const CxMap *src, const CxList *keys, |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
551 | CX_EXTERN CX_NONNULL_ARG(1, 2, 3, 4) |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
552 | int cxMapIntersection(CxMap *dst, const CxMap *src, const CxMap *other, |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
572 | CX_EXTERN CX_NONNULL_ARG(1, 2, 3, 4) |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
573 | int cxMapListIntersection(CxMap *dst, const CxMap *src, const CxList *keys, |
| 621 | 574 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); |
| 490 | 575 | |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
592 | CX_EXTERN CX_NONNULL_ARG(1, 2, 3) |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
593 | int cxMapUnion(CxMap *dst, const CxMap *src, |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
619 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
620 | int cxMapCloneShallow(CxMap *dst, const CxMap *src); |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
634 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
635 | int cxMapDifferenceShallow(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend); |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
655 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
656 | int cxMapListDifferenceShallow(CxMap *dst, const CxMap *src, const CxList *keys); |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
670 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
671 | int cxMapIntersectionShallow(CxMap *dst, const CxMap *src, const CxMap *other); |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
690 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
691 | int cxMapListIntersectionShallow(CxMap *dst, const CxMap *src, const CxList *keys); |
| 621 | 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 | */ | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
709 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
710 | int cxMapUnionShallow(CxMap *dst, const CxMap *src); |
| 621 | 711 | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
712 | /** |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
713 | * Compares the entries of two maps. |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
714 | * |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
715 | * @param map the map |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
716 | * @param other the other map that the first map is compared to |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
717 | * @retval zero when both maps have the same key sets |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
718 | * and the values are pairwise equivalent |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
719 | * @retval negative when the first @p map has fewer keys than the @p other map |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
720 | * @retval positive when the first @p map has more keys than the @p other map |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
721 | * @retval non-zero (unspecified whether positive or negative) when the size |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
722 | * of both maps is equal but a key or a value is different |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
723 | */ |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
724 | CX_EXTERN CX_NONNULL |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
725 | int cxMapCompare(const CxMap *map, const CxMap *other); |
| 490 | 726 | |
| 727 | #endif // UCX_MAP_H |