Blink DB Documentation v1.0.0
Blink DB Documentation
Loading...
Searching...
No Matches
memtable.hpp
Go to the documentation of this file.
1
9#ifndef MEM_TABLE
10#define MEM_TABLE
11
12#include "constants.hpp"
13#include "skiplist.hpp"
14
15#include <cstddef>
16#include <string>
17
23class MemTable {
24 SkipList *list;
25
26public:
27 using Iterator = SkipList::Iterator;
28
29 MemTable() : list(new SkipList()) {
30 }
31
38 void put(const std::string &key, const std::string &value) {
39 list->put(key, value);
40 }
41
51 std::pair<bool, std::string> get(const std::string &key) {
52 std::pair<bool, std::string> result = list->get(key);
53 if (!result.first) {
54 return {false, ""};
55 }
56 if (result.second == TOMBSTONE) {
57 return {false, result.second};
58 }
59 return {true, result.second};
60 }
61
67 void remove(const std::string &key) {
68 list->put(key, TOMBSTONE);
69 return;
70 }
71
77 size_t getSize() {
78 return list->getSize();
79 }
80
81 Iterator begin() {
82 return list->begin();
83 }
84
85 Iterator end() {
86 return list->end();
87 }
88
89 Iterator find(const std::string &key) {
90 return list->find(key);
91 }
92
93 ~MemTable() {
94 delete list;
95 }
96};
97
98#endif
std::pair< bool, std::string > get(const std::string &key)
Get the value associated with a key.
Definition memtable.hpp:51
void put(const std::string &key, const std::string &value)
Put a key-value pair into the MemTable.
Definition memtable.hpp:38
size_t getSize()
Get the size of the MemTable.
Definition memtable.hpp:77
void remove(const std::string &key)
Remove a key from the MemTable.
Definition memtable.hpp:67
A Iterator class for the skip list.
Definition skiplist.hpp:181
Skip List Class.
Definition skiplist.hpp:55
Constants for the database engine.
#define TOMBSTONE
TOMOBSTONE constant.
Definition constants.hpp:22
Skip List Implementation.