src/tree.c

changeset 840
4f02995ce44e
parent 838
1ce90ab4fab9
child 845
2615317311b7
equal deleted inserted replaced
839:62d3aecc5bb7 840:4f02995ce44e
195 if (children == NULL) { 195 if (children == NULL) {
196 // search for the next node 196 // search for the next node
197 void *next; 197 void *next;
198 cx_tree_iter_search_next: 198 cx_tree_iter_search_next:
199 // check if there is a sibling 199 // check if there is a sibling
200 next = tree_next(iter->node); 200 if (iter->exiting) {
201 next = iter->next;
202 } else {
203 next = tree_next(iter->node);
204 iter->next = next;
205 }
201 if (next == NULL) { 206 if (next == NULL) {
202 // no sibling, we are done with this node and exit 207 // no sibling, we are done with this node and exit
203 if (iter->visit_on_exit && !iter->exiting) { 208 if (iter->visit_on_exit && !iter->exiting) {
204 // iter is supposed to visit the node again 209 // iter is supposed to visit the node again
205 iter->exiting = true; 210 iter->exiting = true;
206 } else { 211 } else {
207 iter->exiting = false; 212 iter->exiting = false;
208 if (iter->depth == 1) { 213 if (iter->depth == 1) {
209 // there is no parent - we have iterated the entire tree 214 // there is no parent - we have iterated the entire tree
210 // invalidate the iterator and free the node stack 215 // invalidate the iterator and free the node stack
211 iter->node = NULL; 216 iter->node = iter->next = NULL;
212 iter->stack_capacity = iter->depth = 0; 217 iter->stack_capacity = iter->depth = 0;
213 free(iter->stack); 218 free(iter->stack);
214 iter->stack = NULL; 219 iter->stack = NULL;
215 } else { 220 } else {
216 // the parent node can be obtained from the top of stack 221 // the parent node can be obtained from the top of stack

mercurial