-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwindows.go
64 lines (54 loc) · 931 Bytes
/
windows.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package window
import "sort"
//Windows ...
type Windows []*TimeWindow
//NewWindows ...
func NewWindows() Windows {
return make([]*TimeWindow, 0)
}
//Len ...
func (o Windows) Len() int {
return len(o)
}
//Swap ...
func (o Windows) Swap(i, j int) {
o[i], o[j] = o[j], o[i]
}
//Less ...
func (o Windows) Less(i, j int) bool {
return o[i].GetStart() <= o[j].GetStart()
}
//Sort ...
func (o *Windows) Sort() {
sort.Stable(o)
}
//Add ...
func (o *Windows) Add(w *TimeWindow) bool {
for _, tw := range *o {
//w已经在了,直接返回
if tw.GetName() == w.GetName() {
return false
}
}
//添加到windows中
*o = append(*o, w)
//从小到大排列
o.Sort()
return true
}
//Peek ...
func (o Windows) Peek() *TimeWindow {
if len(o) == 0 {
return nil
}
return o[0]
}
//PopFront ...
func (o *Windows) PopFront() *TimeWindow {
if len(*o) == 0 {
return nil
}
tw := (*o)[0]
*o = (*o)[1:]
return tw
}