8 #include "misc/utils.h"
14 int main(int argc, char** argv)
16 std::cout << "RLCSA locate test" << std::endl;
19 std::cout << "Usage: locate_test basename [begin end] output [direct]" << std::endl;
23 usint begin = 0, end = 0;
25 std::cout << "Base name: " << argv[1] << std::endl;
29 begin = atoi(argv[2]), end = atoi(argv[3]);
30 std::cout << "Begin: " << begin << std::endl;
31 std::cout << "End: " << end << std::endl;
34 std::cerr << "Error: Empty range!" << std::endl;
38 if(argc < output_arg + 2)
40 std::cout << "Using run-based optimizations." << std::endl;
44 std::cout << "Using direct locate." << std::endl;
46 std::cout << std::endl;
49 if(!rlcsa.supportsLocate())
51 std::cerr << "Error: Locate is not supported!" << std::endl;
57 if(end >= rlcsa.getSize())
59 std::cerr << "Error: Invalid range!" << std::endl;
65 begin = 0; end = rlcsa.getSize() - 1;
68 std::ofstream output(argv[output_arg], std::ios_base::binary);
71 std::cerr << "Error: Cannot open output file!" << std::endl;
75 usint* buffer = new usint[MILLION];
76 std::clock_t start = std::clock();
77 if(argc < output_arg + 2) // Use run-based optimizations for locate.
79 for(usint curr = begin; curr <= end; curr += MILLION)
81 pair_type range(curr, std::min(end, curr + MILLION - 1));
82 rlcsa.locate(range, buffer);
83 for(usint i = 0; i < range.second + 1 - range.first; i++)
85 output.write((char*)&(buffer[i]), sizeof(usint));
89 else // Use direct locate.
91 for(usint curr = begin; curr <= end; curr += MILLION)
93 pair_type range(curr, std::min(end, curr + MILLION - 1));
94 for(usint i = 0; i < range.second + 1 - range.first; i++)
96 buffer[i] = rlcsa.locate(curr + i);
98 for(usint i = 0; i < range.second + 1 - range.first; i++)
100 output.write((char*)&(buffer[i]), sizeof(usint));
104 std::clock_t stop = std::clock();
107 double size = (end + 1 - begin);
108 double time = (stop - start) / (double)CLOCKS_PER_SEC;
109 std::cout << size << " locates in " << time << " seconds (" << (size / time) << " locates/s)" << std::endl;