-
Notifications
You must be signed in to change notification settings - Fork 0
/
sstable.h
69 lines (54 loc) · 1.37 KB
/
sstable.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
#ifndef SSTABLE_H
#define SSTABLE_H
#include <cstdint>
#include <string>
#include "bloomFilter.h"
#include <vector>
#include "skiplist.h"
#include "utils.h"
class Header
{
public:
uint64_t timeStamp;
uint64_t kvNum;
uint64_t minKey;
uint64_t maxKey;
Header(uint64_t t = 0, uint64_t n = 0, uint64_t min = 0, uint64_t max = 0)
: timeStamp(t), kvNum(n), minKey(min), maxKey(max) {}
bool areaNotCross(uint64_t min, uint64_t max) {
return minKey > max || maxKey < min;
}
bool before(uint64_t time) {
return time > timeStamp;
}
bool notAfter(uint64_t time) {
return time >= timeStamp;
}
};
class DataBlock
{
public:
uint64_t key;
uint64_t offset;
uint32_t vlen;
DataBlock() {}
DataBlock(uint64_t k, uint64_t o, uint32_t v) : key(k), offset(o), vlen(v) {}
};
struct Info{
Header header;
BloomFilter bloomFilter;
std::vector<uint64_t> indexes;
};
class SSTable
{
public:
Info info;
std::vector<DataBlock> data;
std::string DFLAG = "~DELETED~";
SSTable(SkipList* list, uint64_t timestamp, std::map<uint64_t, std::string> &all, std::map<uint64_t, uint64_t> &offsets);
SSTable(uint64_t timestamp, uint64_t size, std::vector<DataBlock> &all);
SSTable(const std::string &path);
SSTable() {}
void write2file(const std::string &path);
};
#endif // SSTABLE_H