-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_plcp.cpp
62 lines (48 loc) · 1.51 KB
/
build_plcp.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
#include <cstdlib>
#include <fstream>
#include <iostream>
#include "rlcsa.h"
using namespace CSA;
/*
This program writes run-length encoded PLCP of the collection into a file.
*/
int
main(int argc, char** argv)
{
std::cout << "PLCP builder" << std::endl;
if(argc < 2)
{
std::cout << "Usage: build_plcp base_name [block_size]" << std::endl;
return 1;
}
std::string base_name = argv[1];
std::string plcp_name = base_name + PLCP_EXTENSION;
std::cout << "PLCP: " << plcp_name << std::endl;
std::ofstream plcp_file(plcp_name.c_str(), std::ios_base::binary);
if(!plcp_file)
{
std::cerr << "Error creating PLCP file!" << std::endl;
return 2;
}
usint block_size = 32;
if(argc > 2) { block_size = atoi(argv[2]); }
std::cout << "Block size: " << block_size << std::endl;
std::cout << std::endl;
RLCSA rlcsa(base_name);
clock_t start = clock();
PLCPVector* plcp = rlcsa.buildPLCP(block_size);
plcp->writeTo(plcp_file);
clock_t stop = clock();
double time = ((stop - start) / (double)CLOCKS_PER_SEC);
double megabytes = rlcsa.getSize() / (double)MEGABYTE;
double size = plcp->reportSize() / (double)MEGABYTE;
PLCPVector::Iterator iter(*plcp);
usint runs = iter.countRuns();
std::cout << megabytes << " megabytes in " << time << " seconds (" << (megabytes / time) << " MB/s)" << std::endl;
std::cout << "PLCP size: " << size << " MB" << std::endl;
std::cout << "Runs: " << runs << std::endl;
std::cout << std::endl;
plcp_file.close();
delete plcp;
return 0;
}