123 * |
123 * |
124 * If you want to discard the iterator before, you need to manually |
124 * If you want to discard the iterator before, you need to manually |
125 * call cxTreeIteratorDispose(). |
125 * call cxTreeIteratorDispose(). |
126 */ |
126 */ |
127 void **stack; |
127 void **stack; |
|
128 /** |
|
129 * Internal capacity of the stack. |
|
130 */ |
|
131 size_t stack_capacity; |
|
132 /** |
|
133 * Current depth. |
|
134 */ |
|
135 size_t depth; |
128 } CxTreeIterator; |
136 } CxTreeIterator; |
129 |
137 |
130 /** |
138 /** |
131 * Releases internal memory of the given tree iterator. |
139 * Releases internal memory of the given tree iterator. |
132 * @param iter the iterator |
140 * @param iter the iterator |
239 void **result, |
247 void **result, |
240 ptrdiff_t loc_children, |
248 ptrdiff_t loc_children, |
241 ptrdiff_t loc_next |
249 ptrdiff_t loc_next |
242 ); |
250 ); |
243 |
251 |
|
252 /** |
|
253 * Creates an iterator for a tree with the specified root node. |
|
254 * |
|
255 * The \p passes argument is supposed to be a combination of the flags |
|
256 * #CX_TREE_ITERATOR_ENTER, #CX_TREE_ITERATOR_NEXT_CHILD, and #CX_TREE_ITERATOR_EXIT. |
|
257 * Alternatively, the integer 1 is equivalent to just specifying #CX_TREE_ITERATOR_ENTER |
|
258 * which will cause the iterator to pass every node only once (when entering the node). |
|
259 * |
|
260 * When #CX_TREE_ITERATOR_EXIT is set, the iterator will visit a parent node again, |
|
261 * when \em every of it's children has been visited (including the case when the node does not have any children). |
|
262 * |
|
263 * When #CX_TREE_ITERATOR_NEXT_CHILD is set, the iterator will visit a parent node again, |
|
264 * when advancing from one child to the next. |
|
265 * |
|
266 * @note A tree iterator needs to maintain a stack of visited nodes, which is allocated using stdlib malloc(). |
|
267 * When the iterator becomes invalid, this memory is automatically released. However, if you wish to cancel the |
|
268 * iteration before the iterator becomes invalid by itself, you MUST call cxTreeIteratorDispose() manually to release |
|
269 * the memory. |
|
270 * |
|
271 * @remark At the moment, the returned iterator does not support cxIteratorFlagRemoval(). |
|
272 * |
|
273 * @param root the root node |
|
274 * @param passes the passes this iterator shall perform |
|
275 * @param loc_children offset in the node struct for the children linked list |
|
276 * @param loc_next offset in the node struct for the next pointer |
|
277 * @return the new tree iterator |
|
278 * @see cxTreeIteratorDispose() |
|
279 */ |
|
280 __attribute__((__nonnull__)) |
|
281 CxTreeIterator cx_tree_iterate( |
|
282 void const *root, |
|
283 int passes, |
|
284 ptrdiff_t loc_children, |
|
285 ptrdiff_t loc_next |
|
286 ); |
|
287 |
244 #ifdef __cplusplus |
288 #ifdef __cplusplus |
245 } // extern "C" |
289 } // extern "C" |
246 #endif |
290 #endif |
247 |
291 |
248 #endif //UCX_TREE_H |
292 #endif //UCX_TREE_H |