/** * Free whole tree, discarding each node with the supplied free routine. * * @param tree the tree descriptor * @param fcb free routine for each item */ void etree_free(etree_t *tree, free_fn_t fcb) { etree_foreach(tree, etree_item_free, cast_func_to_pointer(fcb)); tree->root = NULL; tree->count = 0; }
/** * Recursively apply function on each node, in depth-first mode. * * Traversal is done in such a way that the applied function can safely * free up the local node. */ void xnode_tree_foreach(xnode_t *root, data_fn_t func, void *data) { etree_t t; xnode_check(root); etree_init_root(&t, root, TRUE, offsetof(xnode_t, node)); etree_foreach(&t, func, data); }
/** * Free whole tree, discarding each node with the supplied free routine. * * @param tree the tree descriptor * @param fcb free routine for each item * @param data user-supplied argument to the free routine */ void etree_free_data(etree_t *tree, free_data_fn_t fcb, void *data) { struct etree_item_free_data_ctx ctx; ctx.fcb = fcb; ctx.data = data; etree_foreach(tree, etree_item_free_data, &ctx); tree->root = NULL; tree->count = 0; }