From 849f185a20ea2216f2f780f872b6cd8bac854d2b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 21 Aug 2021 15:00:44 -0700 Subject: [PATCH] add memory kv store --- weed/util/bptree/tree_store/memory_store.go | 29 ++++++++++++++++++++ weed/util/bptree/tree_store/tree_store.go.go | 6 ++++ 2 files changed, 35 insertions(+) create mode 100644 weed/util/bptree/tree_store/memory_store.go create mode 100644 weed/util/bptree/tree_store/tree_store.go.go diff --git a/weed/util/bptree/tree_store/memory_store.go b/weed/util/bptree/tree_store/memory_store.go new file mode 100644 index 000000000..467455664 --- /dev/null +++ b/weed/util/bptree/tree_store/memory_store.go @@ -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 +} diff --git a/weed/util/bptree/tree_store/tree_store.go.go b/weed/util/bptree/tree_store/tree_store.go.go new file mode 100644 index 000000000..6a0af6ae6 --- /dev/null +++ b/weed/util/bptree/tree_store/tree_store.go.go @@ -0,0 +1,6 @@ +package tree_store + +type TreeStore interface { + Put(k int64, v []byte) error + Get(k int64) ([]byte, error) +}