forked from wenj91/gobatis
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoll_stack.go
More file actions
49 lines (40 loc) · 675 Bytes
/
coll_stack.go
File metadata and controls
49 lines (40 loc) · 675 Bytes
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 gobatis
import (
l "container/list"
"sync"
)
type stack struct {
list *l.List
mu sync.Mutex
}
func NewStack() *stack {
list := l.New()
return &stack{list: list,}
}
func (s *stack) Push(t interface{}){
s.mu.Lock()
defer s.mu.Unlock()
s.list.PushFront(t)
}
func (s *stack) Pop() interface{} {
s.mu.Lock()
defer s.mu.Unlock()
ele := s.list.Front()
if nil != ele {
s.list.Remove(ele)
return ele.Value
}
return nil
}
func (s *stack) Peak() interface{} {
s.mu.Lock()
defer s.mu.Unlock()
ele := s.list.Front()
return ele.Value
}
func (s *stack) Len() int {
return s.list.Len()
}
func (s *stack) IsEmpty() bool {
return s.list.Len() == 0
}