-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_sa.cpp
46 lines (37 loc) · 1.09 KB
/
build_sa.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
#include <iostream>
#include "suffixarray.h"
#include "misc/utils.h"
using namespace CSA;
int
main(int argc, char** argv)
{
std::cout << "Suffix array builder" << std::endl;
if(argc < 2)
{
std::cout << "Usage: build_sa base_name" << std::endl;
return 1;
}
std::string base_name = argv[1];
std::cout << "Input: " << base_name << std::endl;
std::cout << std::endl;
std::ifstream input(base_name.c_str(), std::ios_base::binary);
if(!input)
{
std::cerr << "Error: Cannot open input file!" << std::endl;
return 2;
}
usint bytes = fileSize(input);
uchar* data = new uchar[bytes];
input.read((char*)data, bytes);
input.close();
double start = readTimer();
SuffixArray sa(data, bytes);
if(!sa.isOk()) { return 3; }
double time = readTimer() - start;
double megabytes = bytes / (double)MEGABYTE;
std::cout << "Indexed " << megabytes << " megabytes in " << time << " seconds (" << (megabytes / time) << " MB/s)." << std::endl;
std::cout << "Memory: " << memoryUsage() << " kB" << std::endl;
std::cout << std::endl;
sa.writeTo(base_name);
return 0;
}