src/kv_list.c

changeset 1377
1562bdf948da
parent 1376
0698e573936f
child 1378
1b4fa55f7caa
--- a/src/kv_list.c	Tue Sep 16 22:32:23 2025 +0200
+++ b/src/kv_list.c	Wed Sep 17 22:45:00 2025 +0200
@@ -471,8 +471,21 @@
     return 0;
 }
 
-int cx_kv_list_remove_key(CxList *list, size_t index, CxHashKey key) {
-    return -1;
+int cxKvListRemoveKey(CxList *list, size_t index) {
+    cx_kv_list *kv_list = (cx_kv_list*)list;
+    void *node_data = kv_list->list_methods->at(list, index);
+    if (node_data == NULL) {
+        return 1;
+    }
+    CxHashKey *loc_key = cx_kv_list_loc_key(kv_list, node_data);
+    if (loc_key->hash == 0) {
+        return 0;
+    }
+    kv_list->map_methods->remove(&kv_list->map->map_base.base, *loc_key, NULL);
+    // also zero the memory in the list node,
+    // but don't free the key data (that was done by the map remove)
+    memset(loc_key, 0, sizeof(CxHashKey));
+    return 0;
 }
 
 int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value) {

mercurial