src/kv_list.c

changeset 1379
9ad4a7011528
parent 1378
1b4fa55f7caa
equal deleted inserted replaced
1378:1b4fa55f7caa 1379:9ad4a7011528
489 } 489 }
490 490
491 int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value) { 491 int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value) {
492 cx_kv_list *kv_list = (cx_kv_list*)list; 492 cx_kv_list *kv_list = (cx_kv_list*)list;
493 493
494 // add the new node via emplacement (we don't want to look up the node again) 494 // insert the node
495 void *node_data = cxListEmplaceAt(list, index); 495 void *node_data = kv_list->list_methods->insert_element(&kv_list->list.base, index,
496 kv_list->list.base.collection.store_pointer ? &value : value);
496 if (node_data == NULL) return -1; // LCOV_EXCL_LINE 497 if (node_data == NULL) return -1; // LCOV_EXCL_LINE
497
498 // copy the data
499 if (list->collection.store_pointer) {
500 memcpy(node_data, &value, sizeof(void*));
501 } else {
502 memcpy(node_data, value, kv_list->list.base.collection.elem_size);
503 }
504 498
505 // add the key to the map 499 // add the key to the map
506 kv_list->map_methods->put(&kv_list->map->map_base.base, key, node_data); 500 kv_list->map_methods->put(&kv_list->map->map_base.base, key, node_data);
507 // TODO: get rid of the node again, when adding the entry to the map failed 501 // TODO: get rid of the node again, when adding the entry to the map failed
508 502

mercurial