src/cx/tree.h

changeset 917
ff8ad2c9e1bd
parent 914
7da30512efc4
child 918
ec1f2015ec79
equal deleted inserted replaced
916:526ed389c3d2 917:ff8ad2c9e1bd
1085 */ 1085 */
1086 __attribute__((__nonnull__)) 1086 __attribute__((__nonnull__))
1087 size_t cxTreeDepth(CxTree *tree); 1087 size_t cxTreeDepth(CxTree *tree);
1088 1088
1089 /** 1089 /**
1090 * Creates a depth-first iterator for the specified tree starting in \p node.
1091 *
1092 * If the node is not part of the tree, the behavior is undefined.
1093 *
1094 * @param tree the tree to iterate
1095 * @param node the node where to start
1096 * @param visit_on_exit true, if the iterator shall visit a node again when
1097 * leaving the sub-tree
1098 * @return a tree iterator (depth-first)
1099 * @see cxTreeVisit()
1100 */
1101 __attribute__((__nonnull__, __warn_unused_result__))
1102 static inline CxTreeIterator cxTreeIterateSubtree(
1103 CxTree *tree,
1104 void *node,
1105 bool visit_on_exit
1106 ) {
1107 return cx_tree_iterator(
1108 node, visit_on_exit,
1109 tree->loc_children, tree->loc_next
1110 );
1111 }
1112
1113 /**
1114 * Creates a breadth-first iterator for the specified tree starting in \p node.
1115 *
1116 * If the node is not part of the tree, the behavior is undefined.
1117 *
1118 * @param tree the tree to iterate
1119 * @param node the node where to start
1120 * @return a tree visitor (a.k.a. breadth-first iterator)
1121 * @see cxTreeIterate()
1122 */
1123 __attribute__((__nonnull__, __warn_unused_result__))
1124 static inline CxTreeVisitor cxTreeVisitSubtree(CxTree *tree, void *node) {
1125 return cx_tree_visitor(
1126 node, tree->loc_children, tree->loc_next
1127 );
1128 }
1129
1130 /**
1090 * Creates a depth-first iterator for the specified tree. 1131 * Creates a depth-first iterator for the specified tree.
1091 * 1132 *
1092 * @param tree the tree to iterate 1133 * @param tree the tree to iterate
1093 * @param visit_on_exit true, if the iterator shall visit a node again when 1134 * @param visit_on_exit true, if the iterator shall visit a node again when
1094 * leaving the sub-tree 1135 * leaving the sub-tree
1095 * @return a tree iterator (depth-first) 1136 * @return a tree iterator (depth-first)
1096 * @see cxTreeVisitor() 1137 * @see cxTreeVisit()
1097 */ 1138 */
1098 __attribute__((__nonnull__, __warn_unused_result__)) 1139 __attribute__((__nonnull__, __warn_unused_result__))
1099 static inline CxTreeIterator cxTreeIterator( 1140 static inline CxTreeIterator cxTreeIterate(
1100 CxTree *tree, 1141 CxTree *tree,
1101 bool visit_on_exit 1142 bool visit_on_exit
1102 ) { 1143 ) {
1103 return cx_tree_iterator( 1144 return cxTreeIterateSubtree(tree, tree->root, visit_on_exit);
1104 tree->root, visit_on_exit,
1105 tree->loc_children, tree->loc_next
1106 );
1107 } 1145 }
1108 1146
1109 /** 1147 /**
1110 * Creates a breadth-first iterator for the specified tree. 1148 * Creates a breadth-first iterator for the specified tree.
1111 * 1149 *
1112 * @param tree the tree to iterate 1150 * @param tree the tree to iterate
1113 * @return a tree visitor (a.k.a. breadth-first iterator) 1151 * @return a tree visitor (a.k.a. breadth-first iterator)
1114 * @see cxTreeIterator() 1152 * @see cxTreeIterate()
1115 */ 1153 */
1116 __attribute__((__nonnull__, __warn_unused_result__)) 1154 __attribute__((__nonnull__, __warn_unused_result__))
1117 static inline CxTreeVisitor cxTreeVisitor(CxTree *tree) { 1155 static inline CxTreeVisitor cxTreeVisit(CxTree *tree) {
1118 return cx_tree_visitor( 1156 return cxTreeVisitSubtree(tree, tree->root);
1119 tree->root, tree->loc_children, tree->loc_next
1120 );
1121 } 1157 }
1122 1158
1123 /** 1159 /**
1124 * Adds a new node to the tree. 1160 * Adds a new node to the tree.
1125 * 1161 *

mercurial