Debug swcsa
[SXSI/TextCollection.git] / incbwt / build_plcp.cpp
1 #include <cstdlib>
2 #include <fstream>
3 #include <iostream>
4
5 #include "rlcsa.h"
6
7
8 using namespace CSA;
9
10
11 /*
12   This program writes run-length encoded PLCP of the collection into a file.
13 */
14
15
16 int
17 main(int argc, char** argv)
18 {
19   std::cout << "PLCP builder" << std::endl;
20   if(argc < 2)
21   {
22     std::cout << "Usage: build_plcp base_name [block_size]" << std::endl;
23     return 1;
24   }
25
26   std::string base_name = argv[1];
27   std::string plcp_name = base_name + PLCP_EXTENSION;
28   std::cout << "PLCP: " << plcp_name << std::endl;
29   std::ofstream plcp_file(plcp_name.c_str(), std::ios_base::binary);
30   if(!plcp_file)
31   {
32     std::cerr << "Error creating PLCP file!" << std::endl;
33     return 2;
34   }
35
36   usint block_size = 32;
37   if(argc > 2) { block_size = atoi(argv[2]); }
38   std::cout << "Block size: " << block_size << std::endl;
39   std::cout << std::endl;
40   RLCSA rlcsa(base_name);
41
42   clock_t start = clock();
43   RLEVector* plcp = rlcsa.buildPLCP(block_size);
44   plcp->writeTo(plcp_file);
45   clock_t stop = clock();
46
47   double time = ((stop - start) / (double)CLOCKS_PER_SEC);
48   double megabytes = rlcsa.getSize() / (double)MEGABYTE;
49   double size = plcp->reportSize() / (double)MEGABYTE;
50   RLEVector::Iterator iter(*plcp);
51   usint runs = iter.countRuns();
52
53   std::cout << megabytes << " megabytes in " << time << " seconds (" << (megabytes / time) << " MB/s)" << std::endl;
54   std::cout << "PLCP size: " << size << " MB" << std::endl;
55   std::cout << "Runs: " << runs << std::endl;
56   std::cout << std::endl;
57
58   plcp_file.close();
59   delete plcp;
60
61   return 0;
62 }