diff -r ff8ad2c9e1bd -r ec1f2015ec79 src/cx/tree.h --- a/src/cx/tree.h Sun Oct 06 19:02:32 2024 +0200 +++ b/src/cx/tree.h Sun Oct 06 19:17:41 2024 +0200 @@ -1157,8 +1157,29 @@ } /** + * Sets the (new) parent of the specified child. + * + * If the \p child is not already member of the tree, this function behaves + * as #cxTreeAddChildNode(). + * + * @param tree the tree + * @param parent the (new) parent of the child + * @param child the node to add + * @see cxTreeAddChildNode() + */ +__attribute__((__nonnull__)) +void cxTreeSetParent( + CxTree *tree, + void *parent, + void *child +); + +/** * Adds a new node to the tree. * + * If the \p child is already member of the tree, the behavior is undefined. + * Use #cxTreeSetParent() if you want to move a subtree to another location. + * * \attention The node may be externally created, but MUST obey the same rules * as if it was created by the tree itself with #cxTreeAddChild() (e.g. use * the same allocator). @@ -1166,15 +1187,14 @@ * @param tree the tree * @param parent the parent of the node to add * @param child the node to add + * @see cxTreeSetParent() */ __attribute__((__nonnull__)) -static inline void cxTreeAddChildNode( +void cxTreeAddChildNode( CxTree *tree, void *parent, - void *child) { - cx_tree_link(parent, child, cx_tree_node_layout(tree)); - tree->size++; -} + void *child +); /** * Creates a new node and adds it to the tree.