src/kv_list.c

changeset 1378
1b4fa55f7caa
parent 1377
1562bdf948da
child 1379
9ad4a7011528
equal deleted inserted replaced
1377:1562bdf948da 1378:1b4fa55f7caa
487 memset(loc_key, 0, sizeof(CxHashKey)); 487 memset(loc_key, 0, sizeof(CxHashKey));
488 return 0; 488 return 0;
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 return -1; 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)
495 void *node_data = cxListEmplaceAt(list, index);
496 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
505 // add the key to the map
506 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
508
509 // write the key to the node
510 CxHashKey *loc_key = cx_kv_list_loc_key(kv_list, node_data);
511 *loc_key = key;
512
513 return 0;
514 }

mercurial