-
Notifications
You must be signed in to change notification settings - Fork 1
/
Level.h
91 lines (73 loc) · 1.85 KB
/
Level.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Created by LSC on 2020/3/30.
//
#ifndef PROJECT1_KVSTORE_LEVEL_H
#define PROJECT1_KVSTORE_LEVEL_H
#include <cstdint>
#include <string>
#include "Mynode.h"
#include <iostream>
#include <fstream>
#include <filesystem>
//#define MAX_SIZE 33
//#define INDEX_BEGIN 33
#define MAX_SIZE 2097152
#define INDEX_BEGIN 2097152
using namespace std;
#include "Skiplist.h"
#include <vector>
struct pairs{
uint64_t key;
unsigned int offset;
unsigned int timer;
bool del;
pairs(uint64_t k,int o,uint64_t t,bool d=false):key(k),offset(o),timer(t),del(d){}
pairs(){key=0;offset=0;timer=0;del= false;}
};
struct sortNode{
uint64_t key;
std::string value;
unsigned int timer;
bool del;
sortNode(){key=0;value="";timer=0;del= false;}
};
class Sstable{
public:
unsigned int end;//存最后一个kv对结束的位置
vector<pairs*> buffer;
public:
Sstable(){end=0;}
bool find(uint64_t key,pairs &temp,int &id); //记得检查标记是否是删了的
void clear();//清空并析构
};
class Level {
public:
int level_id;
bool *is_creat;
vector<Sstable*> file;
Level(int id){
level_id=id;
is_creat =new bool[(1<<(level_id+1))+1];
for(int i=0;i<=(1<<(level_id+1));i++)
{
is_creat[i]= false;
file.push_back(nullptr);
}
}
std::string get(const pairs &ans,int id,int file_id);//从文件里取出offset
//vector<Content*> * compaction(vector<Content*> *temp);
std::string get_file_name(int level_id, int file_id);
std::string get_level_name(int level_id);
bool flush_to_file(Skiplist &,unsigned int timer);
int size()
{
int sum=0;
for(int i=0;i<(1<<(level_id+1))+1;i++)
{
if(is_creat[i])sum++;
}
return sum;
}
bool clear();
};
#endif //PROJECT1_KVSTORE_LEVEL_H