File: sa-construct-space-efficient.cpp

package info (click to toggle)
libsdsl 2.1.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,992 kB
  • sloc: cpp: 42,286; makefile: 1,171; ansic: 318; sh: 201; python: 27
file content (43 lines) | stat: -rw-r--r-- 1,431 bytes parent folder | download | duplicates (18)
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;
}