-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
stack.go
49 lines (39 loc) · 956 Bytes
/
stack.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
package sandbox
type Stack struct {
tasksInStack []*Flow
}
func NewStackFromTasks(f ...*Flow) *Stack {
return &Stack{
tasksInStack: f,
}
}
func (s *Stack) Pop() (*Stack, *Flow) {
return &Stack{
tasksInStack: s.tasksInStack[0 : len(s.tasksInStack)-1],
}, s.tasksInStack[len(s.tasksInStack)-1]
}
func (s *Stack) Push(flow *Flow) *Stack {
return &Stack{
tasksInStack: append(append([]*Flow{}, s.tasksInStack...), flow),
}
}
func (s *Stack) Size() int {
return len(s.tasksInStack)
}
func (s *Stack) PushMulti(tasks []*Flow) *Stack {
state := append([]*Flow{}, s.tasksInStack...)
return &Stack{
tasksInStack: append(state, tasks...),
}
}
func (s *Stack) Concat(other *Stack) *Stack {
return &Stack{
tasksInStack: append(append([]*Flow{}, s.tasksInStack...), other.tasksInStack...),
}
}
func (s *Stack) FromBottom() []*Flow {
return s.tasksInStack
}
func (s *Stack) Top() *Flow {
return s.tasksInStack[len(s.tasksInStack)-1]
}