-
Notifications
You must be signed in to change notification settings - Fork 0
/
kvstore.h
58 lines (38 loc) · 1.07 KB
/
kvstore.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef LSM_KV__KVSTORE_H_
#define LSM_KV__KVSTORE_H_
#include <assert.h>
#include <unistd.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include "SSTable.h"
#include "SkipList.h"
#include "kvstore_api.h"
#include "utils.h"
using namespace std;
class KVStore : public KVStoreAPI {
private:
string storagePath;
uint64_t timeStamp;
int fileNums;
SkipList memTable;
map<string, SSTableCache *> cache;
// if memTable is large enough to be converted to a SSTable
static inline bool overflow(unsigned long length, unsigned long valueSize);
void compaction(int level);
// utils
// return 2^n
static int pow2(int n);
// extract level from a path
static int getLevel(const string &path);
public:
explicit KVStore(const string &_storagePath);
virtual ~KVStore();
void put(uint64_t key, const string &value) override;
string get(uint64_t key) override;
bool del(uint64_t key) override;
void reset() override;
};
#endif // LSM_KV__KVSTORE_H_