-
Notifications
You must be signed in to change notification settings - Fork 2
/
query_binary_vid.cpp
79 lines (65 loc) · 2 KB
/
query_binary_vid.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
#include "util/file_piece.hh"
#include "util/file.hh"
#include "util/scoped.hh"
#include "util/string_piece.hh"
#include "util/tokenize_piece.hh"
#include "util/murmur_hash.hh"
#include "util/probing_hash_table.hh"
#include "util/usage.hh"
#include "helpers/quering.hh"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/mman.h>
#include <sys/stat.h> //For finding size of file
#include <boost/functional/hash.hpp>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctime> //for timing.
#include <chrono>
int main(int argc, char* argv[]) {
if (argc != 2) {
// Tell the user how to run the program
std::cerr << "Usage: " << argv[0] << " path_to_directory" << std::endl;
return 1;
}
QueryEngine queries(argv[1]);
//Interactive search
std::cout << "Please enter a string to be searched, or exit to exit." << std::endl;
while (true){
std::string cinstr = "";
getline(std::cin, cinstr);
if (cinstr == "exit"){
break;
}else{
//Time lookup
std::clock_t c_start = std::clock();
auto t_start = std::chrono::high_resolution_clock::now();
std::pair<bool, std::vector<target_text>> query_result;
//Actual lookup
query_result = queries.query(StringPiece(cinstr));
if (query_result.first) {
queries.printTargetInfo(query_result.second);
} else {
std::cout << "Key not found!" << std::endl;
}
//End timing
std::clock_t c_end = std::clock();
auto t_end = std::chrono::high_resolution_clock::now();
//Print timing results
std::cout << "CPU time used: "<< 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC<< " ms\n";
std::cout << "Real time passed: "<< std::chrono::duration_cast<std::chrono::milliseconds>(t_end - t_start).count()<< " ms\n";
}
}
//clean up
std::cout << "FIXME: Should destructor be called or will the object be destroyed automatically?" << std::endl;
//delete queries;
util::PrintUsage(std::cout);
return 0;
}