-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemTable.h
72 lines (51 loc) · 1.3 KB
/
MemTable.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <string>
#include <vector>
#include <random>
#include <time.h>
#include "fuctions_in_kvstore.h"
#include "file_operation.h"
#include <iostream>
#include "fuctions_in_kvstore.h"
using namespace std;
//#define TEST_2
struct SkipNode {
uint64_t key;
string str;
vector<SkipNode*> next;
SkipNode(uint64_t k, string s, int level): key(k), str(s) {
for (int i = 0; i < level; i++)
next.push_back(nullptr);
}
};
class MemTable {
private:
SkipNode* head;
SkipNode* tail;
int maxLevel;
int randomLevel();
void clear();
SkipNode* find(uint64_t key);
int nodeLevel(vector<SkipNode*> p);
public:
MemTable(int maxlevel);
MemTable();//maxLevel=100
~MemTable();
unsigned long size_bits();
bool put(uint64_t key, const string& s);
string get(uint64_t key);
bool del(uint64_t key);
void reset();
void printNode();
vector<uint64_t> tovector_keys();
vector<uint32_t> tovector_offsets();
vector<string> tovector_strs();
sstable_header* toSSTable(uint64_t tamp, string filepath,unsigned int serial_number);
// #ifdef TEST_2
// vector<vector<uint64_t>> temp_keys_vectors;
// vector<vector<uint32_t>> temp_offsets_vectors;
// vector<string> paths;
// vector<uint64_t> find_keys_vector(string path);
// vector<string> filter_vector;
// string find_filter_vector(string path);
// #endif
};