src/cx/tree.h

changeset 902
5ed7f634f046
parent 901
109567325fe7
child 903
a018f5916d3b
equal deleted inserted replaced
901:109567325fe7 902:5ed7f634f046
699 const cx_tree_class *cl; 699 const cx_tree_class *cl;
700 700
701 /** 701 /**
702 * Allocator to allocate new nodes. 702 * Allocator to allocate new nodes.
703 */ 703 */
704 CxAllocator *allocator; 704 const CxAllocator *allocator;
705 705
706 /** 706 /**
707 * A pointer to the root node. 707 * A pointer to the root node.
708 * 708 *
709 * Will be \c NULL when \c size is 0. 709 * Will be \c NULL when \c size is 0.
710 */ 710 */
711 struct cx_tree_node_base_s *root; 711 void *root;
712 712
713 /** 713 /**
714 * A function to create new nodes. 714 * A function to create new nodes.
715 * 715 *
716 * Invocations to this function will receive a pointer to this tree 716 * Invocations to this function will receive a pointer to this tree
870 * Creates a new tree structure based on the specified layout. 870 * Creates a new tree structure based on the specified layout.
871 * 871 *
872 * The specified \p allocator will be used for creating the tree struct 872 * The specified \p allocator will be used for creating the tree struct
873 * and SHALL be used by \p create_func to allocate memory for the nodes. 873 * and SHALL be used by \p create_func to allocate memory for the nodes.
874 * 874 *
875 * \note This function will also register a simple destructor which 875 * \note This function will also register an advanced destructor which
876 * will free the nodes with the allocator's free() method. 876 * will free the nodes with the allocator's free() method.
877 * 877 *
878 * @param allocator the allocator that shall be used 878 * @param allocator the allocator that shall be used
879 * @param create_func a function that creates new nodes 879 * @param create_func a function that creates new nodes
880 * @param search_func a function that compares two nodes 880 * @param search_func a function that compares two nodes
905 * 905 *
906 * Nodes created by \p create_func MUST contain #cx_tree_node_base_s as first 906 * Nodes created by \p create_func MUST contain #cx_tree_node_base_s as first
907 * member (or at least respect the default offsets specified in the tree 907 * member (or at least respect the default offsets specified in the tree
908 * struct) and they MUST be allocated with the default stdlib allocator. 908 * struct) and they MUST be allocated with the default stdlib allocator.
909 * 909 *
910 * \note This function will also register a simple destructor which 910 * \note This function will also register an advanced destructor which
911 * will free the nodes with the default stdlib allocator. 911 * will free the nodes with the #cxDefaultAllocator.
912 * 912 *
913 * @param create_func a function that creates new nodes 913 * @param create_func a function that creates new nodes
914 * @param search_func a function that compares two nodes 914 * @param search_func a function that compares two nodes
915 * @return the new tree 915 * @return the new tree
916 * @see cxTreeCreate() 916 * @see cxTreeCreate()
1079 ) { 1079 ) {
1080 return tree->cl->find(tree, subtree_root, data); 1080 return tree->cl->find(tree, subtree_root, data);
1081 } 1081 }
1082 1082
1083 /** 1083 /**
1084 * Determines the size of the specified subtree.
1085 *
1086 * @param tree the tree
1087 * @param subtree_root the root node of the subtree
1088 * @return the number of nodes in the specified subtree
1089 */
1090 __attribute__((__nonnull__))
1091 size_t cxTreeSubtreeSize(CxTree *tree, void *subtree_root);
1092
1093 /**
1084 * Creates a depth-first iterator for the specified tree. 1094 * Creates a depth-first iterator for the specified tree.
1085 * 1095 *
1086 * @param tree the tree to iterate 1096 * @param tree the tree to iterate
1087 * @param visit_on_exit true, if the iterator shall visit a node again when 1097 * @param visit_on_exit true, if the iterator shall visit a node again when
1088 * leaving the sub-tree 1098 * leaving the sub-tree

mercurial