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
37 TextCollectionBuilder::TextCollectionBuilder(unsigned samplerate, ulong estimatedInputLength)
38 : p_(new struct TCBuilderRep())
41 p_->samplerate = samplerate;
42 p_->numberOfTexts = 0;
43 p_->numberOfSamples = 0;
45 // Current params: 8 bytes, no samples, buffer size n/10 bytes.
46 p_->sa = new CSA::RLCSABuilder(8, 0, estimatedInputLength/10);
47 assert(p_->sa->isOk());
51 for (unsigned i = 0; i < 255; ++i)
54 p_->dynFMI = new DynFMI(temp, 1, 255, false);
58 TextCollectionBuilder::~TextCollectionBuilder()
68 void TextCollectionBuilder::InsertText(uchar const * text)
70 TextCollection::TextPosition m = std::strlen((char *)text) + 1;
71 if (m > p_->maxTextLength)
72 p_->maxTextLength = m; // Store length of the longest text seen so far.
78 p_->numberOfSamples += (m-1)/p_->samplerate;
81 p_->dynFMI->addText(text, m);
83 p_->sa->insertSequence((char*)text, m-1, 0);
84 assert(p_->sa->isOk());
88 // FIXME indexing empty texts
89 std::cerr << "TextCollectionBuilder::InsertText() error: can not index empty texts!" << std::endl;
95 TextCollection * TextCollectionBuilder::InitTextCollection()
98 CSA::usint length = 0;
99 if (p_->numberOfTexts == 0)
101 p_->numberOfTexts ++; // Add one empty text
106 p_->maxTextLength = 1;
110 bwt = (uchar *)p_->sa->getBWT(length);
114 assert(length == p_->n);
118 uchar *bwtTest = p_->dynFMI->getBWT();
119 printf("123456789012345678901234567890123456789\n");
120 for (ulong i = 0; i < p_->n && i < 100; i ++)
122 printf("%d", (int)bwt[i]);
124 printf("%c", bwt[i]);
126 for (ulong i = 0; i < p_->n && i < 100; i ++)
128 printf("%d", (int)bwtTest[i]);
130 printf("%c", bwtTest[i]);
134 assert(p_->numberOfTexts == p_->dynFMI->getCollectionSize());
138 for (ulong i = 0; i < p_->n; ++i)
139 if (bwt[i] != bwtTest[i])
141 std::cout << "i = " << i << ", bwt = " << (unsigned)bwt[i] << ", "
142 << (unsigned)bwtTest[i] << std::endl;
147 #endif // TCB_TEST_BWT
150 TextCollection *result = new TCImplementation(bwt, (ulong)length,
151 p_->samplerate, p_->numberOfTexts, p_->maxTextLength, p_->numberOfSamples);