src/map.c

changeset 1579
0393c67556ec
parent 1479
ac1baaed2fd7
child 1587
7156d6699410
--- a/src/map.c	Sat Dec 13 12:09:58 2025 +0100
+++ b/src/map.c	Sat Dec 13 12:24:35 2025 +0100
@@ -326,3 +326,32 @@
 int cxMapUnionSimple(CxMap *dst, const CxMap *src) {
     return cxMapUnion(dst, src, use_simple_clone_func(src));
 }
+
+int cxMapCompare(const CxMap *map, const CxMap *other) {
+    // compare map sizes
+    const size_t size_left = cxMapSize(map);
+    const size_t size_right = cxMapSize(other);
+    if (size_left < size_right) {
+        return -1;
+    } else if (size_left > size_right) {
+        return 1;
+    }
+
+    // iterate through the first map
+    CxMapIterator iter = cxMapIterator(map);
+    cx_foreach(const CxMapEntry *, entry, iter) {
+        const void *value_left = entry->value;
+        const void *value_right = cxMapGet(other, *entry->key);
+        // if the other map does not have the key, we are done
+        if (value_right == NULL) {
+            return -1;
+        }
+        // compare the values
+        const int d = map->collection.cmpfunc(value_left, value_right);
+        if (d != 0) {
+            return d;
+        }
+    }
+
+    return 0;
+}

mercurial