-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIndexManager.h
162 lines (154 loc) · 4.85 KB
/
IndexManager.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
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
#pragma once
#include<iostream>
#include<list>
#include"buffer.h"
#include"common.h"
#define LENGTHOFPOINTER 4;
//#define INT 4;
using namespace std;
extern class catalog cata;
extern class buffer Buffer;
class IndexLeaf {
public:
string key;
int offsetinFile;
int offsetinBlock;
IndexLeaf() :
key(""), offsetinFile(0), offsetinBlock(0) {}
IndexLeaf(string k, int oif, int oib) :
key(k), offsetinFile(oif), offsetinBlock(oib) {}
};
class IndexBranch {
public:
string key;
int ptrChild;
IndexBranch() :
key(""), ptrChild(0) {}
IndexBranch(string k, int ptrC) :
key(k), ptrChild(ptrC) {}
};
class BPlusTree {
public:
bool IntorString;
bool StringorFloat;
int blockNum;
int ptrFather; //block pointer, if is root, this pointer is useless
int recordNum;
int Max;
int columnLength;
BPlusTree() {}
//BPlusTree() : recordNum(0) {}
};
class Branch : public BPlusTree
{
public:
list<IndexBranch> nodelist;
int lastChild;
bool isRoot;
Branch() {};
void createBranch(bool IsRoot, int lengthOFcolumn, int type) {//ÏÈcreateÖ®ºóÔÙ¸³ÖµptrfatherµÈ
this->isRoot = IsRoot;
lastChild = 0;
if (type == 10)
IntorString = 1;
else if (type == 11) {
StringorFloat = 0;
IntorString = 0;
}
else if (type == 12) {
IntorString = 0;
StringorFloat = 1;
}
ptrFather = 0;
recordNum = 0;
columnLength = lengthOFcolumn;
int totallength = this->columnLength + LENGTHOFPOINTER;
this->Max = 4081 / totallength;
}
Branch(char memory[], int lengthOFcolumn, int type);
~Branch() {};
void insert(IndexBranch node);
IndexBranch pop();
IndexBranch getfront();
void writeclear() {
nodelist.pop_front();
}
void clearall();
};
class Leaf : public BPlusTree
{
public:
int nextSibling; //block pointer
int lastSibling; //block pointer
list<IndexLeaf> nodelist;
Leaf() {};
void createLeaf(int lengthOFcolumn, int type) {
ptrFather = 0;
recordNum = 0;
nextSibling = 0;
lastSibling = 0;
this->columnLength = lengthOFcolumn;
if (type == 10)
IntorString = 1;
else if (type == 11) {
IntorString = 0;
StringorFloat = 0;
}
else if (type == 12) {
IntorString = 0;
StringorFloat = 1;
}
int totallength = 2 * this->columnLength + LENGTHOFPOINTER;
this->Max = 4078 / totallength;
}
Leaf(char memory[], int lengthOFcolumn, int type);
~Leaf() {};
void insert(IndexLeaf node);
IndexLeaf pop();
IndexLeaf getfront();
void writeclear() {
nodelist.pop_front();
}
void clearall();
};
class IndexManager {
public:
void createIndex(Index& indexinfor, IndexColumn DataofIndex);
void index_insertValue(Index indexinfor, IndexColumn data);
IndexColumn selectEqual(Index indexinfor, string key/*, int blockoffset = 0*/);
IndexColumn selectBetween(Index indexinfor, string keyFrom, string keyTo/*, int& blockoffset*/);
//void dropIndex(Index& indexinfor);
void deleteValue(Index indexinfor, IndexColumn dc/*, int&blockoffset*/);
//void translateLeaf(char neicun[], Leaf needt);
//void translateBranch(char neicun[], Branch needt);
//list<IndexBranch>::iterator SearchlocaB(Branch& searched, IndexLeaf node);
//list<IndexLeaf>::iterator SearchlocaL(Leaf& searched, IndexLeaf node, bool* valid);
private:
//Row splitRow(Table tableinfor, string row);
//string getColumnValue(const Table& tableinfor, const Index& indexinfor, string row);
void insertValue(Branch& Searchnode, IndexRow dataRecord, Index& indexinfor);
void translateLeaf(char neicun[], Leaf needt);
void translateBranch(char neicun[], Branch needt);
void InttoChar(int number, int startpos, int length, char neicun[]);
int StringtoInt(string key);
//void MemorytoLeaf(char memory[], Leaf receptor);
//void MemorytoBranch(char memory[], Branch receptor);
void insertvalue(Branch& Searchnode, IndexLeaf& data, Index& indexinfor, int Fp, bool* valid, int* ptrChild, string& ckey);
void insertvalueL(Leaf& SearchnodeL, IndexLeaf& data, Index& indexinfor, bool* valid, int* prrChild, string& ckey);
list<IndexBranch>::iterator SearchlocaB(Branch& searched, IndexLeaf node, bool* valid);
list<IndexLeaf>::iterator SearchlocaL(Leaf& searched, IndexLeaf node, bool* valid);
list<IndexLeaf>::iterator SearchlocaLM(Leaf& searched, IndexLeaf node, bool* valid);
void deletevalueL(Index indexinfor, IndexLeaf &data);
void deletevalueB(Index indexinfor, Branch& Dnode, IndexLeaf &data);
list<IndexLeaf> whichDelete(Index indexinfor, string keyFrom, string keyTo, int& blockoffset);
int indextoleaf(Index indexinfor, IndexLeaf data, Leaf& getleaf, list<IndexLeaf>::iterator &location);
void changefather(Index indexinfor, Branch Tbranch);
string minkey(Index indexinfor, Branch Tbranch);
};
int comparefi(int type, string key1, string key2);
int compare(int IntorString, int StringorFloat, string key1, string key2);
float StringtoFloat(string get);
int StringtoInt(string get);
void MemorytoBranch(char memory[], Branch& receptor);
void MemorytoLeaf(char memory[], Leaf& receptor);
int getPtr(int pos, char memory[]);