-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisk.hpp
109 lines (85 loc) · 2.03 KB
/
disk.hpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
#ifndef DISK_HPP
#define DISK_HPP
#include "SSLevel.hpp"
class disk
{
private:
string dir;
int depth = 0;
int depest = 5;
SSLevel *levels;
public:
disk(){}
disk(string path, int deep){
SET_DEPTH(deep);
SET_DIR_PATH(path);
}
~disk(){
FREE_DISK();
}
public:
void SET_DEPTH(int deep){
depest = deep;
levels = new SSLevel[depest];
}
void SET_DIR_PATH(const string path){
dir = path;
_mkdir(dir.c_str());
for(int i = 0; i < depest; ++i){
levels[i].SET_LEVEL(i);
levels[i].SET_DIR_PATH(dir + "C" + to_string(i) + "/");
if(!levels[i].GET_SIZE())
depth++;
}
}
int GET_DEPTH(){
return depth;
}
int GET_LEVEL_SST(int n){
return levels[n].GET_SIZE();
}
void WRITE_TO_SSL(int n, MAP_DATA &table){
levels[n].WRITE_TO_SST(GET_LEVEL_SST(n), table);
if(!depth)
depth++;
}
void WRITE_TO_LV0(MAP_DATA &table){
levels[0].WRITE_TO_SST(GET_LEVEL_SST(0), table);
if(!depth)
depth = 1;
}
void WRITE_TO_LEVELS(MAP_DATA &table){
int i = 0;
while(i < depth){
LV_TO_MAP(i, table);
if(levels[i].WRITE_TO_TABLES(table))
return;
++i;
}
depth++;
bool flag = levels[i].WRITE_TO_TABLES(table);
}
string GET(uint64_t key, bool &flag){
flag = false;
for(int i = 0; i < depth; ++i){
string res = levels[i].GET(key, flag);
if(res != "")
return res;
if(flag)
return "";
}
return "";
}
void LV_TO_MAP(int n, MAP_DATA &table){
levels[n].SSL_TO_MAP(table);
}
void FREE_DISK(){
delete []levels;
}
void DISK_RESET(){
for(int i = 0; i < depest; ++i)
levels[i].LEVEL_RESET();
}
};
#endif // disk_hpp