@@ -61,8 +61,9 @@ For **Tree** implementation, there are 9 main components.
6161 4 . Find single child node based on name, user-defined condition
62626 . [ ** 🔧 Helper Function** ] ( https://bigtree.readthedocs.io/en/latest/bigtree/tree/helper.html )
6363 1 . Cloning tree to another ` Node ` type
64- 2 . Prune tree
65- 3 . Get difference between two trees
64+ 2 . Get subtree (smaller tree with different root)
65+ 3 . Prune tree (smaller tree with same root)
66+ 4 . Get difference between two trees
66677 . [ ** 📊 Plotting Tree** ] ( https://bigtree.readthedocs.io/en/latest/bigtree/utils/plot.html )
6768 1 . Enhanced Reingold Tilford Algorithm to retrieve (x, y) coordinates for a tree structure
68698 . [ ** 🔨 Exporting Tree** ] ( https://bigtree.readthedocs.io/en/latest/bigtree/tree/export.html )
@@ -835,58 +836,80 @@ find_child_by_name(c, "c")
835836
836837### Helper Utility
837838
838- There following are helper functions for cloning tree to another ` Node ` type, pruning tree, and getting difference
839- between two trees.
839+ There following are helper functions for
840+ 1 . Cloning tree to another ` Node ` type
841+ 2 . Getting subtree (smaller tree with different root)
842+ 3 . Pruning tree (smaller tree with same root)
843+ 4 . Getting difference between two trees
840844
841845{emphasize-lines="6,18,38,43"}
842846``` python
843- from bigtree import BaseNode, Node, clone_tree, prune_tree , get_tree_diff
847+ from bigtree import BaseNode, Node, clone_tree, get_subtree , get_tree_diff, prune_tree, str_to_tree
844848
845- # Cloning tree from `BaseNode` to `Node` type
849+ # 1. Cloning tree from `BaseNode` to `Node` type
846850root = BaseNode(name = " a" )
847851b = BaseNode(name = " b" , parent = root)
848852clone_tree(root, Node)
849853# Node(/a, )
850854
851- # Prune tree to only path a/b
852- root = Node(" a" )
853- b = Node(" b" , parent = root)
854- c = Node(" c" , parent = root)
855- root.show()
856- # a
857- # ├── b
858- # └── c
855+ # Create a tree for future sections
856+ root = str_to_tree("""
857+ a
858+ ├── b
859+ │ ├── d
860+ │ └── e
861+ └── c
862+ └── f
863+ """ )
859864
865+ # 2. Getting subtree with root b
866+ root_subtree = get_subtree(root, " b" )
867+ root_subtree.show()
868+ # b
869+ # ├── d
870+ # └── e
871+
872+ # 3.1 Prune tree to only path a/b
860873root_pruned = prune_tree(root, " a/b" )
861874root_pruned.show()
862875# a
863876# └── b
877+ # ├── d
878+ # └── e
864879
865- # Get difference between two trees
866- root = Node(" a" )
867- b = Node(" b" , parent = root)
868- c = Node(" c" , parent = root)
869- root.show()
870- # a
871- # ├── b
872- # └── c
873-
874- root_other = Node(" a" )
875- b_other = Node(" b" , parent = root_other)
876- root_other.show()
880+ # 3.1 Prune tree to exactly path a/b
881+ root_pruned = prune_tree(root, " a/b" , exact = True )
882+ root_pruned.show()
877883# a
878884# └── b
879885
886+ # 4. Get difference between two trees
887+ root_other = str_to_tree("""
888+ a
889+ ├── b
890+ │ └── d
891+ └── c
892+ └── g
893+ """ )
894+
880895tree_diff = get_tree_diff(root, root_other)
881896tree_diff.show()
882897# a
883- # └── c (-)
898+ # ├── b
899+ # │ └── e (-)
900+ # └── c
901+ # ├── f (-)
902+ # └── g (+)
884903
885904tree_diff = get_tree_diff(root, root_other, only_diff = False )
886905tree_diff.show()
887906# a
888907# ├── b
889- # └── c (-)
908+ # │ ├── d
909+ # │ └── e (-)
910+ # └── c
911+ # ├── f (-)
912+ # └── g (+)
890913```
891914
892915### Export Tree
0 commit comments