-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlist.go
55 lines (45 loc) · 1 KB
/
list.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
package sqlbuilder
//
// Author: 陈永佳 [email protected], [email protected]
//
//
const SQLMaxColumns = 255
const SQLDefaultColumns = 64
type List struct {
items []interface{}
cursor int
}
func newItems() *List {
return &List{
items: make([]interface{}, SQLDefaultColumns, SQLMaxColumns),
cursor: 0,
}
}
func (slf *List) Count() int {
return slf.cursor
}
func (slf *List) Range(it func(index int, val interface{}) bool) {
for i, v := range slf.AvailableItems() {
if !it(i, v) {
break
}
}
}
func (slf *List) Add(val interface{}) {
for slf.cursor >= len(slf.items) {
slf.items = append(slf.items, make([]interface{}, 8)...)
}
slf.items[slf.cursor] = val
slf.cursor++
}
func (slf *List) SetAt(val interface{}, index int) {
slf.items[index] = val
}
func (slf *List) AvailableItems() []interface{} {
return slf.items[:slf.cursor]
}
func (slf *List) AvailableStrItems() []string {
return MapAny(slf.AvailableItems(), func(val interface{}) string {
return val.(string)
})
}