src/map.c

changeset 1616
bdc04a8e0dd3
parent 1604
68b75c091028
equal deleted inserted replaced
1615:5c211187dde9 1616:bdc04a8e0dd3
140 cxMapRemove(map, key); 140 cxMapRemove(map, key);
141 map->collection.simple_destructor = destr_bak; 141 map->collection.simple_destructor = destr_bak;
142 map->collection.advanced_destructor = destr2_bak; 142 map->collection.advanced_destructor = destr2_bak;
143 } 143 }
144 144
145 static void* cx_map_simple_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) { 145 static void* cx_map_shallow_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) {
146 size_t elem_size = *(size_t*)data; 146 size_t elem_size = *(size_t*)data;
147 if (dst == NULL) dst = cxMalloc(al, elem_size); 147 if (dst == NULL) dst = cxMalloc(al, elem_size);
148 if (dst != NULL) memcpy(dst, src, elem_size); 148 if (dst != NULL) memcpy(dst, src, elem_size);
149 return dst; 149 return dst;
150 } 150 }
151 151
152 #define use_simple_clone_func(map) cx_map_simple_clone_func, NULL, (void*)&((map)->collection.elem_size) 152 #define use_shallow_clone_func(map) cx_map_shallow_clone_func, NULL, (void*)&((map)->collection.elem_size)
153 153
154 int cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func, 154 int cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func,
155 const CxAllocator *clone_allocator, void *data) { 155 const CxAllocator *clone_allocator, void *data) {
156 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; 156 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator;
157 CxMapIterator src_iter = cxMapIterator(src); 157 CxMapIterator src_iter = cxMapIterator(src);
304 } 304 }
305 return 0; 305 return 0;
306 } 306 }
307 307
308 int cxMapCloneShallow(CxMap *dst, const CxMap *src) { 308 int cxMapCloneShallow(CxMap *dst, const CxMap *src) {
309 return cxMapClone(dst, src, use_simple_clone_func(src)); 309 return cxMapClone(dst, src, use_shallow_clone_func(src));
310 } 310 }
311 311
312 int cxMapDifferenceShallow(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend) { 312 int cxMapDifferenceShallow(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend) {
313 return cxMapDifference(dst, minuend, subtrahend, use_simple_clone_func(minuend)); 313 return cxMapDifference(dst, minuend, subtrahend, use_shallow_clone_func(minuend));
314 } 314 }
315 315
316 int cxMapListDifferenceShallow(CxMap *dst, const CxMap *src, const CxList *keys) { 316 int cxMapListDifferenceShallow(CxMap *dst, const CxMap *src, const CxList *keys) {
317 return cxMapListDifference(dst, src, keys, use_simple_clone_func(src)); 317 return cxMapListDifference(dst, src, keys, use_shallow_clone_func(src));
318 } 318 }
319 319
320 int cxMapIntersectionShallow(CxMap *dst, const CxMap *src, const CxMap *other) { 320 int cxMapIntersectionShallow(CxMap *dst, const CxMap *src, const CxMap *other) {
321 return cxMapIntersection(dst, src, other, use_simple_clone_func(src)); 321 return cxMapIntersection(dst, src, other, use_shallow_clone_func(src));
322 } 322 }
323 323
324 int cxMapListIntersectionShallow(CxMap *dst, const CxMap *src, const CxList *keys) { 324 int cxMapListIntersectionShallow(CxMap *dst, const CxMap *src, const CxList *keys) {
325 return cxMapListIntersection(dst, src, keys, use_simple_clone_func(src)); 325 return cxMapListIntersection(dst, src, keys, use_shallow_clone_func(src));
326 } 326 }
327 327
328 int cxMapUnionShallow(CxMap *dst, const CxMap *src) { 328 int cxMapUnionShallow(CxMap *dst, const CxMap *src) {
329 return cxMapUnion(dst, src, use_simple_clone_func(src)); 329 return cxMapUnion(dst, src, use_shallow_clone_func(src));
330 } 330 }
331 331
332 int cxMapCompare(const CxMap *map, const CxMap *other) { 332 int cxMapCompare(const CxMap *map, const CxMap *other) {
333 // compare map sizes 333 // compare map sizes
334 const size_t size_left = cxMapSize(map); 334 const size_t size_left = cxMapSize(map);

mercurial