-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.go
57 lines (48 loc) · 856 Bytes
/
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
package meta
import (
"github.com/berylyvos/yojoudb/wal"
)
// K alias for []byte
type K = []byte
// Loc alias for *wal.ChunkLoc
type Loc = *wal.ChunkLoc
type Loc1 = wal.ChunkLoc
// Indexer is the interface for in-memory index.
type Indexer interface {
Put(key K, loc Loc) Loc
Get(key K) Loc
Delete(key K) (Loc, bool)
Iterator(opt IteratorOpt) Iterator
Size() int
}
type IndexType = uint8
const (
IndexBTree IndexType = iota
IndexART
IndexSKL
)
func NewIndexer(indexType IndexType) Indexer {
switch indexType {
case IndexBTree:
return NewBTree()
case IndexART:
return NewART()
case IndexSKL:
return NewSkiplist()
default:
panic("unsupported index type")
}
}
type Iterator interface {
Rewind()
Seek(key []byte)
Next()
Valid() bool
Key() []byte
Value() Loc
Close()
}
type IteratorOpt struct {
Prefix K
Reverse bool
}