-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestIndex.cpp
More file actions
92 lines (82 loc) · 2.65 KB
/
Copy pathtestIndex.cpp
File metadata and controls
92 lines (82 loc) · 2.65 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
//
// main.cpp
// DBMS
//
// Created by 张函祎 on 15/10/28.
// Copyright © 2015年 Sylvanus. All rights reserved.
//
#include <iostream>
#include <string>
#include <sstream>
#include "IndexManager.hpp"
typedef struct {
int intValue;
float floatValue;
string stringValue;
} Tuple;
int main(int argc, const char * argv[]) {
// insert code here...
vector<Tuple> value;
ifstream fin("/Users/Sylvanus/Sylvanus's Library/Studies/CS/Database/Design/DBMS/DBMS/data.txt");
if (fin.is_open()) {
string line;
getline(fin, line);
getline(fin, line);
int st, ed;
Tuple tuple;
while (getline(fin, line)) {
st = (int)line.find("(", 0)+1;
ed = (int)line.find(",", st);
stringstream stream;
stream<<line.substr(st, ed-st);
int aInt;
stream>>aInt;
tuple.intValue = aInt;
st = (int)line.find("'", ed)+1;
ed = (int)line.find("'", st);
tuple.stringValue = line.substr(st, ed-st);
st = ed+2;
ed = (int)line.find(")", st);
stream.clear();
stream<<line.substr(st, ed);
float aFloat;
stream>>aFloat;
tuple.floatValue = aFloat;
value.push_back(tuple);
}
}
random_shuffle(value.begin(), value.end());
vector<Tuple>::iterator itor;
vector<int> offset;
vector<Value> intValue;
int count = 0;
for (itor = value.begin(); itor!=value.end(); itor++) {
offset.push_back(++count);
intValue.push_back(Value((*itor).intValue));
// if (count>1000)
// break;
}
BufferManager::UseDB("TEST1");
BufferManager::CreateFile("TEST1", "t1.index", 1);
IndexManager indexManager;
indexManager.create("TEST1", "Table", "t1.index", sizeof(int), intValue, offset);
indexManager.tree.printTree(0);
cout<<"create done."<<endl;
// Value val(1080108009);
// vector<int> results;
// indexManager.select("TEST1", "Table", "t1.index", val, EQUAL, results);
// vector<int>::iterator i;
// for (i = results.begin(); i != results.end(); i++) {
// cout<<*i<<" ";
// }
random_shuffle(intValue.begin(), intValue.end());
vector<Value>::iterator intItor;
int i = 300;
for (intItor = intValue.begin(); intItor != intValue.end(); intItor++) {
indexManager.deleteFrom("TEST1", "Table", "t1.index", *intItor);
// indexManager.tree.printTree(++i);
cout<<"delete"<<i<<": "<<(*intItor).intValue<<endl;
}
indexManager.tree.printTree(1);
return 0;
}