Tue, 03 Feb 2026 19:09:53 +0100
use bool instead of WSBool in strreplace
| 504 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | ||
| 29 | #include "cx/map.h" | |
| 30 | #include <string.h> | |
| 31 | ||
| 621 | 32 | #include "cx/list.h" |
| 33 | ||
| 504 | 34 | // <editor-fold desc="empty map implementation"> |
| 35 | ||
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
36 | static void cx_empty_map_noop(CX_UNUSED CxMap *map) { |
| 504 | 37 | // this is a noop, but MUST be implemented |
| 38 | } | |
| 39 | ||
| 40 | static void *cx_empty_map_get( | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
41 | CX_UNUSED const CxMap *map, |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
42 | CX_UNUSED CxHashKey key |
| 504 | 43 | ) { |
| 44 | return NULL; | |
| 45 | } | |
| 46 | ||
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
47 | static bool cx_empty_map_iter_valid(CX_UNUSED const void *iter) { |
| 504 | 48 | return false; |
| 49 | } | |
| 50 | ||
| 579 | 51 | static CxMapIterator cx_empty_map_iterator( |
| 52 | const struct cx_map_s *map, | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
53 | CX_UNUSED enum cx_map_iterator_type type |
| 504 | 54 | ) { |
| 579 | 55 | CxMapIterator iter = {0}; |
| 621 | 56 | iter.map = (CxMap*) map; |
| 504 | 57 | iter.base.valid = cx_empty_map_iter_valid; |
| 58 | return iter; | |
| 59 | } | |
| 60 | ||
| 61 | static struct cx_map_class_s cx_empty_map_class = { | |
| 62 | cx_empty_map_noop, | |
| 63 | cx_empty_map_noop, | |
| 64 | NULL, | |
| 65 | cx_empty_map_get, | |
| 66 | NULL, | |
| 67 | cx_empty_map_iterator | |
| 68 | }; | |
| 69 | ||
| 70 | CxMap cx_empty_map = { | |
| 579 | 71 | { |
| 504 | 72 | NULL, |
| 73 | 0, | |
| 74 | 0, | |
| 75 | NULL, | |
| 76 | NULL, | |
| 77 | NULL, | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
78 | NULL, |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
79 | NULL, |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
80 | NULL, |
| 504 | 81 | false, |
| 579 | 82 | true |
| 83 | }, | |
| 84 | &cx_empty_map_class | |
| 504 | 85 | }; |
| 86 | ||
| 87 | CxMap *const cxEmptyMap = &cx_empty_map; | |
| 88 | ||
| 89 | // </editor-fold> | |
| 90 | ||
| 621 | 91 | void cxMapClear(CxMap *map) { |
| 92 | map->cl->clear(map); | |
| 93 | } | |
| 94 | ||
| 95 | size_t cxMapSize(const CxMap *map) { | |
| 96 | return map->collection.size; | |
| 97 | } | |
| 98 | ||
| 99 | CxMapIterator cxMapIteratorValues(const CxMap *map) { | |
| 100 | if (map == NULL) map = cxEmptyMap; | |
| 101 | return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES); | |
| 102 | } | |
| 103 | ||
| 104 | CxMapIterator cxMapIteratorKeys(const CxMap *map) { | |
| 105 | if (map == NULL) map = cxEmptyMap; | |
| 106 | return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS); | |
| 504 | 107 | } |
| 108 | ||
| 621 | 109 | CxMapIterator cxMapIterator(const CxMap *map) { |
| 110 | if (map == NULL) map = cxEmptyMap; | |
| 111 | return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS); | |
| 112 | } | |
| 113 | ||
| 114 | int cx_map_put(CxMap *map, CxHashKey key, void *value) { | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
115 | return map->cl->put(map, key, value).key == NULL; |
| 504 | 116 | } |
| 117 | ||
| 621 | 118 | void *cx_map_emplace(CxMap *map, CxHashKey key) { |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
119 | const CxMapEntry entry = map->cl->put(map, key, NULL); |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
120 | if (entry.key == NULL) return NULL; |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
121 | return entry.value; |
| 621 | 122 | } |
| 123 | ||
| 124 | void *cx_map_get(const CxMap *map, CxHashKey key) { | |
| 125 | return map->cl->get(map, key); | |
| 126 | } | |
| 127 | ||
| 128 | int cx_map_remove(CxMap *map, CxHashKey key, void *targetbuf) { | |
| 129 | return map->cl->remove(map, key, targetbuf); | |
| 579 | 130 | } |
| 504 | 131 | |
| 579 | 132 | void cxMapFree(CxMap *map) { |
| 133 | if (map == NULL) return; | |
| 134 | map->cl->deallocate(map); | |
| 504 | 135 | } |
| 621 | 136 | |
| 137 | static void cx_map_remove_uninitialized_entry(CxMap *map, CxHashKey key) { | |
| 138 | cx_destructor_func destr_bak = map->collection.simple_destructor; | |
| 139 | cx_destructor_func2 destr2_bak = map->collection.advanced_destructor; | |
| 140 | map->collection.simple_destructor = NULL; | |
| 141 | map->collection.advanced_destructor = NULL; | |
| 142 | cxMapRemove(map, key); | |
| 143 | map->collection.simple_destructor = destr_bak; | |
| 144 | map->collection.advanced_destructor = destr2_bak; | |
| 145 | } | |
| 146 | ||
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
147 | static void* cx_map_shallow_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) { |
| 621 | 148 | size_t elem_size = *(size_t*)data; |
| 149 | if (dst == NULL) dst = cxMalloc(al, elem_size); | |
| 150 | if (dst != NULL) memcpy(dst, src, elem_size); | |
| 151 | return dst; | |
| 152 | } | |
| 153 | ||
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
154 | #define use_shallow_clone_func(map) cx_map_shallow_clone_func, NULL, (void*)&((map)->collection.elem_size) |
| 621 | 155 | |
| 156 | int cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func, | |
| 157 | const CxAllocator *clone_allocator, void *data) { | |
| 158 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 159 | CxMapIterator src_iter = cxMapIterator(src); | |
| 160 | for (size_t i = 0; i < cxMapSize(src); i++) { | |
| 161 | const CxMapEntry *entry = cxIteratorCurrent(src_iter); | |
| 162 | void **dst_mem = cxMapEmplace(dst, *(entry->key)); | |
| 163 | if (dst_mem == NULL) { | |
| 164 | return 1; // LCOV_EXCL_LINE | |
| 165 | } | |
| 166 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 167 | void *dst_ptr = clone_func(target, entry->value, clone_allocator, data); | |
| 168 | if (dst_ptr == NULL) { | |
| 169 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | |
| 170 | return 1; | |
| 171 | } | |
| 172 | if (cxCollectionStoresPointers(dst)) { | |
| 173 | *dst_mem = dst_ptr; | |
| 174 | } | |
| 175 | cxIteratorNext(src_iter); | |
| 176 | } | |
| 177 | return 0; | |
| 178 | } | |
| 179 | ||
| 180 | int cxMapDifference(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend, | |
| 181 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | |
| 182 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 183 | ||
| 184 | CxMapIterator src_iter = cxMapIterator(minuend); | |
| 185 | cx_foreach(const CxMapEntry *, entry, src_iter) { | |
| 186 | if (cxMapContains(subtrahend, *entry->key)) { | |
| 187 | continue; | |
| 188 | } | |
| 189 | void** dst_mem = cxMapEmplace(dst, *entry->key); | |
| 190 | if (dst_mem == NULL) { | |
| 191 | return 1; // LCOV_EXCL_LINE | |
| 192 | } | |
| 193 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 194 | void* dst_ptr = clone_func(target, entry->value, clone_allocator, data); | |
| 195 | if (dst_ptr == NULL) { | |
| 196 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | |
| 197 | return 1; | |
| 198 | } | |
| 199 | if (cxCollectionStoresPointers(dst)) { | |
| 200 | *dst_mem = dst_ptr; | |
| 201 | } | |
| 202 | } | |
| 203 | return 0; | |
| 204 | } | |
| 205 | ||
| 206 | int cxMapListDifference(CxMap *dst, const CxMap *src, const CxList *keys, | |
| 207 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | |
| 208 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 209 | ||
| 210 | CxMapIterator src_iter = cxMapIterator(src); | |
| 211 | cx_foreach(const CxMapEntry *, entry, src_iter) { | |
| 212 | if (cxListContains(keys, entry->key)) { | |
| 213 | continue; | |
| 214 | } | |
| 215 | void** dst_mem = cxMapEmplace(dst, *entry->key); | |
| 216 | if (dst_mem == NULL) { | |
| 217 | return 1; // LCOV_EXCL_LINE | |
| 218 | } | |
| 219 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 220 | void* dst_ptr = clone_func(target, entry->value, clone_allocator, data); | |
| 221 | if (dst_ptr == NULL) { | |
| 222 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | |
| 223 | return 1; | |
| 224 | } | |
| 225 | if (cxCollectionStoresPointers(dst)) { | |
| 226 | *dst_mem = dst_ptr; | |
| 227 | } | |
| 228 | } | |
| 229 | return 0; | |
| 230 | } | |
| 231 | ||
| 232 | int cxMapIntersection(CxMap *dst, const CxMap *src, const CxMap *other, | |
| 233 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | |
| 234 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 235 | ||
| 236 | CxMapIterator src_iter = cxMapIterator(src); | |
| 237 | cx_foreach(const CxMapEntry *, entry, src_iter) { | |
| 238 | if (!cxMapContains(other, *entry->key)) { | |
| 239 | continue; | |
| 240 | } | |
| 241 | void** dst_mem = cxMapEmplace(dst, *entry->key); | |
| 242 | if (dst_mem == NULL) { | |
| 243 | return 1; // LCOV_EXCL_LINE | |
| 244 | } | |
| 245 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 246 | void* dst_ptr = clone_func(target, entry->value, clone_allocator, data); | |
| 247 | if (dst_ptr == NULL) { | |
| 248 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | |
| 249 | return 1; | |
| 250 | } | |
| 251 | if (cxCollectionStoresPointers(dst)) { | |
| 252 | *dst_mem = dst_ptr; | |
| 253 | } | |
| 254 | } | |
| 255 | return 0; | |
| 256 | } | |
| 257 | ||
| 258 | int cxMapListIntersection(CxMap *dst, const CxMap *src, const CxList *keys, | |
| 259 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | |
| 260 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 261 | ||
| 262 | CxMapIterator src_iter = cxMapIterator(src); | |
| 263 | cx_foreach(const CxMapEntry *, entry, src_iter) { | |
| 264 | if (!cxListContains(keys, entry->key)) { | |
| 265 | continue; | |
| 266 | } | |
| 267 | void** dst_mem = cxMapEmplace(dst, *entry->key); | |
| 268 | if (dst_mem == NULL) { | |
| 269 | return 1; // LCOV_EXCL_LINE | |
| 270 | } | |
| 271 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 272 | void* dst_ptr = clone_func(target, entry->value, clone_allocator, data); | |
| 273 | if (dst_ptr == NULL) { | |
| 274 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | |
| 275 | return 1; | |
| 276 | } | |
| 277 | if (cxCollectionStoresPointers(dst)) { | |
| 278 | *dst_mem = dst_ptr; | |
| 279 | } | |
| 280 | } | |
| 281 | return 0; | |
| 282 | } | |
| 283 | ||
| 284 | int cxMapUnion(CxMap *dst, const CxMap *src, | |
| 285 | cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { | |
| 286 | if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; | |
| 287 | ||
| 288 | CxMapIterator src_iter = cxMapIterator(src); | |
| 289 | cx_foreach(const CxMapEntry *, entry, src_iter) { | |
| 290 | if (cxMapContains(dst, *entry->key)) { | |
| 291 | continue; | |
| 292 | } | |
| 293 | void** dst_mem = cxMapEmplace(dst, *entry->key); | |
| 294 | if (dst_mem == NULL) { | |
| 295 | return 1; // LCOV_EXCL_LINE | |
| 296 | } | |
| 297 | void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; | |
| 298 | void* dst_ptr = clone_func(target, entry->value, clone_allocator, data); | |
| 299 | if (dst_ptr == NULL) { | |
| 300 | cx_map_remove_uninitialized_entry(dst, *(entry->key)); | |
| 301 | return 1; | |
| 302 | } | |
| 303 | if (cxCollectionStoresPointers(dst)) { | |
| 304 | *dst_mem = dst_ptr; | |
| 305 | } | |
| 306 | } | |
| 307 | return 0; | |
| 308 | } | |
| 309 | ||
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
310 | int cxMapCloneShallow(CxMap *dst, const CxMap *src) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
311 | return cxMapClone(dst, src, use_shallow_clone_func(src)); |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
312 | } |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
313 | |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
314 | int cxMapDifferenceShallow(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
315 | return cxMapDifference(dst, minuend, subtrahend, use_shallow_clone_func(minuend)); |
| 621 | 316 | } |
| 317 | ||
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
318 | int cxMapListDifferenceShallow(CxMap *dst, const CxMap *src, const CxList *keys) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
319 | return cxMapListDifference(dst, src, keys, use_shallow_clone_func(src)); |
| 621 | 320 | } |
| 321 | ||
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
322 | int cxMapIntersectionShallow(CxMap *dst, const CxMap *src, const CxMap *other) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
323 | return cxMapIntersection(dst, src, other, use_shallow_clone_func(src)); |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
324 | } |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
325 | |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
326 | int cxMapListIntersectionShallow(CxMap *dst, const CxMap *src, const CxList *keys) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
327 | return cxMapListIntersection(dst, src, keys, use_shallow_clone_func(src)); |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
328 | } |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
329 | |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
330 | int cxMapUnionShallow(CxMap *dst, const CxMap *src) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
331 | return cxMapUnion(dst, src, use_shallow_clone_func(src)); |
| 621 | 332 | } |
| 333 | ||
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
334 | int cxMapCompare(const CxMap *map, const CxMap *other) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
335 | // compare map sizes |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
336 | const size_t size_left = cxMapSize(map); |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
337 | const size_t size_right = cxMapSize(other); |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
338 | if (size_left < size_right) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
339 | return -1; |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
340 | } else if (size_left > size_right) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
341 | return 1; |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
342 | } |
| 621 | 343 | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
344 | // iterate through the first map |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
345 | CxMapIterator iter = cxMapIterator(map); |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
346 | cx_foreach(const CxMapEntry *, entry, iter) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
347 | const void *value_left = entry->value; |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
348 | const void *value_right = cxMapGet(other, *entry->key); |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
349 | // if the other map does not have the key, we are done |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
350 | if (value_right == NULL) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
351 | return -1; |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
352 | } |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
353 | // compare the values |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
354 | const int d = cx_invoke_compare_func(map, value_left, value_right); |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
355 | if (d != 0) { |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
356 | return d; |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
357 | } |
|
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
358 | } |
| 621 | 359 | |
|
660
f00d03835dd9
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
360 | return 0; |
| 621 | 361 | } |