-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_index.cpp
executable file
·74 lines (60 loc) · 1.68 KB
/
main_index.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
#include <iostream>
#include <time.h>
#include <vector>
#include <windows.h>
#include <filesystem>
#include "Indexer/Indexer.hpp"
using namespace std;
unsigned countFiles{0};
unsigned total_files{0};
bool completed{false};
// thread which prints the indexing results on screen
DWORD WINAPI printCount(LPVOID lpParam)
{
while (completed == false)
{
printf("reading... %.1f percent\r", (100.0 * countFiles) / total_files);
Sleep(1000);
}
ExitThread(0);
}
int main()
{
const char *datasetDir = "./dataset/";
const char *resultFile = "./index.txt";
// start timer:
time_t begin, end;
time(&begin);
// read metadeta about dataset:
vector<pair<string, int>> files(10); // (filename, file_id)
files.clear();
// files should have no extension
for (const auto &entry : filesystem::directory_iterator(datasetDir))
files.push_back(
pair<string, int> (
entry.path().string(), // full path to file
stoi(entry.path().filename().stem().string()) // file id
)
);
files.shrink_to_fit(); // remove empty indexes
total_files = files.size();
// start printing thread:
HANDLE hThread = CreateThread(0, 0, printCount, 0, 0, 0);
// index all files:
Indexer indexer(total_files);
for (const auto& file : files)
{
indexer.index(file.first.c_str(), file.second);
countFiles++;
}
// stop timer:
time(&end);
printf("\nTime measured: %d seconds.\n", end - begin);
completed = true;
// write the inverted index on given file
indexer.write_on(resultFile);
// exit:
CloseHandle(hThread);
fflush(stdin);
return 0;
}