-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.cpp
More file actions
42 lines (35 loc) · 1.21 KB
/
select.cpp
File metadata and controls
42 lines (35 loc) · 1.21 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
//
// Created by Yuchen Zhang on 2/22/23.
//
#include "library.h"
//<heapfile> <attribute_id> <start> <end> <page_size>
int main(int argc, char* argv[]){
auto startTime = system_clock::now();
FILE* heapFile = fopen(argv[1], "r+");
int attribute_id = atoi(argv[2]);
string start = argv[3];
string end = argv[4];
int page_size = atoi(argv[5]);
// Initialize heapfile
auto* heapfile = new Heapfile;
init_heapfile(heapfile, page_size, heapFile);
RecordIterator recordIterator(heapfile);
Record record;
vector<string> ans;
int numOfRecord = 0;
while(recordIterator.hasNext()){
record = recordIterator.next();
if(record[attribute_id] >= start && record[attribute_id] <= end){
string temp = record[attribute_id];
ans.push_back(temp.substr(0,5));
numOfRecord+=1;
}
}
for(auto i : ans){
cout << i << endl;
}
cout << "NUMBER OF RECORDS: " << numOfRecord << endl;
auto endTime = system_clock::now();
auto duration = duration_cast<microseconds>(endTime - startTime);
std::cout << "TIME: " << double(duration.count()) * microseconds::period::num / microseconds::period::den << "s" << endl;
}