Attach a branch to a node
Hi!
I like your code very much - the quick question is:
Can you please enhance your brilliant code implementing (pseudocode) as follows:
- $branch = $node->getBranch($childNode)
This should return an array defining $childNode (what is a child node of $node) with all its children.
- $branch = $node->detatchBranch($childNode)
This should behave as (1) but also remove $childNode and all it's children from $node
- $node->attachBranch($branch)
This should attach $childNode with all its children to $node
Having this functionality this library would be really great as it would enable complex manipulation on the tree structure.
@Ziggizag
Apologies for the delay! Can you clarify, please?
Can you please enhance your brilliant code implementing (pseudocode) as follows:
- $branch = $node->getBranch($childNode)
This should return an array defining $childNode (what is a child node of $node) with all its children.
I'm unsure what you mean by that, can you elaborate?
- What node does
$noderefer to? - What node does
$childNoderefer to? Should it be a direct child of$node? - What should the structure of
$branchlook like? A list of nodes? Which nodes?
Hi,
The node is:
$node = new Node('foo');
$childNode is a direct child of a $node.
A $branch should be a structure keeping all information about a $childNode and all its children with their children and their children, etc. So, formally a $branch is a sub-tree.
The idea is to easily manipulate tree structure, like moving the entire branches (sub-trees) between nodes rather than re-creating them recursively.