src/kv_list.c

changeset 1370
607f822c79fe
parent 1369
a9989e16f7df
child 1371
37dcaeebe5ca
equal deleted inserted replaced
1369:a9989e16f7df 1370:607f822c79fe
236 cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; 236 cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list;
237 // insert the data into the list first (assume that insertion destroys the sorted property) 237 // insert the data into the list first (assume that insertion destroys the sorted property)
238 kv_list->list.base.collection.sorted = false; 238 kv_list->list.base.collection.sorted = false;
239 // TODO: use the same trick as above to increase the element size temporarily to add the key to the data 239 // TODO: use the same trick as above to increase the element size temporarily to add the key to the data
240 void *node_data = kv_list->list_methods->insert_element( 240 void *node_data = kv_list->list_methods->insert_element(
241 &kv_list->list.base, kv_list->list.base.collection.size, value); 241 &kv_list->list.base, kv_list->list.base.collection.size,
242 kv_list->list.base.collection.store_pointer ? &value : value);
242 if (node_data == NULL) return NULL; // LCOV_EXCL_LINE 243 if (node_data == NULL) return NULL; // LCOV_EXCL_LINE
243 // then insert the key into the map, referring to the node data 244 // then insert the key into the map, referring to the node data
244 // TODO: check if we still get a correct pointer when the list is storing pointers
245 return kv_list->map_methods->put(map, key, node_data); 245 return kv_list->map_methods->put(map, key, node_data);
246 } 246 }
247 247
248 void *cx_kvl_map_get(const CxMap *map, CxHashKey key) { 248 void *cx_kvl_map_get(const CxMap *map, CxHashKey key) {
249 cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; 249 cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list;
250 return kv_list->map_methods->get(map, key); 250 void *node_data = kv_list->map_methods->get(map, key);
251 if (node_data == NULL) return NULL; // LCOV_EXCL_LINE
252 // return the node data
253 return kv_list->list.base.collection.store_pointer ? *(void**)node_data : node_data;
251 } 254 }
252 255
253 int cx_kvl_map_remove(CxMap *map, CxHashKey key, void *targetbuf) { 256 int cx_kvl_map_remove(CxMap *map, CxHashKey key, void *targetbuf) {
254 cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; 257 cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list;
255 258

mercurial