-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_fixed_len_pages.cpp
More file actions
48 lines (46 loc) · 1.68 KB
/
write_fixed_len_pages.cpp
File metadata and controls
48 lines (46 loc) · 1.68 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
#include <bitset>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "library.h"
int main(int argc, char* argv[]){
Record record;
auto startTime = system_clock::now();
std::ifstream fp(argv[1]);
std::ofstream page_file(argv[2]);
if(!fp.is_open() || !page_file.is_open()){
cout << "failure";
}
std::string line;
Page* page = new Page;
int number_of_records = 0;
int number_of_pages = 1;
while (getline(fp,line)){
// line = line.substr(0, line.size() - 2); // remove '\n'
line = line.substr(0, SLOT_SIZE + SLOT_SIZE / ATTRIBUTE_SIZE - 1);
stringstream ss(line);
string attr;
while(getline(ss, attr, ',')){
char* temp = new char[ATTRIBUTE_SIZE+1];
strcpy(temp, attr.c_str());
record.push_back(temp);
}
if(number_of_records == 0){
init_fixed_len_page(page, atoi(argv[3]), fixed_len_sizeof(&record));
}
while (add_fixed_len_page(page, &record) == -1){
page_file.write((char*)page->data, page->page_size);
init_fixed_len_page(page, atoi(argv[3]), fixed_len_sizeof(&record));
++number_of_pages;
}
record.clear();
++number_of_records;
}
page_file.write((char*)page->data, page->page_size) ;
auto endTime = system_clock::now();
cout << "NUMBER OF RECORDS: " << number_of_records << endl;
cout << "NUMBER OF PAGES: " << number_of_pages << endl;
auto duration = duration_cast<microseconds>(endTime - startTime);
std::cout << "TIME: " << double(duration.count()) * microseconds::period::num / microseconds::period::den << "s" << endl;
}