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
33 * Init text collection
35 * See CSA.h for more details.
37 TextCollectionBuilder::TextCollectionBuilder(unsigned samplerate)
38 : p_(new struct TCBuilderRep())
41 p_->samplerate = samplerate;
42 p_->numberOfTexts = 0;
44 // Current params: 8 bytes, 15 MB, no samples
45 p_->sa = new CSA::RLCSABuilder(8, 0, 15 * 1024 * 1024);
46 assert(p_->sa->isOk());
50 for (unsigned i = 0; i < 255; ++i)
53 p_->dynFMI = new DynFMI(temp, 1, 255, false);
57 TextCollectionBuilder::~TextCollectionBuilder()
67 void TextCollectionBuilder::InsertText(uchar const * text)
69 TextCollection::TextPosition m = std::strlen((char *)text) + 1;
70 if (m > p_->maxTextLength)
71 p_->maxTextLength = m; // Store length of the longest text seen so far.
79 p_->dynFMI->addText(text, m);
82 p_->sa->insertSequence((char*)text, m-1, 0);
83 assert(p_->sa->isOk());
87 // FIXME indexing empty texts
88 std::cerr << "TextCollectionBuilder::InsertText() error: can not index empty texts!" << std::endl;
94 TextCollection * TextCollectionBuilder::InitTextCollection()
97 CSA::usint length = 0;
98 if (p_->numberOfTexts == 0)
100 p_->numberOfTexts ++; // Add one empty text
105 p_->maxTextLength = 1;
109 bwt = (uchar *)p_->sa->getBWT(length);
113 assert(length == p_->n);
117 uchar *bwtTest = p_->dynFMI->getBWT();
118 printf("123456789012345678901234567890123456789\n");
119 for (ulong i = 0; i < p_->n && i < 100; i ++)
121 printf("%d", (int)bwt[i]);
123 printf("%c", bwt[i]);
125 for (ulong i = 0; i < p_->n && i < 100; i ++)
127 printf("%d", (int)bwtTest[i]);
129 printf("%c", bwtTest[i]);
133 assert(p_->numberOfTexts == p_->dynFMI->getCollectionSize());
137 for (ulong i = 0; i < p_->n; ++i)
138 if (bwt[i] != bwtTest[i])
140 std::cout << "i = " << i << ", bwt = " << (unsigned)bwt[i] << ", " << (unsigned)bwtTest[i] << std::endl;
145 #endif // TCB_TEST_BWT
148 TextCollection *result = new TCImplementation(bwt, (ulong)length, p_->samplerate, p_->numberOfTexts, p_->maxTextLength);