-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSSTable.cpp
82 lines (72 loc) · 1.31 KB
/
SSTable.cpp
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
73
74
75
76
77
78
79
80
81
82
#include "SSTable.h"
#include "MurmurHash3.h"
SSTable::SSTable(int l, int i, uint64_t time, std::vector<bool> BF, std::vector<IndexNode> ind)
{
level = l;
id = i;
timeStamp = time;
bloomFilter = BF;
index = ind;
}
SSTable::~SSTable()
{
}
uint32_t SSTable::hasKey(uint64_t key)
{
//用BloomFilter判断是否存在key
unsigned int hash[4] = {0};
MurmurHash3_x64_128(&key, sizeof(key), 1, hash);
for (size_t i = 0; i < 4; i++)
{
if (!bloomFilter[hash[i] % BFSIZE])
{
return 0;
}
}
return searchKey(key);
}
uint32_t SSTable::searchKey(uint64_t key)
{
int left = 0, right = index.size() - 1, mid;
while (left <= right)
{
mid = (left + right) / 2;
if (index[mid].key == key)
{
return index[mid].offset;
}
if (key > index[mid].key)
{
left = mid + 1;
}
else
{
right = mid - 1;
}
}
return 0;
}
uint64_t SSTable::getTimeStamp()
{
return timeStamp;
}
int SSTable::getLevel()
{
return level;
}
int SSTable::getId()
{
return id;
}
uint64_t SSTable::getMinKey()
{
return index.front().key;
}
uint64_t SSTable::getMaxKey()
{
return index.back().key;
}
void SSTable::changeId(int newId)
{
id = newId;
}