src/map.c

changeset 1479
ac1baaed2fd7
parent 1474
84de0ba791af
--- a/src/map.c	Fri Nov 07 19:23:21 2025 +0100
+++ b/src/map.c	Sat Nov 08 23:45:19 2025 +0100
@@ -140,6 +140,15 @@
     map->collection.advanced_destructor = destr2_bak;
 }
 
+static void* cx_map_simple_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) {
+    size_t elem_size = *(size_t*)data;
+    if (dst == NULL) dst = cxMalloc(al, elem_size);
+    if (dst != NULL) memcpy(dst, src, elem_size);
+    return dst;
+}
+
+#define use_simple_clone_func(map) cx_map_simple_clone_func, NULL, (void*)&((map)->collection.elem_size)
+
 int cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func,
         const CxAllocator *clone_allocator, void *data) {
     if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator;
@@ -293,3 +302,27 @@
     }
     return 0;
 }
+
+int cxMapCloneSimple(CxMap *dst, const CxMap *src) {
+    return cxMapClone(dst, src, use_simple_clone_func(src));
+}
+
+int cxMapDifferenceSimple(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend) {
+    return cxMapDifference(dst, minuend, subtrahend, use_simple_clone_func(minuend));
+}
+
+int cxMapListDifferenceSimple(CxMap *dst, const CxMap *src, const CxList *keys) {
+    return cxMapListDifference(dst, src, keys, use_simple_clone_func(src));
+}
+
+int cxMapIntersectionSimple(CxMap *dst, const CxMap *src, const CxMap *other) {
+    return cxMapIntersection(dst, src, other, use_simple_clone_func(src));
+}
+
+int cxMapListIntersectionSimple(CxMap *dst, const CxMap *src, const CxList *keys) {
+    return cxMapListIntersection(dst, src, keys, use_simple_clone_func(src));
+}
+
+int cxMapUnionSimple(CxMap *dst, const CxMap *src) {
+    return cxMapUnion(dst, src, use_simple_clone_func(src));
+}

mercurial