From 7bfb203cb4557a46150254cf7361ad43b41d112a Mon Sep 17 00:00:00 2001 From: Sarthak Makhija Date: Mon, 10 Apr 2023 11:26:21 +0530 Subject: [PATCH] Sarthak | Memtable now uses InMemoryMap instead of Node --- storage/memory/MemTable.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/storage/memory/MemTable.go b/storage/memory/MemTable.go index ae7cf2c..276020c 100644 --- a/storage/memory/MemTable.go +++ b/storage/memory/MemTable.go @@ -7,7 +7,8 @@ import ( ) type MemTable struct { - head *Node + //head *Node + inMemoryMap *InMemoryMap size uint64 totalKeys int keyComparator comparator.KeyComparator @@ -16,7 +17,8 @@ type MemTable struct { func NewMemTable(maxLevel int, keyComparator comparator.KeyComparator) *MemTable { return &MemTable{ - head: NewNode(model.NilSlice(), model.NilSlice(), maxLevel), + //head: NewNode(model.NilSlice(), model.NilSlice(), maxLevel), + inMemoryMap: NewInMemoryMap(), size: 0, keyComparator: keyComparator, levelGenerator: utils.NewLevelGenerator(maxLevel), @@ -24,7 +26,7 @@ func NewMemTable(maxLevel int, keyComparator comparator.KeyComparator) *MemTable } func (memTable *MemTable) Put(key, value model.Slice) bool { - if ok := memTable.head.Put(key, value, memTable.keyComparator, memTable.levelGenerator); ok { + if ok := memTable.inMemoryMap.Put(key, value); ok { memTable.size = memTable.size + uint64(key.Size()) + uint64(value.Size()) memTable.totalKeys = memTable.totalKeys + 1 return ok @@ -33,15 +35,15 @@ func (memTable *MemTable) Put(key, value model.Slice) bool { } func (memTable *MemTable) Get(key model.Slice) model.GetResult { - return memTable.head.Get(key, memTable.keyComparator) + return memTable.inMemoryMap.Get(key) } func (memTable *MemTable) MultiGet(keys []model.Slice) (model.MultiGetResult, []model.Slice) { - return memTable.head.MultiGet(keys, memTable.keyComparator) + return memTable.inMemoryMap.MultiGet(keys) } func (memTable *MemTable) AllKeyValues() []model.KeyValuePair { - return memTable.head.AllKeyValues() + return memTable.inMemoryMap.AllKeyValues(memTable.keyComparator) } func (memTable *MemTable) TotalSize() uint64 {