src/ucx/kv_list.c

changeset 645
0c85c4cd0dd8
parent 622
6e44c7ce0834
equal deleted inserted replaced
644:e96e92e3508f 645:0c85c4cd0dd8
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,
522 cx_kvl_at, 531 cx_kvl_at,
523 cx_kvl_find_remove, 532 cx_kvl_find_remove,
524 cx_kvl_sort, 533 cx_kvl_sort,
525 NULL, 534 NULL,
526 cx_kvl_reverse, 535 cx_kvl_reverse,
536 cx_kvl_change_capacity,
527 cx_kvl_iterator, 537 cx_kvl_iterator,
528 }; 538 };
529 539
530 static cx_map_class cx_kv_map_class = { 540 static cx_map_class cx_kv_map_class = {
531 cx_kvl_map_deallocate, 541 cx_kvl_map_deallocate,
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

mercurial