src/map.c

changeset 1479
ac1baaed2fd7
parent 1474
84de0ba791af
equal deleted inserted replaced
1478:bba2e5efdca0 1479:ac1baaed2fd7
138 cxMapRemove(map, key); 138 cxMapRemove(map, key);
139 map->collection.simple_destructor = destr_bak; 139 map->collection.simple_destructor = destr_bak;
140 map->collection.advanced_destructor = destr2_bak; 140 map->collection.advanced_destructor = destr2_bak;
141 } 141 }
142 142
143 static void* cx_map_simple_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) {
144 size_t elem_size = *(size_t*)data;
145 if (dst == NULL) dst = cxMalloc(al, elem_size);
146 if (dst != NULL) memcpy(dst, src, elem_size);
147 return dst;
148 }
149
150 #define use_simple_clone_func(map) cx_map_simple_clone_func, NULL, (void*)&((map)->collection.elem_size)
151
143 int cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func, 152 int cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func,
144 const CxAllocator *clone_allocator, void *data) { 153 const CxAllocator *clone_allocator, void *data) {
145 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; 154 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator;
146 CxMapIterator src_iter = cxMapIterator(src); 155 CxMapIterator src_iter = cxMapIterator(src);
147 for (size_t i = 0; i < cxMapSize(src); i++) { 156 for (size_t i = 0; i < cxMapSize(src); i++) {
291 *dst_mem = dst_ptr; 300 *dst_mem = dst_ptr;
292 } 301 }
293 } 302 }
294 return 0; 303 return 0;
295 } 304 }
305
306 int cxMapCloneSimple(CxMap *dst, const CxMap *src) {
307 return cxMapClone(dst, src, use_simple_clone_func(src));
308 }
309
310 int cxMapDifferenceSimple(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend) {
311 return cxMapDifference(dst, minuend, subtrahend, use_simple_clone_func(minuend));
312 }
313
314 int cxMapListDifferenceSimple(CxMap *dst, const CxMap *src, const CxList *keys) {
315 return cxMapListDifference(dst, src, keys, use_simple_clone_func(src));
316 }
317
318 int cxMapIntersectionSimple(CxMap *dst, const CxMap *src, const CxMap *other) {
319 return cxMapIntersection(dst, src, other, use_simple_clone_func(src));
320 }
321
322 int cxMapListIntersectionSimple(CxMap *dst, const CxMap *src, const CxList *keys) {
323 return cxMapListIntersection(dst, src, keys, use_simple_clone_func(src));
324 }
325
326 int cxMapUnionSimple(CxMap *dst, const CxMap *src) {
327 return cxMapUnion(dst, src, use_simple_clone_func(src));
328 }

mercurial