-
Notifications
You must be signed in to change notification settings - Fork 8
/
simple_tree_grow_spreader.go
58 lines (49 loc) · 1.13 KB
/
simple_tree_grow_spreader.go
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
//go:build !tinywasm
package gtree
import (
"fmt"
"io"
)
func newGrowSpreaderSimple(
lastNodeFormat, intermedialNodeFormat branchFormat,
) growSpreaderSimple {
return &defaultGrowSpreaderSimple{
defaultGrowerSimple: &defaultGrowerSimple{
lastNodeFormat: lastNodeFormat,
intermedialNodeFormat: intermedialNodeFormat,
enabledValidation: false,
},
}
}
type defaultGrowSpreaderSimple struct {
*defaultGrowerSimple
w io.Writer
}
func (dgs *defaultGrowSpreaderSimple) growAndSpread(w io.Writer, roots []*Node) error {
dgs.w = w
for _, root := range roots {
if err := dgs.assembleAndPrint(root); err != nil {
return err
}
}
return nil
}
func (dgs *defaultGrowSpreaderSimple) assembleAndPrint(current *Node) error {
if err := dgs.assembleBranch(current); err != nil {
return err
}
ret := current.name + "\n"
if !current.isRoot() {
ret = current.branch() + " " + current.name + "\n"
}
fmt.Fprint(dgs.w, ret)
for _, child := range current.children {
if err := dgs.assembleAndPrint(child); err != nil {
return err
}
}
return nil
}
var (
_ growSpreaderSimple = (*defaultGrowSpreaderSimple)(nil)
)