| 564 ptrdiff_t loc_last_child, |
564 ptrdiff_t loc_last_child, |
| 565 ptrdiff_t loc_prev, |
565 ptrdiff_t loc_prev, |
| 566 ptrdiff_t loc_next |
566 ptrdiff_t loc_next |
| 567 ) { |
567 ) { |
| 568 *cnode = cfunc(src, cdata); |
568 *cnode = cfunc(src, cdata); |
| 569 if (*cnode == NULL) return 1; |
569 if (*cnode == NULL) return 1; // LCOV_EXCL_LINE |
| 570 cx_tree_zero_pointers(*cnode, cx_tree_ptr_locations); |
570 cx_tree_zero_pointers(*cnode, cx_tree_ptr_locations); |
| 571 |
571 |
| 572 void *match = NULL; |
572 void *match = NULL; |
| 573 int result = cx_tree_search( |
573 int result = cx_tree_search( |
| 574 root, |
574 root, |
| 625 iter->next(iter)) { |
625 iter->next(iter)) { |
| 626 elem = *eptr; |
626 elem = *eptr; |
| 627 |
627 |
| 628 // create the new node |
628 // create the new node |
| 629 void *new_node = cfunc(elem, cdata); |
629 void *new_node = cfunc(elem, cdata); |
| 630 if (new_node == NULL) return processed; |
630 if (new_node == NULL) return processed; // LCOV_EXCL_LINE |
| 631 cx_tree_zero_pointers(new_node, cx_tree_ptr_locations); |
631 cx_tree_zero_pointers(new_node, cx_tree_ptr_locations); |
| 632 |
632 |
| 633 // start searching from current node |
633 // start searching from current node |
| 634 void *match; |
634 void *match; |
| 635 int result; |
635 int result; |
| 729 const void *data |
729 const void *data |
| 730 ) { |
730 ) { |
| 731 void *node; |
731 void *node; |
| 732 if (tree->root == NULL) { |
732 if (tree->root == NULL) { |
| 733 node = tree->node_create(data, tree); |
733 node = tree->node_create(data, tree); |
| 734 if (node == NULL) return 1; |
734 if (node == NULL) return 1; // LCOV_EXCL_LINE |
| 735 cx_tree_zero_pointers(node, cx_tree_node_layout(tree)); |
735 cx_tree_zero_pointers(node, cx_tree_node_layout(tree)); |
| 736 tree->root = node; |
736 tree->root = node; |
| 737 tree->size = 1; |
737 tree->size = 1; |
| 738 return 0; |
738 return 0; |
| 739 } |
739 } |
| 756 if (!iter->valid(iter)) return 0; |
756 if (!iter->valid(iter)) return 0; |
| 757 if (tree->root == NULL) { |
757 if (tree->root == NULL) { |
| 758 // use the first element from the iter to create the root node |
758 // use the first element from the iter to create the root node |
| 759 void **eptr = iter->current(iter); |
759 void **eptr = iter->current(iter); |
| 760 void *node = tree->node_create(*eptr, tree); |
760 void *node = tree->node_create(*eptr, tree); |
| 761 if (node == NULL) return 0; |
761 if (node == NULL) return 0; // LCOV_EXCL_LINE |
| 762 cx_tree_zero_pointers(node, cx_tree_node_layout(tree)); |
762 cx_tree_zero_pointers(node, cx_tree_node_layout(tree)); |
| 763 tree->root = node; |
763 tree->root = node; |
| 764 ins = 1; |
764 ins = 1; |
| 765 iter->next(iter); |
765 iter->next(iter); |
| 766 } |
766 } |
| 817 assert(create_func != NULL); |
817 assert(create_func != NULL); |
| 818 assert(search_func != NULL); |
818 assert(search_func != NULL); |
| 819 assert(search_data_func != NULL); |
819 assert(search_data_func != NULL); |
| 820 |
820 |
| 821 CxTree *tree = cxMalloc(allocator, sizeof(CxTree)); |
821 CxTree *tree = cxMalloc(allocator, sizeof(CxTree)); |
| 822 if (tree == NULL) return NULL; |
822 if (tree == NULL) return NULL; // LCOV_EXCL_LINE |
| 823 |
823 |
| 824 tree->cl = &cx_tree_default_class; |
824 tree->cl = &cx_tree_default_class; |
| 825 tree->allocator = allocator; |
825 tree->allocator = allocator; |
| 826 tree->node_create = create_func; |
826 tree->node_create = create_func; |
| 827 tree->search = search_func; |
827 tree->search = search_func; |
| 855 allocator = cxDefaultAllocator; |
855 allocator = cxDefaultAllocator; |
| 856 } |
856 } |
| 857 assert(root != NULL); |
857 assert(root != NULL); |
| 858 |
858 |
| 859 CxTree *tree = cxMalloc(allocator, sizeof(CxTree)); |
859 CxTree *tree = cxMalloc(allocator, sizeof(CxTree)); |
| 860 if (tree == NULL) return NULL; |
860 if (tree == NULL) return NULL; // LCOV_EXCL_LINE |
| 861 |
861 |
| 862 tree->cl = &cx_tree_default_class; |
862 tree->cl = &cx_tree_default_class; |
| 863 // set the allocator anyway, just in case... |
863 // set the allocator anyway, just in case... |
| 864 tree->allocator = allocator; |
864 tree->allocator = allocator; |
| 865 tree->node_create = NULL; |
865 tree->node_create = NULL; |
| 891 tree->size++; |
891 tree->size++; |
| 892 } |
892 } |
| 893 |
893 |
| 894 int cxTreeAddChild(CxTree *tree, void *parent, const void *data) { |
894 int cxTreeAddChild(CxTree *tree, void *parent, const void *data) { |
| 895 void *node = tree->node_create(data, tree); |
895 void *node = tree->node_create(data, tree); |
| 896 if (node == NULL) return 1; |
896 if (node == NULL) return 1; // LCOV_EXCL_LINE |
| 897 cx_tree_zero_pointers(node, cx_tree_node_layout(tree)); |
897 cx_tree_zero_pointers(node, cx_tree_node_layout(tree)); |
| 898 cx_tree_link(parent, node, cx_tree_node_layout(tree)); |
898 cx_tree_link(parent, node, cx_tree_node_layout(tree)); |
| 899 tree->size++; |
899 tree->size++; |
| 900 return 0; |
900 return 0; |
| 901 } |
901 } |
| 1069 while (q != NULL) { |
1069 while (q != NULL) { |
| 1070 struct cx_tree_visitor_queue_s *next = q->next; |
1070 struct cx_tree_visitor_queue_s *next = q->next; |
| 1071 cxFreeDefault(q); |
1071 cxFreeDefault(q); |
| 1072 q = next; |
1072 q = next; |
| 1073 } |
1073 } |
| |
1074 visitor->queue_next = visitor->queue_last = NULL; |
| 1074 } |
1075 } |
| 1075 |
1076 |
| 1076 CxTreeIterator cxTreeIterateSubtree(CxTree *tree, void *node, bool visit_on_exit) { |
1077 CxTreeIterator cxTreeIterateSubtree(CxTree *tree, void *node, bool visit_on_exit) { |
| 1077 return cx_tree_iterator( |
1078 return cx_tree_iterator( |
| 1078 node, visit_on_exit, |
1079 node, visit_on_exit, |