-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathplanner.go
More file actions
60 lines (51 loc) · 1.05 KB
/
planner.go
File metadata and controls
60 lines (51 loc) · 1.05 KB
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
/*
* Radon
*
* Copyright 2018 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/
package planner
import ()
// Plan interface.
type Plan interface {
Build() error
Type() PlanType
JSON() string
Size() int
Children() *PlanTree
}
// PlanTree is a container for all plans
type PlanTree struct {
size int
children []Plan
}
// NewPlanTree creates the new plan tree.
func NewPlanTree() *PlanTree {
return &PlanTree{
children: make([]Plan, 0, 8),
}
}
// Add used to add new plan to the tree.
func (pt *PlanTree) Add(plan Plan) error {
pt.children = append(pt.children, plan)
pt.size += plan.Size()
return nil
}
// Build used to build plans(we won't build sub-plans in this plan).
func (pt *PlanTree) Build() error {
for _, plan := range pt.children {
if err := plan.Build(); err != nil {
return err
}
}
return nil
}
// Plans returns all the plans of the tree.
func (pt *PlanTree) Plans() []Plan {
return pt.children
}
// Size used to measure the memory usage for this plantree.
func (pt *PlanTree) Size() int {
return pt.size
}