Tree Parsing
bigtree.tree.parsing
get_common_ancestors
Get common ancestors between different branches of the same tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
Sequence[T]
|
branches belonging to the same tree |
required |
Returns:
| Type | Description |
|---|---|
list[T]
|
Common ancestors between the different branches of the same tree |
get_path
Get path from origin node to destination node from the same tree. Path is inclusive of origin and destination nodes.
Examples:
>>> from bigtree import Node, Tree, get_path
>>> a = Node(name="a")
>>> b = Node(name="b", parent=a)
>>> c = Node(name="c", parent=a)
>>> d = Node(name="d", parent=b)
>>> e = Node(name="e", parent=b)
>>> f = Node(name="f", parent=c)
>>> g = Node(name="g", parent=e)
>>> h = Node(name="h", parent=e)
>>> tree = Tree(a)
>>> tree.show()
a
βββ b
β βββ d
β βββ e
β βββ g
β βββ h
βββ c
βββ f
>>> get_path(d, d)
[Node(/a/b/d, )]
>>> get_path(d, g)
[Node(/a/b/d, ), Node(/a/b, ), Node(/a/b/e, ), Node(/a/b/e/g, )]
>>> get_path(d, f)
[Node(/a/b/d, ), Node(/a/b, ), Node(/a, ), Node(/a/c, ), Node(/a/c/f, )]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_node
|
T
|
start point of path, node to travel from |
required |
to_node
|
T
|
end point of path, node to travel to |
required |
Returns:
| Type | Description |
|---|---|
Iterable[T]
|
Path from origin to destination node from the same tree |