-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuctions_in_kvstore.cpp
46 lines (36 loc) · 1.25 KB
/
fuctions_in_kvstore.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
#include "fuctions_in_kvstore.h"
using namespace std;
string buildBloomFilter(vector<uint64_t> keys){
string filter(10240*8,'0');
uint32_t hash[4] = {0};
uint64_t size=keys.size();
for(uint64_t i = 0; i < size; i++){
MurmurHash3_x64_128(&keys[i], sizeof(keys[i]), 1, hash);
for(int k=0;k<4;k++)
if(hash[k]<10240*8&&hash[k]>=0)
filter[hash[k]]='1';
}
return filter;
}
bool checkBloomFilter(string BloomFilter,uint64_t key){
uint32_t hash[4] = {0};
MurmurHash3_x64_128(&key, sizeof(key), 1, hash);
for(int k=0;k<4;k++){
if(hash[k]<10240*8&&hash[k]>=0){
if(BloomFilter[hash[k]]=='0')
return false;
}
}
return true;
}
int min_timestamp_index(vector<uint64_t> &files_tobe_read_timestamp){
vector<uint64_t>::iterator smallest = min_element(begin(files_tobe_read_timestamp), end(files_tobe_read_timestamp));
int index=distance(begin(files_tobe_read_timestamp), smallest);
files_tobe_read_timestamp[index]=UINT64_MAX;
return index;
}
uint64_t max_timestamp(vector<uint64_t> files_tobe_read_timestamp){
vector<uint64_t>::iterator largest = max_element(begin(files_tobe_read_timestamp), end(files_tobe_read_timestamp));
int index=distance(begin(files_tobe_read_timestamp), largest);
return files_tobe_read_timestamp[index];
}