-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexManager.h
180 lines (178 loc) · 5.31 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
// IndexManager.h
//
//
// Created by 杨凯 on 15/10/23.
//
//
#ifndef ____IndexManager__
#define ____IndexManager__
#include "sqlstruct.h"
#include "BufferManager.hpp"
#include <stdio.h>
#include <string.h>
#include <iostream>
struct Integer{
int value;
bool cmp(const struct Integer &a,const struct Integer &b) const {
return a.value<b.value;
}
friend bool operator==(const struct Integer &a,const struct Integer &b){
return a.value == b.value;
}
friend bool operator>=(const struct Integer &a,const struct Integer &b){
return a.value>=b.value;
}
friend bool operator<=(const struct Integer &a,const struct Integer &b){
return a.value<=b.value;
}
friend bool operator>(const struct Integer &a,const struct Integer &b){
return a.value>b.value;
}
friend bool operator<(const struct Integer &a,const struct Integer &b){
return a.value<b.value;
}
void operator=(const int &a){
value = a;
}
Integer(const int &a){
value = a;
}
Integer(){
}
};
struct Float{
float value;
bool cmp(const struct Float &a,const struct Float &b) const {
return a.value<b.value;
}
friend bool operator==(const struct Float &a,const struct Float &b){
return fabs(a.value - b.value)<0.00001;
}
friend bool operator>=(const struct Float &a,const struct Float &b){
return a.value>=b.value;
}
friend bool operator<=(const struct Float &a,const struct Float &b){
return a.value<=b.value;
}
friend bool operator>(const struct Float &a,const struct Float &b){
return a.value>b.value;
}
friend bool operator<(const struct Float &a,const struct Float &b){
return a.value<b.value;
}
Float& operator=(const float &a){
std::cout << "enter" << a << std::endl;
value = a;
return *this;
}
Float(const float &a){
value = a;
}
Float(){
}
};
struct String{
char *value;
//static int times;
//static int create;
size_t size;
bool cmp(const struct String &a,const struct String &b) const {
return strcmp(a.value,b.value)<=0;
}
friend bool operator==(const struct String &a,const struct String &b){
if(a.size!=b.size)
return false;
else return strcmp(a.value, b.value) == 0;
}
friend bool operator>=(const struct String &a,const struct String &b){
return strcmp(a.value, b.value)>=0;
}
friend bool operator<=(const struct String &a,const struct String &b){
return strcmp(a.value,b.value)<=0;
}
friend bool operator>(const struct String &a,const struct String &b){
return strcmp(a.value, b.value)>0;
}
friend bool operator<(const struct String &a,const struct String &b){
return strcmp(a.value, b.value)<0;
}
String& operator=(const String &a){
//std::cout << "enter operator=" << std::endl;
size = a.size;
if(this!=&a){
//if(strlen(a.value) == 0){
// return *this;
//}
if(value)
delete value;
value = new char [a.size];
strcpy(value,a.value);
}
return *this;
}
String(const char *a,size_t size){
this->size = size;
value = new char [size];
//std::cout << "create " << create << " ";
//printf("%x\n",value);
//create++;
strcpy(value,a);
}
String(){
//value = NULL;
//std::cout << "create " << create << " ";
//printf("%x\n",value);
//create++;
value = NULL;
size = 0;
}
~String(){
//std::cout << "in string destory func " << times << " ";
//printf("%x\n",value);
//times++;
if(value){
delete value;
}
}
String(const String &a){
size = a.size;
value = new char[size];
strcpy(value,a.value);
}
};
class IndexManager {
public:
/*do some basic setting, using it when the first time construct db*/
void InitFromEmpty();
/*after first time construct db, then every time initialize IndexManager, call this func*/
void InitFromFile();
/*create new index(new bplustree) dataType are define in sqlstruct.h (note number of char is dataType - CHAR)
*return head addr of bpt(be store in catalog file)
*/
off_t newIndex(int dataType);
/*delete index*/
void DeleteIndex(off_t pos);
/*Insert int into bpt, pos is bpt's head addr(store in catalog file),value is the addr of this record*/
void InsertKey(off_t pos,int key,off_t value);
/*Insert float into bpt*/
void InsertKey(off_t pos,float key,off_t value);
/*insert char into bpt*/
void InsertKey(off_t pos,char *key,off_t value);
//void InsertKey(off_t pos,sqlstruct::insertitem item,off_t value);
/*delete char key*/
void DeleteKey(off_t pos,char *key);
/*delete int key*/
void DeleteKey(off_t pos,int key);
/*delete float key*/
void DeleteKey(off_t pos,float key);
/*search int key*/
off_t SearchKey(off_t pos,int key);
/*search float key*/
off_t SearchKey(off_t pos,float key);
/*search char key*/
off_t SearchKey(off_t pos,char *key);
void SetBuffer(BufferManager &buffer);
~IndexManager();
};
#endif /* defined(____IndexManager__) */