-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal.h
More file actions
191 lines (167 loc) · 3.99 KB
/
global.h
File metadata and controls
191 lines (167 loc) · 3.99 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#pragma once
#include<unordered_map>
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<cstdlib>
#include<string.h>
#include <map>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <random>
#include <chrono>
using namespace std;
// config浜嬪姟绯荤粺鐨勫彉閲忛厤缃?
extern chrono::duration<int64_t> log_timeout;
static constexpr int32_t INVALID_TXN_ID = -1; // 鏃犳晥浜嬪姟id
using txn_id_t = int32_t; // transaction id type
static constexpr int32_t INVALID_LSN = -1; // 鏃犳晥鏃ュ織璁板綍搴忓彿
using lsn_t = int32_t; // log sequence number type
// -------------------
const int MAX_NAME_LENGTH = 20; //鍚勭鍚嶅瓧濡傛暟鎹〃鍚嶃�佸瓧娈靛悕绛夋渶澶ч暱搴?
const int BUFFER_NUM = 200;
enum SQL_type {
SELECT,
UPDATE,
DELETE,
INSERT
};
enum Distribution_Type {
//姝f�佸垎甯?
NORMAL
//鍧囧寑鍒嗗竷
,EVENLY
};
struct Distribution;
struct DISTRIBUTION_TYPE {
//涓�鍏冩潯浠?
virtual double rate(int op, double value) = 0;
//浜屽厓鏉′欢
virtual double binary_rate(int op, const Distribution& dis) = 0;
virtual void display() = 0;
};
struct NORMAL_dis : public DISTRIBUTION_TYPE {
double mu;
double sigma;
double rate(int op, double value) {
return 0.5;
}
double binary_rate(int op, const Distribution& dis) {
return 0.5;
}
void display() {
cout << "分布为:高斯分布" << endl;
cout << "参数: mu:" << mu << " sigma:" << sigma << endl;
}
};
struct EVENLY_dis : public DISTRIBUTION_TYPE {
double MIN;
double MAX;
double rate(int op, double value);
double binary_rate(int op, const Distribution& dis) {
return 0.5;
}
void display() {
cout << "分布为:均匀分布" << endl;
cout << "参数: max:" << MAX << " min:" << MIN << endl;
}
};
struct Distribution {
Distribution_Type type;
NORMAL_dis normal_dis;
EVENLY_dis evenly_dis;
DISTRIBUTION_TYPE* dis() {
if (type == NORMAL) return &normal_dis;
return &evenly_dis;
}
};
class Global_Paras { //鐢ㄤ簬瀛樻斁涓�浜涘叏灞�鍙橀噺锛屽褰撳墠鏁版嵁搴撱�佺敤鎴风瓑锛屼笉鍙疄渚嬪寲
private:
Global_Paras();
public:
static string Current_DB;
static string Current_User;
static int Block_Size;
};
struct RID {
int blockID;
int slotID;
bool operator<(const RID& rhs) const
{
if (blockID < rhs.blockID) return true;
else if (blockID == rhs.blockID && slotID < rhs.slotID) return true;
return false;
}
};
// 浜嬪姟绯荤粺瑕佺敤鐨凴ID鍜岃〃鍚嶅瓧鑱斿悎鐨勬爣璇?
struct Trid {
string relname;
RID rid;
// 鍙瀯鎴愪竴鏉¤褰曠殑鍞竴鏍囪瘑
Trid(string name = "", RID r = RID{}) : relname(name), rid(r) {}
bool operator < (const Trid& rhs) const {
return relname < rhs.relname ||
(relname == rhs.relname && rid < rhs.rid);
}
};
enum AttrType {
INT,FLOAT,STRING
};
enum Authority {
Authority_SELECT, Authority_INSERT, Authority_DELETE, Authority_UPDATE
};
enum IndexType {
CLUSTER_INDEX,NORMAL_INDEX
};
struct DB_Info {
char DBName[MAX_NAME_LENGTH];
char Creator[MAX_NAME_LENGTH];
};
struct User_Info {
char UserName[MAX_NAME_LENGTH];
char PassWord[MAX_NAME_LENGTH];
};
struct Rel_Info {
char Rel_Name[MAX_NAME_LENGTH];
char Creator[MAX_NAME_LENGTH];
char DBName[MAX_NAME_LENGTH];
int Record_Num;
int PageID_Head;
};
struct Authority_Info {
char UserName[MAX_NAME_LENGTH];
char Rel_Name[MAX_NAME_LENGTH];
char Creator[MAX_NAME_LENGTH];
char DBName[MAX_NAME_LENGTH];
bool authority[4]; //authority[SELECT]=true/false
};
struct Page_Info {
char Rel_Name[MAX_NAME_LENGTH];
char Creator[MAX_NAME_LENGTH];
char DBName[MAX_NAME_LENGTH];
int PageID;
int NextID;
};
struct Attr_Info {
char Rel_Name[MAX_NAME_LENGTH];
char Creator[MAX_NAME_LENGTH];
char DBName[MAX_NAME_LENGTH];
char Attr_Name[MAX_NAME_LENGTH];
AttrType type;
int Length;
int Offset;
Distribution distribution;
int Num_of_Change_Records;
};
struct Index_Info {
char Rel_Name[MAX_NAME_LENGTH];
char Creator[MAX_NAME_LENGTH];
char DBName[MAX_NAME_LENGTH];
char Attr_Name[MAX_NAME_LENGTH];
char Index_Creator[MAX_NAME_LENGTH];
int Head_PageID;
IndexType type;
};