ucx/tree.c

changeset 16
04c9f8d8f03b
parent 11
0aa8cbd7912e
child 21
5ea41679e15d
equal deleted inserted replaced
15:862ab606ee06 16:04c9f8d8f03b
39 #define tree_prev(node) CX_TREE_PTR(node, loc_prev) 39 #define tree_prev(node) CX_TREE_PTR(node, loc_prev)
40 #define tree_next(node) CX_TREE_PTR(node, loc_next) 40 #define tree_next(node) CX_TREE_PTR(node, loc_next)
41 41
42 #define cx_tree_ptr_locations \ 42 #define cx_tree_ptr_locations \
43 loc_parent, loc_children, loc_last_child, loc_prev, loc_next 43 loc_parent, loc_children, loc_last_child, loc_prev, loc_next
44
45 #define cx_tree_node_layout(tree) \
46 (tree)->loc_parent,\
47 (tree)->loc_children,\
48 (tree)->loc_last_child,\
49 (tree)->loc_prev, \
50 (tree)->loc_next
44 51
45 static void cx_tree_zero_pointers( 52 static void cx_tree_zero_pointers(
46 void *node, 53 void *node,
47 ptrdiff_t loc_parent, 54 ptrdiff_t loc_parent,
48 ptrdiff_t loc_children, 55 ptrdiff_t loc_children,
740 return result; 747 return result;
741 } 748 }
742 749
743 static size_t cx_tree_default_insert_many( 750 static size_t cx_tree_default_insert_many(
744 CxTree *tree, 751 CxTree *tree,
745 struct cx_iterator_base_s *iter, 752 CxIteratorBase *iter,
746 size_t n 753 size_t n
747 ) { 754 ) {
748 size_t ins = 0; 755 size_t ins = 0;
749 if (!iter->valid(iter)) return 0; 756 if (!iter->valid(iter)) return 0;
750 if (tree->root == NULL) { 757 if (tree->root == NULL) {
833 tree->loc_next = loc_next; 840 tree->loc_next = loc_next;
834 tree->root = NULL; 841 tree->root = NULL;
835 tree->size = 0; 842 tree->size = 0;
836 843
837 return tree; 844 return tree;
845 }
846
847 void cxTreeFree(CxTree *tree) {
848 if (tree == NULL) return;
849 if (tree->root != NULL) {
850 cxTreeClear(tree);
851 }
852 cxFree(tree->allocator, tree);
838 } 853 }
839 854
840 CxTree *cxTreeCreateWrapped( 855 CxTree *cxTreeCreateWrapped(
841 const CxAllocator *allocator, 856 const CxAllocator *allocator,
842 void *root, 857 void *root,

mercurial