1 #include "incbwt/rlcsa_builder.h"
2 #include "TextCollectionBuilder.h"
4 // Un-comment next line to run a comparison of resulting BWT
11 #include "TCImplementation.h"
19 CSA::RLCSABuilder * sa;
22 // Total number of texts in the collection
23 unsigned numberOfTexts;
24 // Length of the longest text
26 ulong numberOfSamples;
34 * Init text collection
36 * See CSA.h for more details.
38 TextCollectionBuilder::TextCollectionBuilder(unsigned samplerate)
39 : p_(new struct TCBuilderRep())
42 p_->samplerate = samplerate;
43 p_->numberOfTexts = 0;
44 p_->numberOfSamples = 0;
46 // Current params: 8 bytes, 15 MB, no samples
47 p_->sa = new CSA::RLCSABuilder(8, 0, 15 * 1024 * 1024);
48 assert(p_->sa->isOk());
52 for (unsigned i = 0; i < 255; ++i)
55 p_->dynFMI = new DynFMI(temp, 1, 255, false);
59 TextCollectionBuilder::~TextCollectionBuilder()
69 void TextCollectionBuilder::InsertText(uchar const * text)
71 TextCollection::TextPosition m = std::strlen((char *)text) + 1;
72 if (m > p_->maxTextLength)
73 p_->maxTextLength = m; // Store length of the longest text seen so far.
79 p_->numberOfSamples += (m-1)/p_->samplerate;
82 p_->dynFMI->addText(text, m);
84 p_->sa->insertSequence((char*)text, m-1, 0);
85 assert(p_->sa->isOk());
89 // FIXME indexing empty texts
90 std::cerr << "TextCollectionBuilder::InsertText() error: can not index empty texts!" << std::endl;
96 TextCollection * TextCollectionBuilder::InitTextCollection()
99 CSA::usint length = 0;
100 if (p_->numberOfTexts == 0)
102 p_->numberOfTexts ++; // Add one empty text
107 p_->maxTextLength = 1;
111 bwt = (uchar *)p_->sa->getBWT(length);
115 assert(length == p_->n);
119 uchar *bwtTest = p_->dynFMI->getBWT();
120 printf("123456789012345678901234567890123456789\n");
121 for (ulong i = 0; i < p_->n && i < 100; i ++)
123 printf("%d", (int)bwt[i]);
125 printf("%c", bwt[i]);
127 for (ulong i = 0; i < p_->n && i < 100; i ++)
129 printf("%d", (int)bwtTest[i]);
131 printf("%c", bwtTest[i]);
135 assert(p_->numberOfTexts == p_->dynFMI->getCollectionSize());
139 for (ulong i = 0; i < p_->n; ++i)
140 if (bwt[i] != bwtTest[i])
142 std::cout << "i = " << i << ", bwt = " << (unsigned)bwt[i] << ", "
143 << (unsigned)bwtTest[i] << std::endl;
148 #endif // TCB_TEST_BWT
151 TextCollection *result = new TCImplementation(bwt, (ulong)length,
152 p_->samplerate, p_->numberOfTexts, p_->maxTextLength, p_->numberOfSamples);