mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add memory kv store
This commit is contained in:
parent
5f6cc9a814
commit
849f185a20
29
weed/util/bptree/tree_store/memory_store.go
Normal file
29
weed/util/bptree/tree_store/memory_store.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package tree_store
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
NotFound = errors.New("not found")
|
||||
)
|
||||
|
||||
type MemoryTreeStore struct {
|
||||
m map[int64][]byte
|
||||
}
|
||||
|
||||
func NewMemoryTreeStore() *MemoryTreeStore{
|
||||
return &MemoryTreeStore{
|
||||
m: make(map[int64][]byte),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MemoryTreeStore) Put(k int64, v []byte) error {
|
||||
m.m[k] = v
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MemoryTreeStore) Get(k int64) ([]byte, error) {
|
||||
if v, found := m.m[k]; found {
|
||||
return v, nil
|
||||
}
|
||||
return nil, NotFound
|
||||
}
|
6
weed/util/bptree/tree_store/tree_store.go.go
Normal file
6
weed/util/bptree/tree_store/tree_store.go.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package tree_store
|
||||
|
||||
type TreeStore interface {
|
||||
Put(k int64, v []byte) error
|
||||
Get(k int64) ([]byte, error)
|
||||
}
|
Loading…
Reference in a new issue