src/hash_map.c

changeset 1587
7156d6699410
parent 1499
d0a0a41405bb
--- a/src/hash_map.c	Sat Dec 13 15:16:25 2025 +0100
+++ b/src/hash_map.c	Sat Dec 13 16:27:16 2025 +0100
@@ -78,7 +78,7 @@
     cxFree(map->collection.allocator, map);
 }
 
-static void *cx_hash_map_put(
+static CxMapEntry cx_hash_map_put(
         CxMap *map,
         CxHashKey key,
         void *value
@@ -117,7 +117,7 @@
                 allocator,
                 sizeof(struct cx_hash_map_element_s) + map->collection.elem_size
         );
-        if (e == NULL) return NULL; // LCOV_EXCL_LINE
+        if (e == NULL) return (CxMapEntry){NULL, NULL}; // LCOV_EXCL_LINE
 
         // write the value
         if (value == NULL) {
@@ -132,7 +132,7 @@
         void *kd = cxMalloc(allocator, key.len);
         if (kd == NULL) { // LCOV_EXCL_START
             cxFree(allocator, e);
-            return NULL;
+            return (CxMapEntry){NULL, NULL};
         } // LCOV_EXCL_STOP
         memcpy(kd, key.data, key.len);
         e->key.data = kd;
@@ -152,8 +152,8 @@
         map->collection.size++;
     }
 
-    // return pointer to the element
-    return elm->data;
+    // return the entry
+    return (CxMapEntry){&elm->key, elm->data};
 }
 
 static void cx_hash_map_unlink(

mercurial