Tree Structure

1 Usages of Tree Structure

Tree structure is one of basic data structure which presents one type of nonlinear logic.

Tree structure can describe relationships in hierarchy and membership accurately.

2 Features of Tree Structure

2.1 Concepts

Information can be organized as a tree:

  1. "Node" stores a piece of information.
  2. "Children Nodes": In lower level and belong to the node. Also called "Branches".
  3. One node can have multiple children.
  4. "Parent Node": In higher level and owns the node.
  5. One node can have only one "Parent".
  6. "Descendant Nodes": All lower nodes extended recursively from children.
  7. "Ancestral Nodes": All higher nodes extended recursively from parent.
  8. "Sibling Nodes": Nodes which have same parent node.
  9. "Root Node": In top level and be ancestry of all other nodes.
  10. "Leaf Nodes": Have not children.
  11. "Hierarchy Number": The chain of sequence numbers from root to the node.
  12. "Node Name": String to describe the node.
  13. "Chain Name": The chain of node names from root to the node.
  14. "Steady Node Name": During the tree is being watched or handled, node name is not changed.
  15. "Static Tree": During the tree is being watched or handled, tree structure is not changed, that is no node is deleted, added, or moved.
  16. "Dynamic Tree": During the tree is being watched or handled, tree structure is changed, that is some nodes are deleted, added, or moved.

2.2 Identify and Locate Nodes

To locate specific node in the tree correctly:

2.3 Ordered Tree

"Ordered Tree" has following features:

So hierarchy number can be used to locate a node only for static ordered tree.

2.4 Tree with Unique Chain Names

"Tree with unique Chain Names" has following features:

So chain names can be used to locate nodes for dynamic or static tree when it is "unique chain names".

3 Implement Tree Structure

In MyBox, attributes of tree node include: ID, Title(Node Name), Order_number, Modify_Time, ID of parent node.
And each type of trees has its special data fields.

3.1 ID of Node

ID of node is generated and increased automactically, and used to identify and locate each node uniquely. It is absolutely steady attribute:

IDs of nodes have following disadvantages:

3.2 Title of Node

Title of node is string to describe node:

Because titles of children can be duplicated, if treat node title as node name, then chain name may not be unique and can not locate node correctly with it.

Titles of nodes have following advantages:

3.3 Value of Node

Value of node is stored as large text of length 2G.

In MyBox, objects handled by following functions are stored and managed in tree:

MyBox Function Fields of data
Html Tree Html codes
Texts Tree Text
Favorite Address Two fields: Address, Icon
Image Scope Fields of image scope
Row Expression JavaScript codes
Data Column Fields of column definition
SQL SQL statement
Math Function Four fields: Function Name, Variables, Expression, Domain
JavaScript JavaScript codes
JShell Java codes
JEXL Three fields: Script, Context, Parameters

3.4 Order Number of Node

Order number of node is for sorting sibling nodes, which have same parent node. It can be negative or with decimal point.

MyBox provides function to trim order numbers: reassign order numbers of sibling nodes as values increased in step value 1.

3.5 Tags of Node

4 Manage Tree Structure

4.1 Define Tags

User can define different sets of tags for each type of trees.

4.2 Examples

MyBox provides examples for functions in tree.
Click menu item "Examples" to import example data of the function.

Examples' tree view of of each function tree can be viewed in MyBox documents list.

4.3 Export

Select one node, and export its tree with this node as root:

4.4 Import

Tree information can be imported in batch:

Tree XML can be used to locate tree nodes in a file:

Can not locate node by ID when import nodes, because ID is an attribute which couples application environment tightly:

4.5 Add/Delete/Modify Nodes

Select one or multiple nodes, and:

4.6 View Nodes

Select one node:

4.7 Menu