-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtable.hpp
More file actions
72 lines (71 loc) · 1.57 KB
/
table.hpp
File metadata and controls
72 lines (71 loc) · 1.57 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
#ifndef TABLE_H
#define TABLE_H
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <string>
#include <vector>
#include "type.hpp"
#include "baseobj.hpp"
const int PAGE_SIZE = 8192;
const int NAME_LEN = 50;
struct Type {
TYPE type;
bool null;
int size;
char name[NAME_LEN];
Type(){};
Type(TYPE t, bool n, int s, char* name_) {
type = t;
null = n;
size = s;
std::memcpy(name, name_, NAME_LEN);
}
};
const int MaxCol = (PAGE_SIZE - 128) / sizeof(Type);
struct TableDesc {
int colSize;
Type colType[MaxCol];
};
struct HeadPage {
int infoHeadPage;
int pageCount;
char keyname[NAME_LEN];
TableDesc desc;
};
struct Info {
int page_id;
int offset;
bool free;
};
const int MaxInfo = (PAGE_SIZE - 16) / sizeof(Info);
struct InfoPage {
int nextPage;
int size;
Info infos[MaxInfo];
};
struct Table {
int keyoffset;
static const int RowBitmapSize = 2;
std::string filename;
std::unordered_map<void*, Info*> recordInfoMap;
std::unordered_set<void*> usedRecords, emptyRecords;
std::set<Object> key_object;
std::map<void*, int> pageIndex;
std::vector<void*> pages;
std::set<int> dirtyPages;
int rowSize;
HeadPage* head;
InfoPage* LastInfoPage;
Table(const std::string& _filename, bool init = false);
void setDirty(void* dst);
void setDirty(int page_id);
void writeback();
void* getPage(int page_id);
void* genNewRecord();
void removeRecord(void*);
void initKey();
int newPage();
};
#endif