| 96 list->map->map_base.base.collection.destructor_data = NULL; |
96 list->map->map_base.base.collection.destructor_data = NULL; |
| 97 } |
97 } |
| 98 } |
98 } |
| 99 |
99 |
| 100 static CxHashKey *cx_kv_list_loc_key(cx_kv_list *list, void *node_data) { |
100 static CxHashKey *cx_kv_list_loc_key(cx_kv_list *list, void *node_data) { |
| 101 return (CxHashKey*)((char*)node_data + list->list.base.collection.elem_size); |
101 return (CxHashKey*)((char*)node_data - list->list.loc_data + list->list.loc_extra); |
| 102 } |
102 } |
| 103 |
103 |
| 104 static void cx_kvl_deallocate(struct cx_list_s *list) { |
104 static void cx_kvl_deallocate(struct cx_list_s *list) { |
| 105 cx_kv_list *kv_list = (cx_kv_list*)list; |
105 cx_kv_list *kv_list = (cx_kv_list*)list; |
| 106 // patch the destructors |
106 // patch the destructors |
| 507 } |
507 } |
| 508 |
508 |
| 509 return iter; |
509 return iter; |
| 510 } |
510 } |
| 511 |
511 |
| |
512 static int cx_kvl_change_capacity(struct cx_list_s *list, |
| |
513 cx_attr_unused size_t cap) { |
| |
514 // since our backing list is a linked list, we don't need to do much here, |
| |
515 // but rehashing the map is quite useful |
| |
516 cx_kv_list *kv_list = (cx_kv_list*)list; |
| |
517 cxMapRehash(&kv_list->map->map_base.base); |
| |
518 return 0; |
| |
519 } |
| |
520 |
| 512 static cx_list_class cx_kv_list_class = { |
521 static cx_list_class cx_kv_list_class = { |
| 513 cx_kvl_deallocate, |
522 cx_kvl_deallocate, |
| 514 cx_kvl_insert_element, |
523 cx_kvl_insert_element, |
| 515 cx_kvl_insert_array, |
524 cx_kvl_insert_array, |
| 516 cx_kvl_insert_sorted, |
525 cx_kvl_insert_sorted, |
| 547 |
557 |
| 548 // create a normal linked list and a normal hash map, first |
558 // create a normal linked list and a normal hash map, first |
| 549 CxList *list = cxLinkedListCreate(allocator, comparator, elem_size); |
559 CxList *list = cxLinkedListCreate(allocator, comparator, elem_size); |
| 550 if (list == NULL) return NULL; // LCOV_EXCL_LINE |
560 if (list == NULL) return NULL; // LCOV_EXCL_LINE |
| 551 cx_linked_list *ll = (cx_linked_list*)list; |
561 cx_linked_list *ll = (cx_linked_list*)list; |
| 552 ll->extra_data_len = sizeof(CxHashKey); |
562 cx_linked_list_extra_data(ll, sizeof(CxHashKey)); |
| 553 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0); |
563 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0); |
| 554 if (map == NULL) { // LCOV_EXCL_START |
564 if (map == NULL) { // LCOV_EXCL_START |
| 555 cxListFree(list); |
565 cxListFree(list); |
| 556 return NULL; |
566 return NULL; |
| 557 } // LCOV_EXCL_STOP |
567 } // LCOV_EXCL_STOP |