-
-
Notifications
You must be signed in to change notification settings - Fork 290
/
slice.go
54 lines (44 loc) · 843 Bytes
/
slice.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
package bools
type BoolSlice []bool
func New(a ...bool) BoolSlice {
return BoolSlice(a)
}
func (s *BoolSlice) Push(v bool) {
*s = append(*s, v)
}
func (s *BoolSlice) Update(v bool) {
*s = append(*s, v)
}
func (s *BoolSlice) Pop(i int64) (v bool) {
v = (*s)[i]
*s = append((*s)[:i], (*s)[i+1:]...)
return v
}
func (s BoolSlice) Tail(size int) BoolSlice {
length := len(s)
if length <= size {
win := make(BoolSlice, length)
copy(win, s)
return win
}
win := make(BoolSlice, size)
copy(win, s[length-size:])
return win
}
func (s *BoolSlice) Length() int {
return len(*s)
}
func (s *BoolSlice) Index(i int) bool {
length := len(*s)
if length-i < 0 || i < 0 {
return false
}
return (*s)[length-i-1]
}
func (s *BoolSlice) Last() bool {
length := len(*s)
if length > 0 {
return (*s)[length-1]
}
return false
}