ucx/cx/tree.h

changeset 115
e57ca2747782
parent 113
dde28a806552
equal deleted inserted replaced
114:3da24640513a 115:e57ca2747782
86 * Offset in the node struct for the next pointer. 86 * Offset in the node struct for the next pointer.
87 */ 87 */
88 ptrdiff_t loc_next; 88 ptrdiff_t loc_next;
89 /** 89 /**
90 * The total number of distinct nodes that have been passed so far. 90 * The total number of distinct nodes that have been passed so far.
91 * This includes the current node.
91 */ 92 */
92 size_t counter; 93 size_t counter;
93 /** 94 /**
94 * The currently observed node. 95 * The currently observed node.
95 * 96 *
183 * Offset in the node struct for the next pointer. 184 * Offset in the node struct for the next pointer.
184 */ 185 */
185 ptrdiff_t loc_next; 186 ptrdiff_t loc_next;
186 /** 187 /**
187 * The total number of distinct nodes that have been passed so far. 188 * The total number of distinct nodes that have been passed so far.
189 * This includes the currently visited node.
188 */ 190 */
189 size_t counter; 191 size_t counter;
190 /** 192 /**
191 * The currently observed node. 193 * The currently observed node.
192 * 194 *
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

mercurial