Akseli Palén
Akseli Palén

Reputation: 28161

Name of the method that removes a tree node but keeps its children

I am developing an open source JS library that deals with tree structures and scene graphs. As it is targeted for general use, the names of the API methods should follow conventions. However, I cannot find the term for a tree operation where a node is removed from its parent so that the child nodes of the removed one become inserted to the parent to replace the position of the removed one.

To illustrate, the method X is applied to the node B in the tree:

A
|
+-B
| |
| +-C
| |
| +-D
|   |
|   +-E
|
+-F

The result of the operation:

A
|
+-C
|
+-D
| |
| +-E
|
+-F

What is the name of such operation/method X? I remember I have seen it having a specific name years ago. Splice? Reduce? Simplify? Flatten?

Upvotes: 0

Views: 43

Answers (2)

Akseli Palén
Akseli Palén

Reputation: 28161

Finally found where I saw it. A ZUI lib Jazz for Java provides a method extract() for its ZGroup nodes:

public void extract(): Extract this node from the tree, merging the nodes above and below it. If this node has a parent, then this node's children will be added to that parent's children in the same position this node was in. If this node doesn't have a parent, then its children will just be removed from it. Note that this method delays firing any necessary group events until the tree has been completely updated.

However, the ZUI lib Piccolo, the successor of Jazz, seems to have dropped the method. At least I cannot found anything like that from the Piccolo API docs. Maybe the method was unnecessary?

Upvotes: 0

Ramiz Wachtler
Ramiz Wachtler

Reputation: 5683

I would suggest to use unwrap() as it's already being used by jQuery and pretty nice describes what is being done by the operation (At least in my opinion it's easier to follow). Anyway, this kind of questions are for sure primarily opinion based, so my answer should be treated as a pure suggestion :) .

Upvotes: 1

Related Questions