-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmemtable.cpp
More file actions
39 lines (34 loc) · 875 Bytes
/
Copy pathmemtable.cpp
File metadata and controls
39 lines (34 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "memtable.h"
void Memtable::put(const std::string &key, const std::string &value) {
auto it = table.find(key);
if (it != table.end()) {
if (it->second)
bytes -= it->second->size();
} else {
bytes += key.size();
}
bytes += value.size();
table[key] = value;
}
void Memtable::remove(const std::string &key) {
auto it = table.find(key);
if (it != table.end()) {
if (it->second)
bytes -= it->second->size();
} else {
bytes += key.size();
}
table[key] = std::nullopt;
}
std::optional<std::optional<std::string>>
Memtable::get(const std::string &key) const {
auto it = table.find(key);
if (it == table.end())
return std::nullopt;
return it->second;
}
size_t Memtable::byte_size() const { return bytes; }
const std::map<std::string, std::optional<std::string>> &
Memtable::entries() const {
return table;
}