Skip to content

Commit 198ac5d

Browse files
committed
update README
1 parent 8d5dbdb commit 198ac5d

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

README.md

+20-13
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ $ brew install gprof2dot
103103

104104
## Tree Demonstration
105105

106-
Here are some codes to getting started.
106+
Here are some codes to get started.
107107

108108
### Construct Tree
109109

@@ -349,7 +349,7 @@ print_tree(root, attr_list=["age"])
349349
# │ └── e [age=35]
350350
# └── c [age=60]
351351

352-
print_tree(root, attr_list=["age"], attr_bracket_open="*(", attr_bracket_close=")")
352+
print_tree(root, attr_list=["age"], attr_bracket=["*(", ")"])
353353
# a *(age=90)
354354
# ├── b *(age=65)
355355
# │ ├── d *(age=40)
@@ -400,8 +400,9 @@ print_tree(root, style="double")
400400
# ╚══ c
401401

402402
print_tree(
403-
root, style="custom",
404-
style_stem="| ", style_branch="|-- ", style_stem_final="+-- "
403+
root,
404+
style="custom",
405+
custom_style=("| ", "|-- ", "+-- "),
405406
)
406407
# a
407408
# |-- b
@@ -535,22 +536,22 @@ To find multiple nodes,
535536
from bigtree import Node, print_tree, findall, find_names, find_paths, find_attrs
536537
root = Node("a", age=90)
537538
b = Node("b", age=65, parent=root)
538-
c = Node("c", age=65, parent=root)
539+
c = Node("c", age=60, parent=root)
539540
d = Node("c", age=40, parent=c)
540541
print_tree(root, attr_list=["age"])
541542
# a [age=90]
542543
# ├── b [age=65]
543544
# └── c [age=65]
544545
# └── c [age=40]
545546

546-
findall(root, lambda node: node.age == 65)
547-
# (Node(/a/b, age=65), Node(/a/c, age=65))
547+
findall(root, lambda node: node.age >= 65)
548+
# (Node(/a, age=90), Node(/a/b, age=65))
548549

549550
find_names(root, "c")
550-
# (Node(/a/c, age=65), Node(/a/c/c, age=40))
551+
# (Node(/a/c, age=60), Node(/a/c/c, age=40))
551552

552553
find_paths(root, "/c") # partial path
553-
# (Node(/a/c, age=65), Node(/a/c/c, age=40))
554+
# (Node(/a/c, age=60), Node(/a/c/c, age=40))
554555

555556
find_attrs(root, "age", 40)
556557
# (Node(/a/c/c, age=40),)
@@ -603,6 +604,12 @@ tree_diff = get_tree_diff(root, root_other)
603604
print_tree(tree_diff)
604605
# a
605606
# └── c (-)
607+
608+
tree_diff = get_tree_diff(root, root_other, only_diff=False)
609+
print_tree(tree_diff)
610+
# a
611+
# ├── b
612+
# └── c (-)
606613
```
607614

608615
### Export Tree
@@ -802,11 +809,11 @@ from bigtree import dict_to_dag, dag_iterator
802809
relation_dict = {
803810
"a": {"step": 1},
804811
"b": {"step": 1},
805-
"c": {"parent": ["a", "b"], "step": 2},
806-
"d": {"parent": ["a", "c"], "step": 2},
807-
"e": {"parent": ["d"], "step": 3},
812+
"c": {"parents": ["a", "b"], "step": 2},
813+
"d": {"parents": ["a", "c"], "step": 2},
814+
"e": {"parents": ["d"], "step": 3},
808815
}
809-
dag = dict_to_dag(relation_dict, parent_key="parent")
816+
dag = dict_to_dag(relation_dict, parent_key="parents")
810817
print([(parent.node_name, child.node_name) for parent, child in dag_iterator(dag)])
811818
# [('a', 'd'), ('c', 'd'), ('d', 'e'), ('a', 'c'), ('b', 'c')]
812819
```

0 commit comments

Comments
 (0)