* Samplerate defaults to TEXTCOLLECTION_DEFAULT_SAMPLERATE.
*/
TCImplementation::TCImplementation(uchar * bwt, ulong length, unsigned samplerate_,
- unsigned numberOfTexts_, ulong maxTextLength_, ulong numberOfSamples_, char tsType)
+ unsigned numberOfTexts_, ulong maxTextLength_, ulong numberOfSamples_,
+ CSA::DeltaVector & notIndexed, const string & niText, char tsType)
: n(length), samplerate(samplerate_), alphabetrank(0), sampled(0), suffixes(0),
suffixDocId(0), numberOfTexts(numberOfTexts_), maxTextLength(maxTextLength_), Doc(0)
{
bwt = 0;
// Make sampling tables
- maketables(numberOfSamples_, tsType);
+ maketables(numberOfSamples_, tsType, notIndexed, niText);
}
bool TCImplementation::EmptyText(DocId k) const
res[i-j-1] = result[j];
return res;*/
}
+
/*
- * Not supported
+ * Substring queries are supported via the pointer returned by TextStorage::GetText
uchar* TCImplementation::GetText(DocId k, TextPosition i, TextPosition j) const
{
assert(k < (DocId)numberOfTexts);
return Substring(i + start, j-i+1);
}*/
+
+
/******************************************************************
* Existential queries
*/
#endif
}
-void TCImplementation::maketables(ulong sampleLength, char tsType)
+void TCImplementation::maketables(ulong sampleLength, char tsType, CSA::DeltaVector & notIndexed, const string & niText)
{
// Calculate BWT end-marker position (of last inserted text)
{
ulongmax--;
uint alphabetrank_i_tmp =0;
- TextStorageBuilder tsbuilder(n);
- Tools::StartTimer();
+ // Text length = n + number of bytes not indexed.
+ TextStorageBuilder tsbuilder(n + niText.length());
+ ulong tsb_i = n + niText.length(); // Iterator from text length to 0.
+ string::const_reverse_iterator nit_i = niText.rbegin(); // Iterator through non-indexed texts
for (ulong i=n-1;i<ulongmax;i--) {
// i substitutes SA->GetPos(i)
x=(i==n-1)?0:i+1;
uchar c = alphabetrank->access(p, alphabetrank_i_tmp);
- tsbuilder[i] = c;
+
+ tsbuilder[--tsb_i] = c; // Build TextStorage
if ((posOfSuccEndmarker - i) % samplerate == 0 && c != '\0')
{
if (c == '\0')
{
- --textId;
+ unsigned prevTextId = textId; // Cache textId value.
+ --textId;
+ /**
+ * At first c == '\0' it holds that (prevTextId == numberOfTexts), thus,
+ * we have to search for the first text that is actually *indexed*
+ * to get correct prevTextId.
+ */
+ if (prevTextId == numberOfTexts)
+ {
+ prevTextId = 0;
+ while (notIndexed.isSet(prevTextId))
+ ++ prevTextId;
+ // Now prevTextId points to the first indexed Doc ID.
+ }
+
+ /**
+ * Insert non-indexed texts
+ */
+ while (notIndexed.isSet(textId))
+ {
+ do {
+ tsbuilder[tsb_i] = *nit_i;
+ -- tsb_i;
+ ++ nit_i;
+ } while (nit_i != niText.rend() && *nit_i != '\0');
+
+ tsbuilder[tsb_i] = '\0';
+
+ if (textId == 0)
+ break;
+ --textId;
+ }
// Record the order of end-markers in BWT:
ulong endmarkerRank = alphabetrank_i_tmp - 1;
//set_field(endmarkerDocId, logNumberOfTexts, endmarkerRank, (textId + 1) % numberOfTexts);
- (*endmarkerDocId)[endmarkerRank] = (textId + 1) % numberOfTexts;
+ (*endmarkerDocId)[endmarkerRank] = prevTextId % numberOfTexts;
// Store text length and text start position:
if (textId < (DocId)numberOfTexts - 1)
{
// (*textStartPos)[textId + 1] = x; // x-1 is text position of end-marker.
+
posOfSuccEndmarker = i;
}
- // LF-mapping from '\0' does not work with this (pseudo) BWT (see details from Wolfgang's thesis).
- p = textId; // Correct LF-mapping to the last char of the previous text.
+ // LF-mapping from '\0' does not work with this (pseudo) BWT.
+ // Correct LF-mapping to the last char of the previous text:
+ p = textId - notIndexed.rank(textId);
}
else // Now c != '\0', do LF-mapping:
p = C[c]+alphabetrank_i_tmp-1;
}
+ while (textId > 0 && notIndexed.isSet(textId-1))
+ {
+ do {
+ -- tsb_i;
+ tsbuilder[tsb_i] = *nit_i;
+ ++ nit_i;
+ } while (nit_i != niText.rend() && *nit_i != '\0');
+ --textId;
+ }
assert(textId == 0);
+ assert(tsb_i == 0);
+ assert(nit_i == niText.rend());
#ifdef DEBUG_MEMUSAGE
std::cerr << "heap usage before tsbuilder init: " << HeapProfiler::GetHeapConsumption()/(1024*1024) << " / " << HeapProfiler::GetMaxHeapConsumption()/(1024*1024) << " Mbytes, " << HeapProfiler::GetHeapConsumption() << " / " << HeapProfiler::GetMaxHeapConsumption() << std::endl;
suffixes = new BlockArray(sampleLength, Tools::CeilLog2(maxTextLength));
suffixDocId = new BlockArray(sampleLength, Tools::CeilLog2(numberOfTexts));
- x = n - 2;
- posOfSuccEndmarker = n-1;
- for(ulong i=0; i<sampleLength; i++) {
+ x = n + niText.length() - 2;
+ textId = numberOfTexts - 1;
+ posOfSuccEndmarker = x + 1;
+ for(ulong i = 0; i < sampleLength; i ++) {
// Find next sampled text position
- while ((posOfSuccEndmarker - x) % samplerate != 0)
+ while ((posOfSuccEndmarker - x) % samplerate != 0
+ || notIndexed.isSet(textId)) // Loop over non-indexed
{
--x;
assert(x != ~0lu);
if (textStorage->IsEndmarker(x))
+ {
posOfSuccEndmarker = x--;
+ -- textId;
+ }
}
assert((*positions)[i] < n);
ulong j = sampled->rank1((*positions)[i]);
assert(j != 0); // if (j==0) j=sampleLength;
TextPosition textPos = (x==n-1)?0:x+1;
- (*suffixDocId)[j-1] = textStorage->DocIdAtTextPos(textPos);
+ (*suffixDocId)[j-1] = textId; // textStorage->DocIdAtTextPos(textPos);
+ assert(textStorage->DocIdAtTextPos(textPos) == textId);
assert((*suffixDocId)[j-1] < numberOfTexts);
// calculate offset from text start:
(*suffixes)[j-1] = textPos - textStorage->TextStartPos((*suffixDocId)[j-1]);
--x;
if (x != ~0lu && textStorage->IsEndmarker(x))
+ {
posOfSuccEndmarker = x--;
+ -- textId;
+ }
}
delete positions;
HeapProfiler::ResetMaxHeapConsumption();
#endif
- /**
- * Second pass: check tables
- */
-/* p=bwtEndPos;
- textId = numberOfTexts;
- for (ulong i=n-1;i<ulongmax;i--) {
- x=(i==n-1)?0:i+1;
-
- if (sampled->access(p)) {
- ulong j = sampled->rank1(p)-1;
- assert((*suffixDocId)[j] == DocIdAtTextPos(textStartPos, x));
-
- // calculate offset from text start:
- assert((*suffixes)[j] == x - (*textStartPos)[(*suffixDocId)[j]]);
- }
-
- uchar c = alphabetrank->access(p, alphabetrank_i_tmp);
-
- if (c == '\0')
- {
- --textId;
- // LF-mapping from '\0' does not work with this (pseudo) BWT (see details from Wolfgang's thesis).
- p = textId; // Correct LF-mapping to the last char of the previous text.
- }
- else // Now c != '\0', do LF-mapping:
- p = C[c]+alphabetrank_i_tmp-1;
- }
- assert(textId == 0);
- delete textStartPos
-*/
-
#ifdef DEBUG_MEMUSAGE
std::cerr << "max heap usage before Doc: " << HeapProfiler::GetMaxHeapConsumption()/(1024*1024) << " Mbytes" << std::endl;
HeapProfiler::ResetMaxHeapConsumption();