| 639 |
641 |
| 640 /** |
642 /** |
| 641 * Structure for holding the base data of a tree. |
643 * Structure for holding the base data of a tree. |
| 642 */ |
644 */ |
| 643 struct cx_tree_s { |
645 struct cx_tree_s { |
| |
646 CX_COLLECTION_BASE; |
| 644 /** |
647 /** |
| 645 * The tree class definition. |
648 * The tree class definition. |
| 646 */ |
649 */ |
| 647 const cx_tree_class *cl; |
650 const cx_tree_class *cl; |
| 648 |
|
| 649 /** |
|
| 650 * Allocator to allocate new nodes. |
|
| 651 */ |
|
| 652 const CxAllocator *allocator; |
|
| 653 |
651 |
| 654 /** |
652 /** |
| 655 * A pointer to the root node. |
653 * A pointer to the root node. |
| 656 * |
654 * |
| 657 * Will be @c NULL when @c size is 0. |
655 * Will be @c NULL when @c size is 0. |
| 667 * Nodes MAY use #cx_tree_node_base_s as the base layout, but do not need to. |
665 * Nodes MAY use #cx_tree_node_base_s as the base layout, but do not need to. |
| 668 */ |
666 */ |
| 669 cx_tree_node_create_func node_create; |
667 cx_tree_node_create_func node_create; |
| 670 |
668 |
| 671 /** |
669 /** |
| 672 * An optional simple destructor for the tree nodes. |
|
| 673 */ |
|
| 674 cx_destructor_func simple_destructor; |
|
| 675 |
|
| 676 /** |
|
| 677 * An optional advanced destructor for the tree nodes. |
|
| 678 */ |
|
| 679 cx_destructor_func2 advanced_destructor; |
|
| 680 |
|
| 681 /** |
|
| 682 * The pointer to additional data that is passed to the advanced destructor. |
|
| 683 */ |
|
| 684 void *destructor_data; |
|
| 685 |
|
| 686 /** |
|
| 687 * A function to compare two nodes. |
670 * A function to compare two nodes. |
| 688 */ |
671 */ |
| 689 cx_tree_search_func search; |
672 cx_tree_search_func search; |
| 690 |
673 |
| 691 /** |
674 /** |
| 692 * A function to compare a node with data. |
675 * A function to compare a node with data. |
| 693 */ |
676 */ |
| 694 cx_tree_search_data_func search_data; |
677 cx_tree_search_data_func search_data; |
| 695 |
|
| 696 /** |
|
| 697 * The number of currently stored elements. |
|
| 698 */ |
|
| 699 size_t size; |
|
| 700 |
678 |
| 701 /** |
679 /** |
| 702 * Offset in the node struct for the parent pointer. |
680 * Offset in the node struct for the parent pointer. |
| 703 */ |
681 */ |
| 704 ptrdiff_t loc_parent; |
682 ptrdiff_t loc_parent; |
| 1092 * @param tree the tree to iterate |
1070 * @param tree the tree to iterate |
| 1093 * @return a tree visitor (a.k.a. breadth-first iterator) |
1071 * @return a tree visitor (a.k.a. breadth-first iterator) |
| 1094 * @see cxTreeIterate() |
1072 * @see cxTreeIterate() |
| 1095 */ |
1073 */ |
| 1096 cx_attr_nonnull cx_attr_nodiscard |
1074 cx_attr_nonnull cx_attr_nodiscard |
| 1097 CxTreeVisitor cxTreeVisit(CxTree *tree); |
1075 CX_EXPORT CxTreeVisitor cxTreeVisit(CxTree *tree); |
| 1098 |
1076 |
| 1099 /** |
1077 /** |
| 1100 * Sets the (new) parent of the specified child. |
1078 * Sets the (new) parent of the specified child. |
| 1101 * |
1079 * |
| 1102 * If the @p child is not already a member of the tree, this function behaves |
1080 * If the @p child is not already a member of the tree, this function behaves |