@@ -11,7 +11,7 @@ func ExampleNew() {
11
11
tr := tree .New [string ]()
12
12
13
13
// Add nodes do tree
14
- tr .AddRoot (tree .NewNode (0 , "root" ))
14
+ tr .AddRoot (tree .NewNodeWithID (0 , "root" ))
15
15
16
16
// Do more things
17
17
}
@@ -20,63 +20,63 @@ func ExampleNew() {
20
20
func ExampleTree_AddRoot () {
21
21
tr := tree .New [int ]()
22
22
23
- tr .AddRoot (tree .NewNode (0 , 42 ))
23
+ tr .AddRoot (tree .NewNodeWithID (0 , 42 ))
24
24
25
25
// Do more things
26
26
}
27
27
28
28
// ExampleTree_GetRoot demonstrates how to retrieve root node from tree.
29
29
func ExampleTree_GetRoot () {
30
30
tr := tree .New [float64 ]()
31
- tr .AddRoot (tree .NewNode (0 , 3.14 ))
31
+ tr .AddRoot (tree .NewNodeWithID (0 , 3.14 ))
32
32
33
33
node , ok := tr .GetRoot ()
34
34
if ! ok {
35
35
return
36
36
}
37
- fmt .Println (node .Get ())
37
+ fmt .Println (node .GetData ())
38
38
39
39
// Do more things
40
40
}
41
41
42
42
// ExampleTree_Add demonstrates how to add node to tree.
43
43
func ExampleTree_Add () {
44
44
tr := tree .New [bool ]()
45
- tr .AddRoot (tree .NewNode (0 , true ))
45
+ tr .AddRoot (tree .NewNodeWithID (0 , true ))
46
46
47
- tr .Add (0 , tree .NewNode (1 , false ))
47
+ tr .Add (0 , tree .NewNodeWithID (1 , false ))
48
48
49
49
// Do more things
50
50
}
51
51
52
52
// ExampleTree_Get demonstrates how to retrieve node from tree.
53
53
func ExampleTree_Get () {
54
54
tr := tree .New [uint ]()
55
- tr .AddRoot (tree .NewNode (0 , uint (42 )))
55
+ tr .AddRoot (tree .NewNodeWithID (0 , uint (42 )))
56
56
57
57
node , ok := tr .Get (0 )
58
58
if ! ok {
59
59
return
60
60
}
61
- fmt .Println (node .Get ())
61
+ fmt .Println (node .GetData ())
62
62
63
63
// Do more things
64
64
}
65
65
66
66
// ExampleTree_Backtrack demonstrates how to retrieve path of nodes from node to root.
67
67
func ExampleTree_Backtrack () {
68
68
tr := tree .New [string ]()
69
- tr .AddRoot (tree .NewNode (0 , "root" ))
70
- tr .Add (0 , tree .NewNode (1 , "level1" ))
71
- tr .Add (1 , tree .NewNode (2 , "level2" ))
72
- tr .Add (2 , tree .NewNode (3 , "leaf" ))
69
+ tr .AddRoot (tree .NewNodeWithID (0 , "root" ))
70
+ tr .Add (0 , tree .NewNodeWithID (1 , "level1" ))
71
+ tr .Add (1 , tree .NewNodeWithID (2 , "level2" ))
72
+ tr .Add (2 , tree .NewNodeWithID (3 , "leaf" ))
73
73
74
74
nodes , ok := tr .Backtrack (3 )
75
75
if ! ok {
76
76
return
77
77
}
78
78
for _ , node := range nodes {
79
- fmt .Println (node .Get ())
79
+ fmt .Println (node .GetData ())
80
80
}
81
81
82
82
// Do more things
@@ -85,10 +85,10 @@ func ExampleTree_Backtrack() {
85
85
// ExampleTree_GetStructure demonstrates how to retrieve tree structure.
86
86
func ExampleTree_GetStructure () {
87
87
tr := tree .New [string ]()
88
- tr .AddRoot (tree .NewNode (0 , "root" ))
89
- tr .Add (0 , tree .NewNode (1 , "level1" ))
90
- tr .Add (1 , tree .NewNode (2 , "level2" ))
91
- tr .Add (2 , tree .NewNode (3 , "leaf" ))
88
+ tr .AddRoot (tree .NewNodeWithID (0 , "root" ))
89
+ tr .Add (0 , tree .NewNodeWithID (1 , "level1" ))
90
+ tr .Add (1 , tree .NewNodeWithID (2 , "level2" ))
91
+ tr .Add (2 , tree .NewNodeWithID (3 , "leaf" ))
92
92
93
93
structure , ok := tr .GetStructure ()
94
94
if ! ok {
@@ -101,30 +101,48 @@ func ExampleTree_GetStructure() {
101
101
// Do more things
102
102
}
103
103
104
+ // NewNodeWithID demonstrates how to create a node with ID.
105
+ func ExampleNewNodeWithID () {
106
+ n := tree .NewNodeWithID (0 , "node" )
107
+
108
+ n .GetData ()
109
+
110
+ // Do more things
111
+ }
112
+
104
113
// ExampleNewNode demonstrates how to create a node.
105
114
func ExampleNewNode () {
106
- n := tree .NewNode (0 , "node" )
115
+ n := tree .NewNode ("node" )
107
116
108
- n .Get ()
117
+ n .GetData ()
109
118
110
119
// Do more things
111
120
}
112
121
113
- // ExampleNode_Get demonstrates how to retrieve id and data from node.
114
- func ExampleNode_Get () {
115
- n := tree .NewNode (0 , 3.14 )
122
+ // ExampleNode_GetData demonstrates how to retrieve data from node.
123
+ func ExampleNode_GetData () {
124
+ n := tree .NewNodeWithID (0 , 3.14 )
116
125
117
- id , data := n .Get ()
118
- fmt .Println (id )
126
+ data := n .GetData ()
119
127
fmt .Println (data )
120
128
121
129
// Do more things
122
130
}
123
131
132
+ // ExampleNode_GetID demonstrates how to retrieve id from node.
133
+ func ExampleNode_GetID () {
134
+ n := tree .NewNodeWithID (0 , 3.14 )
135
+
136
+ id := n .GetID ()
137
+ fmt .Println (id )
138
+
139
+ // Do more things
140
+ }
141
+
124
142
// ExampleNode_GetNexts demonstrates how to retrieve next nodes from node.
125
143
func ExampleNode_GetNexts () {
126
- root := tree .NewNode (0 , "root" )
127
- leaf := tree .NewNode (1 , "leaf" )
144
+ root := tree .NewNodeWithID (0 , "root" )
145
+ leaf := tree .NewNodeWithID (1 , "leaf" )
128
146
129
147
root .AddNext (leaf )
130
148
nexts := root .GetNexts ()
@@ -135,19 +153,19 @@ func ExampleNode_GetNexts() {
135
153
136
154
// ExampleNode_GetPrevious demonstrates how to retrieve next nodes from node.
137
155
func ExampleNode_GetPrevious () {
138
- root := tree .NewNode (0 , "root" )
139
- leaf := tree .NewNode (1 , "leaf" )
156
+ root := tree .NewNodeWithID (0 , "root" )
157
+ leaf := tree .NewNodeWithID (1 , "leaf" )
140
158
141
159
root .AddNext (leaf )
142
160
previous := leaf .GetPrevious ()
143
- fmt .Println (previous .Get ())
161
+ fmt .Println (previous .GetData ())
144
162
145
163
// Do more things
146
164
}
147
165
148
166
// ExampleNode_IsRoot demonstrates how to retrieve info if node is root.
149
167
func ExampleNode_IsRoot () {
150
- n := tree .NewNode (0 , 'b' )
168
+ n := tree .NewNodeWithID (0 , 'b' )
151
169
152
170
root := n .IsRoot ()
153
171
fmt .Println (root )
@@ -157,8 +175,8 @@ func ExampleNode_IsRoot() {
157
175
158
176
// ExampleNode_IsLeaf demonstrates how to retrieve info if node is leaf.
159
177
func ExampleNode_IsLeaf () {
160
- n1 := tree .NewNode (0 , 'a' )
161
- n2 := tree .NewNode (0 , 'b' )
178
+ n1 := tree .NewNodeWithID (0 , 'a' )
179
+ n2 := tree .NewNodeWithID (0 , 'b' )
162
180
163
181
n1 .AddNext (n2 )
164
182
@@ -170,26 +188,26 @@ func ExampleNode_IsLeaf() {
170
188
171
189
// ExampleNode_Backtrack demonstrates how to retrieve the path between node to root.
172
190
func ExampleNode_Backtrack () {
173
- n1 := tree .NewNode (0 , 'a' )
174
- n2 := tree .NewNode (0 , 'b' )
175
- n3 := tree .NewNode (0 , 'c' )
191
+ n1 := tree .NewNodeWithID (0 , 'a' )
192
+ n2 := tree .NewNodeWithID (0 , 'b' )
193
+ n3 := tree .NewNodeWithID (0 , 'c' )
176
194
177
195
n1 .AddNext (n2 )
178
196
n2 .AddNext (n3 )
179
197
180
198
nodes := n3 .Backtrack ()
181
199
for _ , node := range nodes {
182
- fmt .Println (node .Get ())
200
+ fmt .Println (node .GetData ())
183
201
}
184
202
185
203
// Do more things
186
204
}
187
205
188
206
// ExampleNode_GetStructure demonstrates how to retrieve the tree structure from node.
189
207
func ExampleNode_GetStructure () {
190
- n1 := tree .NewNode (0 , 'a' )
191
- n2 := tree .NewNode (0 , 'b' )
192
- n3 := tree .NewNode (0 , 'c' )
208
+ n1 := tree .NewNodeWithID (0 , 'a' )
209
+ n2 := tree .NewNodeWithID (0 , 'b' )
210
+ n3 := tree .NewNodeWithID (0 , 'c' )
193
211
194
212
n1 .AddNext (n2 )
195
213
n2 .AddNext (n3 )
@@ -204,8 +222,8 @@ func ExampleNode_GetStructure() {
204
222
205
223
// ExampleNode_AddNext demonstrates how to add a node to a parent.
206
224
func ExampleNode_AddNext () {
207
- n1 := tree .NewNode (0 , 'a' )
208
- n2 := tree .NewNode (0 , 'b' )
225
+ n1 := tree .NewNodeWithID (0 , 'a' )
226
+ n2 := tree .NewNodeWithID (0 , 'b' )
209
227
210
228
n1 .AddNext (n2 )
211
229
0 commit comments