src/tree.c

changeset 1690
7d41291b3095
parent 1689
a5b7cf49dea7
equal deleted inserted replaced
1689:a5b7cf49dea7 1690:7d41291b3095
312 } 312 }
313 } else { 313 } else {
314 // node has children, push the first child onto the stack and enter it 314 // node has children, push the first child onto the stack and enter it
315 if (iter->depth >= iter->stack_capacity) { 315 if (iter->depth >= iter->stack_capacity) {
316 const size_t newcap = iter->stack_capacity + 8; 316 const size_t newcap = iter->stack_capacity + 8;
317 if (cxReallocArrayDefault(&iter->stack, newcap, sizeof(void*))) { 317 if (cxReallocateArrayDefault(&iter->stack, newcap, sizeof(void*))) {
318 // we cannot return an error in this function 318 // we cannot return an error in this function
319 abort(); // LCOV_EXCL_LINE 319 abort(); // LCOV_EXCL_LINE
320 } 320 }
321 iter->stack_capacity = newcap; 321 iter->stack_capacity = newcap;
322 } 322 }
566 void cxTreeAddNode(CxTree *tree, void *parent, void *child) { 566 void cxTreeAddNode(CxTree *tree, void *parent, void *child) {
567 cx_tree_add(parent, child, tree_layout(tree)); 567 cx_tree_add(parent, child, tree_layout(tree));
568 tree->collection.size++; 568 tree->collection.size++;
569 } 569 }
570 570
571 void *cxTreeCreateNode(CxTree *tree, void *parent) {
572 void *node = cxZalloc(tree->collection.allocator, tree->node_size);
573 if (node == NULL) return NULL; // LCOV_EXCL_LINE
574 cx_tree_add(parent, node, tree_layout(tree));
575 tree->collection.size++;
576 return node;
577 }
578
571 void *cxTreeAddData(CxTree *tree, void *parent, const void *data) { 579 void *cxTreeAddData(CxTree *tree, void *parent, const void *data) {
572 if (tree->loc_data < 0) return NULL; 580 if (tree->loc_data < 0) return NULL;
573 581
574 void *node = cxZalloc(tree->collection.allocator, tree->node_size); 582 void *node = cxTreeCreateNode(tree, parent);
575 if (node == NULL) return NULL; // LCOV_EXCL_LINE 583 if (node == NULL) return NULL; // LCOV_EXCL_LINE
576 584
577 char *dst = node; 585 char *dst = node;
578 dst += tree->loc_data; 586 dst += tree->loc_data;
579 const void *src = cxCollectionStoresPointers(tree) ? (const void*)&data : data; 587 const void *src = cxCollectionStoresPointers(tree) ? (const void*)&data : data;
580 memcpy(dst, src, tree->collection.elem_size); 588 memcpy(dst, src, tree->collection.elem_size);
581 589
582 cx_tree_add(parent, node, tree_layout(tree));
583 tree->collection.size++;
584 return node; 590 return node;
585 } 591 }
586 592
587 void *cxTreeCreateRoot(CxTree *tree) { 593 void *cxTreeCreateRoot(CxTree *tree) {
588 if (tree->root != NULL) { 594 if (tree->root != NULL) {

mercurial