forked from nutsdb/nutsdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.go
66 lines (53 loc) · 1.14 KB
/
index.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
65
66
package nutsdb
// BPTreeIdx represents the B+ tree index
type BPTreeIdx map[string]*BPTree
// BTreeIdx represents the B tree index
type BTreeIdx map[string]*BTree
// SetIdx represents the set index
type SetIdx map[string]*Set
// SortedSetIdx represents the sorted set index
type SortedSetIdx map[string]*SortedSet
// ListIdx represents the list index
type ListIdx map[string]*List
type index struct {
list ListIdx
}
func NewIndex() *index {
i := new(index)
i.list = map[string]*List{}
return i
}
func (i *index) existList(bucket string) bool {
_, isExist := i.list[bucket]
return isExist
}
func (i *index) getList(bucket string) *List {
l, isExist := i.list[bucket]
if isExist {
return l
}
l = NewList()
i.list[bucket] = l
return l
}
func (i *index) deleteList(bucket string) {
delete(i.list, bucket)
}
func (i *index) addList(bucket string) {
l := NewList()
i.list[bucket] = l
}
func (i *index) rangeList(f func(l *List)) {
for _, l := range i.list {
f(l)
}
}
func (i *index) handleListBucket(f func(bucket string) error) error {
for bucket := range i.list {
err := f(bucket)
if err != nil {
return err
}
}
return nil
}