Skip to content

Commit b3860f5

Browse files
authored
Add doc.go (#8)
1 parent 2fe0d91 commit b3860f5

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88

99
A generic unbalanced tree implementation, where you can define which node will be added to each node.
1010

11+
## Installation
12+
13+
* With `go get`:
14+
15+
```bash
16+
go get -u github.com/johnfercher/tree
17+
```
18+
19+
## Example
20+
1121
```golang
1222
package main
1323

docs/doc.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
1+
/*
2+
# Tree
3+
4+
A generic unbalanced tree implementation, where you can define which node will be added to each node.
5+
6+
## Installation
7+
8+
* With `go get`:
9+
10+
```bash
11+
go get -u github.com/johnfercher/tree
12+
```
13+
14+
## Example
15+
16+
```golang
17+
package main
18+
19+
import (
20+
21+
"fmt"
22+
23+
"github.com/johnfercher/tree/pkg/tree"
24+
25+
)
26+
27+
// nolint:gomnd,gocritic
28+
29+
func main() {
30+
tr := tree.New[string]()
31+
32+
tr.AddRoot(tree.NewNode(0, "0.0"))
33+
34+
tr.Add(0, tree.NewNode(1, "0.1"))
35+
tr.Add(0, tree.NewNode(2, "0.2"))
36+
37+
tr.Add(1, tree.NewNode(3, "1.3"))
38+
tr.Add(1, tree.NewNode(4, "1.4"))
39+
40+
tr.Add(2, tree.NewNode(5, "2.5"))
41+
tr.Add(2, tree.NewNode(6, "2.6"))
42+
43+
root, ok := tr.GetRoot()
44+
fmt.Println(ok) // true
45+
fmt.Println(root.Get()) // 0, 0.0
46+
47+
node, ok := tr.Get(3)
48+
fmt.Println(ok) // true
49+
fmt.Println(node.Get()) // 3, 1.3
50+
51+
structure, ok := tr.GetStructure()
52+
fmt.Println(ok) // true
53+
fmt.Println(structure) // (NULL) -> (0), (0) -> (1), (1) -> (3), (1) -> (4), (0) -> (2), (2) -> (5), (2) -> (6)
54+
55+
nodes, ok := tr.Backtrack(6)
56+
fmt.Println(ok) // true
57+
for _, node := range nodes {
58+
fmt.Println(node.Get()) // 6, 2.6; 2, 0.2; 0, 0.0
59+
}
60+
}
61+
62+
```
63+
*/
164
package docs

pkg/tree/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (t *Tree[T]) Backtrack(id int) ([]*Node[T], bool) {
6262
return n.Backtrack(), true
6363
}
6464

65-
// GetStructure retrieves Tree structure
65+
// GetStructure retrieves Tree structure.
6666
func (t *Tree[T]) GetStructure() ([]string, bool) {
6767
if t.root == nil {
6868
return nil, false

0 commit comments

Comments
 (0)