-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslot.go
More file actions
88 lines (74 loc) · 1.26 KB
/
slot.go
File metadata and controls
88 lines (74 loc) · 1.26 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2017 Granitic. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be found in the LICENSE file at the root of this project.
package timer
type Slot struct {
root *Timer
length int
}
func NewSlot() *Slot {
return &Slot{}
}
func (l *Slot) Front() *Timer {
return l.root
}
func (l *Slot) Len() int {
return l.length
}
func (l *Slot) Back() (el *Timer) {
if nil != l.root {
el = l.root.prev
}
return
}
func (l *Slot) Clear() {
l.root = nil
l.length = 0
}
func (l *Slot) Push(el *Timer) {
if nil == l.root {
el.prev = el
el.next = el
l.root = el
} else {
el.next = l.root
el.prev = l.root.prev
l.root.prev.next = el
l.root.prev = el
}
el.list = l
l.length++
return
}
func (l *Slot) Pop() (el *Timer) {
if nil == l.root {
return
}
if l.root == l.root.next {
el = l.root
l.root = nil
} else {
el = l.root.prev
el.prev.next = l.root
l.root.prev = el.prev
}
el.list = nil
l.length--
return
}
func (l *Slot) Remove(el *Timer) *Timer {
if nil == l.root || l != el.list {
return nil
}
el.list = nil
l.length--
if l.root == el {
if el == el.next {
l.root = nil
return nil
}
l.root = el.next
}
el.prev.next = el.next
el.next.prev = el.prev
return el.next
}