-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
208 lines (201 loc) · 6.13 KB
/
main.cpp
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <iostream>
#include "RM_Manager.h"
#include "IX_Manager.h"
#include "Bit_tools.h"
#include "SYS_Manager.h"
int main() {
//// auto rm_fileHandle = new RM_FileHandle;
//// char test_info[200] = "Hello world!";
//// char modi_info[200] = "Goodbye world!";
//// RID testID;
//// auto fileScan = new RM_FileScan;
////
//// RM_CreateFile((char *) "../test.db", 13 + 200);
//// RM_OpenFile((char *) "../test.db", rm_fileHandle);
//// RID rid[500];
////
//// for (int i = 0; i < 500; i++) {
//// InsertRec(rm_fileHandle, test_info, &rid[i]);
//// }
////
//// for (int i = 0; i < 250; i++) {
//// DeleteRec(rm_fileHandle, &rid[i]);
//// }
////
//// for (int i = 0; i < 250; i++) {
//// InsertRec(rm_fileHandle, modi_info, &rid[i]);
//// }
////
//// auto tmpCon = new Con;
//// tmpCon->bLhsIsAttr = 1;
//// tmpCon->bRhsIsAttr = 0;
//// tmpCon->attrType = chars;
//// tmpCon->LattrLength = sizeof(char) * 200;
//// tmpCon->LattrOffset = 0;
//// tmpCon->compOp = GEqual;
//// tmpCon->Rvalue = modi_info;
////
//// OpenScan(fileScan, rm_fileHandle, 1, tmpCon);
////
//// for (int i = 0; i < 1000; i++) {
//// auto record = new RM_Record;
//// RC result = GetNextRec(fileScan, record);
////
//// if (result == SUCCESS) {
//// printf("rec %d: %d %d %s\n", i, record->rid.pageNum, record->rid.slotNum, record->pData);
//// } else {
//// printf("rec %d: null\n", i);
//// }
//// }
////
//// RM_CloseFile(rm_fileHandle);
//
auto ix_indexHandle = new IX_IndexHandle;
CreateIndex("../test.ix", ints, sizeof(int));
OpenIndex("../test.ix", ix_indexHandle);
RID rid;
rid.bValid = true;
rid.slotNum = 1;
int testData = 42;
for (int i = 0; i < 50; i++) {
rid.pageNum = i;
InsertEntry(ix_indexHandle, (char *) &i, &rid);
}
printf("insert done\n");
for (int i = 0; i < 30; i++) {
rid.pageNum = i;
DeleteEntry(ix_indexHandle, (char *) &i, &rid, i);
}
for (int i = 0; i < 20; i++) {
rid.pageNum = i;
InsertEntry(ix_indexHandle, (char *) &i, &rid);
}
int tmp = 42;
auto indexScan = new IX_IndexScan;
OpenIndexScan(indexScan, ix_indexHandle, LEqual, (char *) &tmp);
while (true) {
RID tmpRid;
int isExist = IX_GetNextEntry(indexScan, &tmpRid);
if (isExist == INDEX_NOT_EXIST) {
break;
}
printf("rid: %d %d\n", tmpRid.pageNum, tmpRid.slotNum);
}
traverseAll(ix_indexHandle);
CloseIndex(ix_indexHandle);
auto tree = new Tree;
GetIndexTree((char *) "../test.ix", tree);
//
// CreateDB((char *)"..", (char *)"test");
// OpenDB((char *) "test");
//
// auto attributes = new AttrInfo[5];
// for (int i = 0; i < 5; i++) {
// auto cur_attr = &attributes[i];
// cur_attr->attrType = ints;
// cur_attr->attrLength = 4;
// cur_attr->attrName = new char[21];
// char tmp[10];
// sprintf(tmp, "%d", i);
// strcpy(cur_attr->attrName, (char *) "hello");
// strcat(cur_attr->attrName, tmp);
// }
// CreateTable((char *) "hello", 5, attributes);
//
// attributes = new AttrInfo[6];
// for (int i = 0; i < 6; i++) {
// auto cur_attr = &attributes[i];
// cur_attr->attrType = chars;
// cur_attr->attrLength = 4;
// cur_attr->attrName = new char[21];
// char tmp[10];
// sprintf(tmp, "%d", i);
// strcpy(cur_attr->attrName, (char *) "bye");
// strcat(cur_attr->attrName, tmp);
// }
// CreateTable((char *) "bye", 6, attributes);
//
// attributes = new AttrInfo[6];
// for (int i = 0; i < 6; i++) {
// auto cur_attr = &attributes[i];
// cur_attr->attrType = chars;
// cur_attr->attrLength = 4;
// cur_attr->attrName = new char[21];
// char tmp[10];
// sprintf(tmp, "%d", i);
// strcpy(cur_attr->attrName, (char *) "nice");
// strcat(cur_attr->attrName, tmp);
// }
// CreateTable((char *) "nice", 6, attributes);
//
// CreateIndex("hello_world", "hello", "hello0");
// CreateIndex("hello_world1", "hello", "hello2");
// CreateIndex("hello_world2", "bye", "bye1");
//
// Value test_values[5];
// for (int i = 0; i < 5; i++) {
// test_values[i].type = ints;
// test_values[i].data = new char[4];
// memcpy(test_values[i].data, &i, sizeof(int));
// }
//
// for (int i = 0; i < 10000; i++) {
// memcpy(test_values[0].data, &i, sizeof(int));
// Insert("hello", 5, test_values);
// }
//
// char full_index_name[255];
// strcpy(full_index_name, sys_dbpath);
// strcat(full_index_name, "/");
// strcat(full_index_name, sys_dbname);
// strcat(full_index_name, ".ix.");
// strcat(full_index_name, "hello");
// strcat(full_index_name, ".");
// strcat(full_index_name, "hello_world");
//
// int tmp = 1;
// char tmp_char[4];
// memcpy(tmp_char, &tmp, sizeof(int));
// auto cons = new Condition[1];
// cons->op = GEqual;
// cons->bLhsIsAttr = 1;
// cons->bRhsIsAttr = 0;
// cons->lhsAttr.attrName = new char[21];
// strcpy(cons->lhsAttr.attrName, "hello0");
// cons->rhsValue.type = ints;
// cons->rhsValue.data = tmp_char;
//
// int tmp_up = 9998;
// char tmp_up_char[4];
// memcpy(tmp_up_char, &tmp_up, sizeof(int));
// Value tmp_value;
// tmp_value.type = ints;
// tmp_value.data = tmp_up_char;
//
//// Tree tree;
//// GetIndexTree(full_index_name, &tree);
////
// Update("hello", "hello0", &tmp_value, 1, cons);
////
// Delete("hello", 1, cons);
//// for (int i = 1001; i < 5000; i++) {
//// memcpy(test_values[0].data, &i, sizeof(int));
//// Insert("hello", 5, test_values);
//// }
//
// auto index_handle = new IX_IndexHandle;
// OpenIndex(full_index_name, index_handle);
// traverseAll(index_handle);
// CloseIndex(index_handle);
////
////// Delete("hello", 1, cons);
////
////
//// DropIndex("hello_world");
//
//// DropTable((char *) "bye");
//// DropTable((char *) "nice");
//// DropTable((char *) "hello");
//// CloseDB();
//// DropDB((char *) "../test");
}