src/map.c

changeset 1467
bb6f04c35310
parent 1466
a58c65d31342
equal deleted inserted replaced
1466:a58c65d31342 1467:bb6f04c35310
213 *dst_mem = dst_ptr; 213 *dst_mem = dst_ptr;
214 } 214 }
215 } 215 }
216 return 0; 216 return 0;
217 } 217 }
218
219 int cxMapIntersection(CxMap *dst, const CxMap *src, const CxMap *other,
220 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) {
221 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator;
222
223 CxMapIterator src_iter = cxMapIterator(src);
224 cx_foreach(const CxMapEntry *, entry, src_iter) {
225 if (!cxMapContains(other, *entry->key)) {
226 continue;
227 }
228 void** dst_mem = cxMapEmplace(dst, *entry->key);
229 if (dst_mem == NULL) {
230 return 1; // LCOV_EXCL_LINE
231 }
232 void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem;
233 void* dst_ptr = clone_func(target, entry->value, clone_allocator, data);
234 if (dst_ptr == NULL) {
235 cx_map_remove_uninitialized_entry(dst, *(entry->key));
236 return 1;
237 }
238 if (cxCollectionStoresPointers(dst)) {
239 *dst_mem = dst_ptr;
240 }
241 }
242 return 0;
243 }
244
245 int cxMapListIntersection(CxMap *dst, const CxMap *src, const CxList *keys,
246 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) {
247 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator;
248
249 CxMapIterator src_iter = cxMapIterator(src);
250 cx_foreach(const CxMapEntry *, entry, src_iter) {
251 if (!cxListContains(keys, entry->key)) {
252 continue;
253 }
254 void** dst_mem = cxMapEmplace(dst, *entry->key);
255 if (dst_mem == NULL) {
256 return 1; // LCOV_EXCL_LINE
257 }
258 void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem;
259 void* dst_ptr = clone_func(target, entry->value, clone_allocator, data);
260 if (dst_ptr == NULL) {
261 cx_map_remove_uninitialized_entry(dst, *(entry->key));
262 return 1;
263 }
264 if (cxCollectionStoresPointers(dst)) {
265 *dst_mem = dst_ptr;
266 }
267 }
268 return 0;
269 }

mercurial