-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathTree.txt
103 lines (82 loc) · 2.91 KB
/
Tree.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
*vital/Data/Tree.txt* tree utilities library.
Maintainer: rbtnn <[email protected]>
==============================================================================
CONTENTS *Vital.Data.Tree-contents*
INTRODUCTION |Vital.Data.Tree-introduction|
INTERFACE |Vital.Data.Tree-interface|
Functions |Vital.Data.Tree-functions|
Examples |Vital.Data.Tree-examples|
==============================================================================
INTRODUCTION *Vital.Data.Tree-introduction*
*Vital.Data.Tree* is Tree Utilities Library.
==============================================================================
INTERFACE *Vital.Data.Tree-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Data.Tree-functions*
new({token},...) *Vital.Data.Tree.new()*
Create a new Tree object. There are 2 ways to create a new Tree
object.
(1) Give a dict that contains token and children in its key as
{token}
(2) Give a string as token in {token}, and multiple of children nodes
in later arguments.
Note that if you choose the (1) way, all the rest of arguments will be
silently ignored.
------------------------------------------------------------------------------
Tree.token *Vital.Data.Tree.token*
Tree.children *Vital.Data.Tree.children*
Tree.addchild *Vital.Data.Tree.addchild*
Tree.todict *Vital.Data.Tree.todict*
Tree.preorder_traversal *Vital.Data.Tree.preorder_traversal*
Tree.inorder_traversal *Vital.Data.Tree.inorder_traversal*
Tree.postorder_traversal *Vital.Data.Tree.postorder_traversal*
Tree.renderer *Vital.Data.Tree.renderer*
==============================================================================
EXAMPLES *Vital.Data.Tree-examples*
>
let s:V = vital#{plugin-name}#new()
let s:T = s:V.import('Data.Tree')
let tree_obj = s:T.new('+',1,s:T.new('-',2,3))
" or
let tree_obj = s:T.new('+', [1,s:T.new('-',2,3)] )
"
" +
" / \
" 1 -
" / \
" 2 3
"
echo tree_obj.token
" +
echo tree_obj.children
" [1,s:T.new('-',2,3)]
echo tree_obj.todict()
" {'+': ['1', {'-': ['2', '3']}]}
echo tree_obj.preorder_traversal()
" ['+', 1, '-', 2, 3]
echo tree_obj.inorder_traversal()
" [1, '+', 2, '-', 3]
echo tree_obj.postorder_traversal()
" [1, '-', 2, 3, '+']
echo tree_obj.addchild(4).todict()
" {'+': ['1', {'-': ['2', '3']}, '4']}
"
" +
" / | \
" 1 - 4
" / \
" 2 3
"
echo join(tree_obj.renderer(), "\n")
" * 3
" |
" | * 2
" | /
" * '-'
" |
" | * 1
" | /
" * '+'
<
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl