diff -r 1562bdf948da -r 1b4fa55f7caa src/kv_list.c --- a/src/kv_list.c Wed Sep 17 22:45:00 2025 +0200 +++ b/src/kv_list.c Thu Sep 18 00:36:42 2025 +0200 @@ -489,5 +489,26 @@ } int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value) { - return -1; + cx_kv_list *kv_list = (cx_kv_list*)list; + + // add the new node via emplacement (we don't want to look up the node again) + void *node_data = cxListEmplaceAt(list, index); + if (node_data == NULL) return -1; // LCOV_EXCL_LINE + + // copy the data + if (list->collection.store_pointer) { + memcpy(node_data, &value, sizeof(void*)); + } else { + memcpy(node_data, value, kv_list->list.base.collection.elem_size); + } + + // add the key to the map + kv_list->map_methods->put(&kv_list->map->map_base.base, key, node_data); + // TODO: get rid of the node again, when adding the entry to the map failed + + // write the key to the node + CxHashKey *loc_key = cx_kv_list_loc_key(kv_list, node_data); + *loc_key = key; + + return 0; }