forked from danielvladco/go-proto-gql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callstack.go
47 lines (39 loc) · 762 Bytes
/
callstack.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
package plugin
type Callstack interface {
Push(entry string)
Pop(entry string)
Has(entry string) bool
Free()
List() []string
}
func NewCallstack() Callstack {
return &callstack{stack: make(map[string]int), index: 0}
}
type callstack struct {
stack map[string]int
sorted []string
index int
}
func (c *callstack) Free() {
c.stack = make(map[string]int)
c.index = 0
}
func (c *callstack) Pop(entry string) {
delete(c.stack, entry)
c.index--
}
func (c *callstack) Push(entry string) {
c.stack[entry] = c.index
c.index++
}
func (c *callstack) List() []string {
res := make([]string, len(c.stack))
for s, si := range c.stack {
res[si] = s
}
return res
}
func (c *callstack) Has(entry string) bool {
_, ok := c.stack[entry]
return ok
}