1 #include "incbwt/rlcsa_builder.h"
2 #include "RLCSABuilder.h"
3 #include "RLCSAWrapper.h"
8 // Using pimpl idiom to hide RLCSABuilder*
12 CSA::RLCSABuilder * sa;
15 unsigned numberOfTexts;
20 * Init text collection
22 RLCSABuilder::RLCSABuilder(unsigned samplerate, ulong estimatedInputLength)
23 : p_(new struct TCBuilderRep())
26 p_->samplerate = samplerate;
28 p_->samplerate = TEXTCOLLECTION_DEFAULT_SAMPLERATE;
30 p_->numberOfTexts = 0;
31 p_->insertAllowed = true;
33 CSA::usint rlcsa_block_size = CSA::RLCSA_BLOCK_SIZE.second;
34 CSA::usint rlcsa_sample_rate = p_->samplerate;
36 // Parameters for RLCSA: 32 bytes, samples, buffer size n/10 bytes.
37 // Buffer size is always at least 15MB:
38 if (estimatedInputLength < TEXTCOLLECTION_DEFAULT_INPUT_LENGTH)
39 estimatedInputLength = TEXTCOLLECTION_DEFAULT_INPUT_LENGTH;
40 p_->sa = new CSA::RLCSABuilder(rlcsa_block_size, rlcsa_sample_rate, estimatedInputLength/10);
41 assert(p_->sa->isOk());
44 RLCSABuilder::~RLCSABuilder()
50 void RLCSABuilder::InsertText(uchar const * text, bool index)
55 std::cerr << "SWCSABuilder::InsertText(): The implementation of SWCSA does not support non-indexed texts"
56 << std::endl << "Use the default (FMIndex) text collection instead." << std::endl;
60 if (!p_->insertAllowed)
62 std::cerr << "RLCSABuilder::InsertText() error: new text can not be inserted after InitTextCollection() call!" << std::endl;
66 TextCollection::TextPosition m = std::strlen((char *)text) + 1;
72 p_->sa->insertSequence((char*)text, m-1, 0);
73 assert(p_->sa->isOk());
77 // FIXME indexing empty texts
78 std::cerr << "RLCSABuilder::InsertText() error: can not index empty texts!" << std::endl;
83 TextCollection * RLCSABuilder::InitTextCollection(char type)
85 p_->insertAllowed = false; // Disable future insertions
86 assert(type == TextStorage::TYPE_PLAIN_TEXT);
87 if (type != TextStorage::TYPE_PLAIN_TEXT)
89 std::cerr << "RLCSABuilder::InitTextCollection(): The implementation of RLCSA supports only TextStorage::TYPE_PLAIN_TEXT"
90 << std::endl << "Use the default (FMIndex) text collection instead." << std::endl;
94 TextCollection *result = new RLCSAWrapper(p_->sa->getRLCSA());