Tree icon indicating copy to clipboard operation
Tree copied to clipboard

Attach a branch to a node

Open Ziggizag opened this issue 3 years ago • 2 comments

Hi!

I like your code very much - the quick question is:

Can you please enhance your brilliant code implementing (pseudocode) as follows:

  1. $branch = $node->getBranch($childNode)

This should return an array defining $childNode (what is a child node of $node) with all its children.

  1. $branch = $node->detatchBranch($childNode)

This should behave as (1) but also remove $childNode and all it's children from $node

  1. $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 avatar Nov 16 '20 19:11 Ziggizag

@Ziggizag

Apologies for the delay! Can you clarify, please?

Can you please enhance your brilliant code implementing (pseudocode) as follows:

  1. $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?

  1. What node does $node refer to?
  2. What node does $childNode refer to? Should it be a direct child of $node?
  3. What should the structure of $branch look like? A list of nodes? Which nodes?

localheinz avatar Jan 28 '23 18:01 localheinz

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.

Ziggizag avatar Mar 04 '23 21:03 Ziggizag