Skip to content

Commit

Permalink
Sarthak | Memtable now uses InMemoryMap instead of Node
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakMakhija committed Apr 10, 2023
1 parent 7399782 commit 7bfb203
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions storage/memory/MemTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

type MemTable struct {
head *Node
//head *Node
inMemoryMap *InMemoryMap
size uint64
totalKeys int
keyComparator comparator.KeyComparator
Expand All @@ -16,15 +17,16 @@ 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),
}
}

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
Expand All @@ -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 {
Expand Down

0 comments on commit 7bfb203

Please sign in to comment.