-
Notifications
You must be signed in to change notification settings - Fork 3
/
sa-construct-space-efficient.cpp
43 lines (38 loc) · 1.4 KB
/
sa-construct-space-efficient.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
#include <iostream>
#include <fstream>
#include <sdsl/construct.hpp>
using namespace sdsl;
using namespace std;
using namespace std::chrono;
using timer = std::chrono::high_resolution_clock;
int main(int argc, char** argv)
{
// Check Parameters
if (argc!=2) {
cout << "Usage: " << argv[0] << " file" << endl;
cout << " Computes the SA from file space efficiently." << endl;
cout << " Result is stored in `sa_<file>.sdsl`." << endl;
return 1;
}
cache_config config(false, ".", util::basename(argv[1]));
int_vector<8> text;
load_vector_from_file(text, argv[1], 1);
append_zero_symbol(text);
auto n = text.size();
store_to_cache(text, conf::KEY_TEXT, config);
util::clear(text);
cout << "Calculate suffix array ... " << flush;
construct_config::byte_algo_sa = SE_SAIS; // or LIBDIVSUFSORT for less space-efficient but faster construction
memory_monitor::start();
auto start = timer::now();
construct_sa<8>(config);
auto stop = timer::now();
memory_monitor::stop();
cout << "done." << endl;
cout << "Construction needed:" << endl;
cout << duration_cast<seconds>(stop-start).count() << " seconds." << endl;
cout << memory_monitor::peak() << " bytes." << endl;
cout << (1.0*memory_monitor::peak())/n << " bytes per input byte." << endl;
sdsl::remove(cache_file_name(conf::KEY_TEXT, config));
return 0;
}