-
Notifications
You must be signed in to change notification settings - Fork 0
/
sstable.cc
41 lines (35 loc) · 1.04 KB
/
sstable.cc
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
//
// Created by yichen_X on 2023/4/1.
//
#include "sstable.h"
sstable_cache::sstable_cache(){
tag = 1;
time_stamp = 1;
pair_num = 0;
min_key = 0;
max_key = 0;
bloomfilter = new class bloomfilter();
}
sstable_cache::~sstable_cache()= default;
bool sstable_cache::is_in_range(uint64_t &key) const {
return (key >= min_key && key <= max_key);
}
index_item* sstable_cache::find_key_in_indexs(const uint64_t key, uint32_t& value_size){
//binary search to find the key
int left = 0, right = Indexs.size() - 1;
while(left <= right){
int mid = (left + right) / 2;
if(Indexs[mid].get_key() == key) {
if(mid == pair_num - 1){
value_size = 0;
}else{
value_size = Indexs[mid + 1].get_offset() - Indexs[mid].get_offset();
}
return &Indexs[mid];
}
else if(Indexs[mid].get_key() < key) left = mid + 1;
else right = mid - 1;
}
value_size = 0;
return nullptr;
}