Small fixes
authornvalimak <nvalimak@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Fri, 27 Mar 2009 15:36:47 +0000 (15:36 +0000)
committernvalimak <nvalimak@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Fri, 27 Mar 2009 15:36:47 +0000 (15:36 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/TextCollection@297 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

TCImplementation.cpp
TCImplementation.h
TextCollection.h

index 290ca9c..723a2b9 100644 (file)
@@ -38,7 +38,7 @@ namespace SXSI
 {
 
 // Save file version info
-const uchar TCImplementation::versionFlag = 3;
+const uchar TCImplementation::versionFlag = 4;
 
 /**
  * Constructor inits an empty dynamic FM-index.
@@ -46,20 +46,8 @@ const uchar TCImplementation::versionFlag = 3;
  */
 TCImplementation::TCImplementation(uchar * bwt, ulong length, unsigned samplerate_, unsigned numberOfTexts_, ulong maxTextLength_)
     : n(length), samplerate(samplerate_), alphabetrank(0), sampled(0), suffixes(0), 
-      suffixDocId(0), numberOfTexts(numberOfTexts_), numberOfAllTexts(numberOfTexts_), maxTextLength(maxTextLength_), endmarkerDocId(0),
-      emptyTextRank(0)
+      suffixDocId(0), numberOfTexts(numberOfTexts_), maxTextLength(maxTextLength_), Doc(0)
 {
-    
-    // Bitvector of empty texts, FIXME Remove?
-    {
-        //std::cout << std::endl << "texts: " << numberOfTexts << ", all texts " << numberOfAllTexts << ", size : " << emptyTextId.size() <<std::endl;
-        ulong *tempB = new ulong[numberOfTexts/W + 1];
-        for (ulong i = 0; i < numberOfTexts/W + 1; ++i)
-            tempB[i] = 0;
-//        for (std::set<unsigned>::const_iterator it = emptyTextId.begin(); it != emptyTextId.end(); ++it)
-//            Tools::SetField(tempB, 1, (*it), 1);
-        emptyTextRank = new BSGAP(tempB, numberOfTexts, true);
-   }
     makewavelet(bwt); // Deletes bwt!
     bwt = 0;
   
@@ -70,25 +58,12 @@ TCImplementation::TCImplementation(uchar * bwt, ulong length, unsigned samplerat
 bool TCImplementation::EmptyText(DocId k) const
 {
     assert(k < (DocId)numberOfTexts); 
-    if (emptyTextRank->IsBitSet(k))
-        return true;
-    return false;
+    return false; // Empty texts are not indexed
 }
 
 uchar* TCImplementation::GetText(DocId k) const
 {
     assert(k < (DocId)numberOfTexts);
-
-    ulong textRank = 0;
-    if (emptyTextRank->IsBitSet(k, &textRank))
-    {
-        uchar* result = new uchar[1];
-        result[0] = 0;
-        return result;
-    }
-    // Map to non-empty text
-    k -= textRank; //emptyTextRank->rank(k);
-    
     TextPosition i = k;
 
     string result;
@@ -121,15 +96,6 @@ uchar* TCImplementation::GetText(DocId k, TextPosition i, TextPosition j) const
     assert(i <= j);
 
     ulong textRank = 0;
-    if (emptyTextRank->IsBitSet(k, &textRank))
-    {
-        uchar* result = new uchar[1];
-        result[0] = 0;
-        return result;
-    }
-    
-    // Map to non-empty text
-    k -= textRank; // emptyTextRank->rank(k);
 
     // Start position of k'th text
     ulong start = (*textStartPos)[k];
@@ -191,11 +157,7 @@ bool TCImplementation::IsEqual(uchar const *pattern) const
 {
     TextPosition m = std::strlen((char *)pattern);
     if (m == 0)
-    {
-        if (numberOfAllTexts - numberOfTexts > 0u)
-            return true; // Empty texts exists
         return false; // No empty texts exists
-    }
 
     TextPosition sp = 0, ep = 0;
     // Match including end-marker
@@ -211,11 +173,7 @@ bool TCImplementation::IsEqual(uchar const *pattern, DocId begin, DocId end) con
 {
     TextPosition m = std::strlen((char *)pattern);
     if (m == 0)
-    {
-        if (numberOfAllTexts - numberOfTexts > 0u)
-            return true; // Empty texts exists
         return false; // No empty texts exists
-    }
 
     TextPosition sp = 0, ep = 0;
     // Match including end-marker
@@ -282,7 +240,7 @@ unsigned TCImplementation::CountPrefix(uchar const * pattern) const
 {
     TextPosition m = strlen((char *)pattern);
     if (m == 0)
-        return numberOfAllTexts;
+        return numberOfTexts;
 
     TextPosition sp = 0, ep = 0;
     Search(pattern, m, &sp, &ep);
@@ -295,7 +253,7 @@ unsigned TCImplementation::CountPrefix(uchar const * pattern, DocId begin, DocId
 {
     TextPosition m = strlen((char *)pattern);
     if (m == 0)
-        return numberOfAllTexts;
+        return numberOfTexts;
 
     TextPosition sp = 0, ep = 0;
     Search(pattern, m, &sp, &ep);
@@ -308,7 +266,7 @@ unsigned TCImplementation::CountSuffix(uchar const * pattern) const
 {
     TextPosition m = strlen((char *)pattern);
     if (m == 0)
-        return numberOfAllTexts;
+        return numberOfTexts;
 
     TextPosition sp = 0, ep = 0;
     // Search with end-marker
@@ -321,7 +279,7 @@ unsigned TCImplementation::CountSuffix(uchar const * pattern, DocId begin, DocId
 {
     TextPosition m = strlen((char *)pattern);
     if (m == 0)
-        return numberOfAllTexts;
+        return numberOfTexts;
 
     TextPosition sp = 0, ep = 0;
     // Search with end-marker
@@ -334,7 +292,7 @@ unsigned TCImplementation::CountEqual(uchar const *pattern) const
 {
     TextPosition m = strlen((char const *)pattern);
     if (m == 0)
-        return numberOfAllTexts - numberOfTexts; // Empty texts. 
+        return 0; // No empty texts. 
 
     TextPosition sp = 0, ep = 0;
     // Match including end-marker
@@ -348,7 +306,7 @@ unsigned TCImplementation::CountEqual(uchar const *pattern, DocId begin, DocId e
 {
     TextPosition m = strlen((char const *)pattern);
     if (m == 0)
-        return numberOfAllTexts - numberOfTexts; // Empty texts. 
+        return 0; // No empty texts. 
 
     TextPosition sp = 0, ep = 0;
     // Match including end-marker
@@ -362,7 +320,7 @@ unsigned TCImplementation::CountContains(uchar const * pattern) const
 {
     TextPosition m = strlen((char const *)pattern);
     if (m == 0)
-        return numberOfAllTexts; // Total number of texts. 
+        return numberOfTexts; // Total number of texts. 
 
     // Here counting is as slow as fetching the result set
     // because we have to filter out occ's that fall within same document.
@@ -374,7 +332,7 @@ unsigned TCImplementation::CountContains(uchar const * pattern, DocId begin, Doc
 {
     TextPosition m = strlen((char const *)pattern);
     if (m == 0)
-        return numberOfAllTexts; // Total number of texts. 
+        return numberOfTexts; // Total number of texts. 
 
     // Here counting is as slow as fetching the result set
     // because we have to filter out occ's that fall within same document.
@@ -387,7 +345,7 @@ unsigned TCImplementation::CountLessThan(uchar const * pattern) const
 {
     TextPosition m = strlen((char const *)pattern);
     if (m == 0)
-        return numberOfAllTexts - numberOfTexts; // Empty texts. 
+        return 0; // No empty texts. 
 
     TextPosition sp = 0, ep = 0;
     SearchLessThan(pattern, m, &sp, &ep);
@@ -400,7 +358,7 @@ unsigned TCImplementation::CountLessThan(uchar const * pattern, DocId begin, Doc
 {
     TextPosition m = strlen((char const *)pattern);
     if (m == 0)
-        return numberOfAllTexts - numberOfTexts; // Empty texts. 
+        return 0; // No empty texts. 
 
     TextPosition sp = 0, ep = 0;
     SearchLessThan(pattern, m, &sp, &ep);
@@ -431,22 +389,7 @@ TextCollection::document_result TCImplementation::Prefix(uchar const * pattern)
     result.reserve(resultSize); // Try to avoid reallocation.
 
     // Iterate through end-markers in [sp,ep]:
-    unsigned i = 0;
-    if (sp > 0)
-        i = alphabetrank->rank(0, sp - 1);
-    while (resultSize)
-    {
-        // End-marker we found belongs to the "preceeding" doc in the collection
-        DocId docId = ((*endmarkerDocId)[i] + 1) % numberOfTexts;
-        // Map to doc ID:
-        docId = emptyTextRank->select0(docId+1);
-        result.push_back(docId);
-
-        -- resultSize;
-        ++ i;
-    }
-    
-    return result;
+    return EnumerateEndmarkers(sp, ep);
 }
 
 TextCollection::document_result TCImplementation::Prefix(uchar const * pattern, DocId begin, DocId end) const
@@ -467,24 +410,8 @@ TextCollection::document_result TCImplementation::Prefix(uchar const * pattern,
 
     result.reserve(resultSize); // Try to avoid reallocation.
 
-    // Iterate through end-markers in [sp,ep] and [begin, end]:
-    unsigned i = 0;
-    if (sp > 0)
-        i = alphabetrank->rank(0, sp - 1);
-    while (resultSize)
-    {
-        // End-marker we found belongs to the "preceeding" doc in the collection
-        DocId docId = ((*endmarkerDocId)[i] + 1) % numberOfTexts;
-        // Map to doc ID:
-        docId = emptyTextRank->select0(docId+1);
-        if (docId >= begin && docId <= end)
-            result.push_back(docId);
-
-        -- resultSize;
-        ++ i;
-    }
-    
-    return result;
+    // Return end-markers in [sp,ep] and [begin, end]:
+    return EnumerateEndmarkers(sp, ep, begin, end);
 }
 
 TextCollection::document_result TCImplementation::Suffix(uchar const * pattern) const
@@ -518,18 +445,11 @@ TextCollection::document_result TCImplementation::Suffix(uchar const * pattern)
         {
             // Rank among the end-markers in BWT
             unsigned endmarkerRank = alphabetrank->rank(0, i) - 1;
-
-            // End-marker that we found belongs to the "preceeding" doc in collection:
-            DocId docId = ((*endmarkerDocId)[endmarkerRank] + 1) % numberOfTexts;        
-            // Map to doc ID:
-            docId = emptyTextRank->select0(docId+1);
-            result.push_back(docId);
+            result.push_back(Doc->access(endmarkerRank));
         }
         else // Sampled position
         {
             DocId docId = (*suffixDocId)[sampled_rank_i-1]; //sampled->rank(i)-1];
-            // Map to doc ID:
-            docId = emptyTextRank->select0(docId+1);
             result.push_back(docId);
         }
     }
@@ -568,18 +488,11 @@ TextCollection::document_result TCImplementation::Suffix(uchar const * pattern,
         {
             // Rank among the end-markers in BWT
             unsigned endmarkerRank = alphabetrank->rank(0, i) - 1;
-
-            // End-marker that we found belongs to the "preceeding" doc in collection:
-            DocId docId = ((*endmarkerDocId)[endmarkerRank] + 1) % numberOfTexts;        
-            // Map to doc ID:
-            docId = emptyTextRank->select0(docId+1);
-            result.push_back(docId);
+            result.push_back(Doc->access(endmarkerRank));
         }
         else // Sampled position
         {
             DocId docId = (*suffixDocId)[sampled_rank_i-1]; //sampled->rank(i)-1];
-            // Map to doc ID:
-            docId = emptyTextRank->select0(docId+1);
             result.push_back(docId);
         }
     }
@@ -601,28 +514,7 @@ TextCollection::document_result TCImplementation::Equal(uchar const *pattern) co
     TextCollection::document_result result;
 
     // Report end-markers in result interval
-    unsigned resultSize = CountEndmarkers(sp, ep);
-    if (resultSize == 0)
-        return result;
-
-    result.reserve(resultSize); // Try to avoid reallocation.
-
-    unsigned i = 0;
-    if (sp > 0)
-        i = alphabetrank->rank(0, sp - 1);
-    while (resultSize)
-    {
-        // End-marker we found belongs to the "previous" doc in the collection
-        DocId docId = ((*endmarkerDocId)[i] + 1) % numberOfTexts;
-        // Map to doc ID:
-        docId = emptyTextRank->select0(docId+1);
-        result.push_back(docId);
-
-        -- resultSize;
-        ++ i;
-    }
-    
-    return result;
+    return EnumerateEndmarkers(sp, ep);
 }
 
 TextCollection::document_result TCImplementation::Equal(uchar const *pattern, DocId begin, DocId end) const
@@ -638,28 +530,7 @@ TextCollection::document_result TCImplementation::Equal(uchar const *pattern, Do
     TextCollection::document_result result;
 
     // Report end-markers in result interval
-    unsigned resultSize = CountEndmarkers(sp, ep);
-    if (resultSize == 0)
-        return result;
-
-    result.reserve(resultSize); // Try to avoid reallocation.
-
-    unsigned i = 0;
-    if (sp > 0)
-        i = alphabetrank->rank(0, sp - 1);
-    while (resultSize)
-    {
-        // End-marker we found belongs to the "previous" doc in the collection
-        DocId docId = ((*endmarkerDocId)[i] + 1) % numberOfTexts;
-        // Map to doc ID:
-        docId = emptyTextRank->select0(docId+1);
-        result.push_back(docId); // already within [begin, end]
-
-        -- resultSize;
-        ++ i;
-    }
-    
-    return result;
+    return EnumerateEndmarkers(sp, ep, begin, end);
 }
 
 
@@ -691,10 +562,7 @@ TextCollection::document_result TCImplementation::Contains(uchar const * pattern
         {
             // Rank among the end-markers in BWT
             unsigned endmarkerRank = alphabetrank->rank(0, i) - 1;
-            
-            // End-marker that we found belongs to the "preceeding" doc in collection:
-            DocId docId = ((*endmarkerDocId)[endmarkerRank] + 1) % numberOfTexts;
-            resultSet.insert(docId);
+            resultSet.insert(Doc->access(endmarkerRank));
         }
         else
         {
@@ -706,9 +574,6 @@ TextCollection::document_result TCImplementation::Contains(uchar const * pattern
     
     // Convert std::set to std::vector
     TextCollection::document_result result(resultSet.begin(), resultSet.end());
-    // Map to doc ID's
-    for (document_result::iterator it = result.begin(); it != result.end(); ++it)
-        *it = emptyTextRank->select0(*it+1);
     return result;
 }
 
@@ -740,9 +605,7 @@ TextCollection::document_result TCImplementation::Contains(uchar const * pattern
         {
             // Rank among the end-markers in BWT
             unsigned endmarkerRank = alphabetrank->rank(0, i) - 1;
-            
-            // End-marker that we found belongs to the "preceeding" doc in collection:
-            DocId docId = ((*endmarkerDocId)[endmarkerRank] + 1) % numberOfTexts;
+            DocId docId = Doc->access(endmarkerRank);
             if (docId >= begin && docId <= end)
                 resultSet.insert(docId);
         }
@@ -757,9 +620,6 @@ TextCollection::document_result TCImplementation::Contains(uchar const * pattern
     
     // Convert std::set to std::vector
     TextCollection::document_result result(resultSet.begin(), resultSet.end());
-    // Map to doc ID's
-    for (document_result::iterator it = result.begin(); it != result.end(); ++it)
-        *it = emptyTextRank->select0(*it+1);
     return result;
 }
 
@@ -775,29 +635,7 @@ TextCollection::document_result TCImplementation::LessThan(uchar const * pattern
     TextCollection::document_result result;
     
     // Report end-markers in result interval
-    unsigned resultSize = CountEndmarkers(sp, ep);
-    if (resultSize == 0)
-        return result;
-
-    result.reserve(resultSize); // Try to avoid reallocation.
-
-    // Iterate through end-markers in [sp,ep]:
-    unsigned i = 0;
-    if (sp > 0)
-        i = alphabetrank->rank(0, sp - 1);
-    while (resultSize)
-    {
-        // End-marker we found belongs to the "preceeding" doc in the collection
-        DocId docId = ((*endmarkerDocId)[i] + 1) % numberOfTexts;
-        // Map to doc ID:
-        docId = emptyTextRank->select0(docId+1);
-        result.push_back(docId);
-
-        -- resultSize;
-        ++ i;
-    }
-    
-    return result;
+    return EnumerateEndmarkers(sp, ep);
 }
 
 TextCollection::document_result TCImplementation::LessThan(uchar const * pattern, DocId begin, DocId end) const
@@ -819,23 +657,7 @@ TextCollection::document_result TCImplementation::LessThan(uchar const * pattern
     result.reserve(resultSize); // Try to avoid reallocation.
 
     // Iterate through end-markers in [sp,ep] and [begin, end]:
-    unsigned i = 0;
-    if (sp > 0)
-        i = alphabetrank->rank(0, sp - 1);
-    while (resultSize)
-    {
-        // End-marker we found belongs to the "preceeding" doc in the collection
-        DocId docId = ((*endmarkerDocId)[i] + 1) % numberOfTexts;
-        // Map to doc ID:
-        docId = emptyTextRank->select0(docId+1);
-        if (docId >= begin && docId <= end)
-            result.push_back(docId);
-
-        -- resultSize;
-        ++ i;
-    }
-    
-    return result;
+    return EnumerateEndmarkers(sp, ep, begin, end);
 }
 
 /**
@@ -871,11 +693,7 @@ TextCollection::full_result TCImplementation::FullContains(uchar const * pattern
         {
             // Rank among the end-markers in BWT
             unsigned endmarkerRank = alphabetrank->rank(0, i) - 1;
-            
-            // End-marker that we found belongs to the "preceeding" doc in collection:
-            DocId docId = ((*endmarkerDocId)[endmarkerRank] + 1) % numberOfTexts;
-            // Map to doc ID:
-            docId = emptyTextRank->select0(docId+1);
+            DocId docId = Doc->access(endmarkerRank);
             result.push_back(make_pair(docId, dist)); 
         }
         else
@@ -884,8 +702,6 @@ TextCollection::full_result TCImplementation::FullContains(uchar const * pattern
             DocId docId = (*suffixDocId)[sampled_rank_i-1]; //sampled->rank(i)-1];
 //            textPos = textPos - (*textStartPos)[docId]; // Offset inside the text
 
-            // Map to doc ID:
-            docId = emptyTextRank->select0(docId+1);
             result.push_back(make_pair(docId, textPos));
         }
     }
@@ -925,9 +741,7 @@ TextCollection::full_result TCImplementation::FullContains(uchar const * pattern
             unsigned endmarkerRank = alphabetrank->rank(0, i) - 1;
             
             // End-marker that we found belongs to the "preceeding" doc in collection:
-            DocId docId = ((*endmarkerDocId)[endmarkerRank] + 1) % numberOfTexts;
-            // Map to doc ID:
-            docId = emptyTextRank->select0(docId+1);
+            DocId docId = Doc->access(endmarkerRank);
             if (docId >= begin && docId <= end)
                 result.push_back(make_pair(docId, dist)); 
         }
@@ -937,8 +751,6 @@ TextCollection::full_result TCImplementation::FullContains(uchar const * pattern
             DocId docId = (*suffixDocId)[sampled_rank_i-1]; //sampled->rank(i)-1];
 //            textPos = textPos - (*textStartPos)[docId]; // Offset inside the text
 
-            // Map to doc ID:
-            docId = emptyTextRank->select0(docId+1);
             if (docId >= begin && docId <= end)
                 result.push_back(make_pair(docId, textPos));
         }
@@ -964,10 +776,8 @@ TextCollection::full_result TCImplementation::FullContains(uchar const * pattern
     BlockArray *suffixes;
     BlockArray *suffixDocId;
     unsigned numberOfTexts;
-    unsigned numberOfAllTexts;
     ulong maxTextLength;
-    BlockArray *endmarkerDocId;
-    BSGAP *emptyTextRank;
+    static_sequence *docId;
  */
 void TCImplementation::Save(FILE *file) const
 {
@@ -994,13 +804,10 @@ void TCImplementation::Save(FILE *file) const
     
     if (std::fwrite(&(this->numberOfTexts), sizeof(unsigned), 1, file) != 1)
         throw std::runtime_error("TCImplementation::Save(): file write error (numberOfTexts).");
-    if (std::fwrite(&(this->numberOfAllTexts), sizeof(unsigned), 1, file) != 1)
-        throw std::runtime_error("TCImplementation::Save(): file write error (numberOfAllTexts).");
     if (std::fwrite(&(this->maxTextLength), sizeof(ulong), 1, file) != 1)
         throw std::runtime_error("TCImplementation::Save(): file write error (maxTextLength).");
 
-    endmarkerDocId->Save(file);
-    emptyTextRank->Save(file);
+    Doc->save(file);
     fflush(file);
 }
 
@@ -1013,8 +820,7 @@ void TCImplementation::Save(FILE *file) const
  */
 TCImplementation::TCImplementation(FILE *file, unsigned samplerate_)
     : n(0), samplerate(samplerate_), alphabetrank(0), sampled(0), suffixes(0), 
-      suffixDocId(0), numberOfTexts(0), numberOfAllTexts(0), maxTextLength(0), endmarkerDocId(0),
-      emptyTextRank(0)
+      suffixDocId(0), numberOfTexts(0), maxTextLength(0), Doc(0)
 {
     uchar verFlag = 0;
     if (std::fread(&verFlag, 1, 1, file) != 1)
@@ -1044,13 +850,10 @@ TCImplementation::TCImplementation(FILE *file, unsigned samplerate_)
 
     if (std::fread(&(this->numberOfTexts), sizeof(unsigned), 1, file) != 1)
         throw std::runtime_error("TCImplementation::Load(): file read error (numberOfTexts).");
-    if (std::fread(&(this->numberOfAllTexts), sizeof(unsigned), 1, file) != 1)
-        throw std::runtime_error("TCImplementation::Load(): file read error (numberOfAllTexts).");
     if (std::fread(&(this->maxTextLength), sizeof(ulong), 1, file) != 1)
         throw std::runtime_error("TCImplementation::Load(): file read error (maxTextLength).");
 
-    endmarkerDocId = new BlockArray(file);
-    emptyTextRank = new BSGAP(file);
+    Doc = static_sequence::load(file);
 
     // FIXME Construct data structures with new samplerate
     //maketables(); 
@@ -1063,38 +866,7 @@ TCImplementation::TCImplementation(FILE *file, unsigned samplerate_)
  */
 
 
-// FIXME Use 2D-search structure
-unsigned TCImplementation::CountEndmarkers(TextPosition sp, TextPosition ep, DocId begin, DocId end) const
-{
-    if (sp > ep)
-        return 0;
-    
-    ulong ranksp = 0;
-    if (sp != 0)
-        ranksp = alphabetrank->rank(0, sp - 1);
-    
-    unsigned resultSize = alphabetrank->rank(0, ep) - ranksp;
-    if (resultSize == 0)
-        return 0;
 
-    // Count end-markers in result interval and within [begin, end]
-    unsigned count = 0;
-    unsigned i = ranksp;
-    while (resultSize)
-    {
-        // End-marker we found belongs to the "previous" doc in the collection
-        DocId docId = ((*endmarkerDocId)[i] + 1) % numberOfTexts;
-        // Map to doc ID:
-        docId = emptyTextRank->select0(docId+1);
-        if (docId >= begin && docId <= end)
-            ++ count;
-
-        -- resultSize;
-        ++ i;
-    }
-    return count;
-}
 ulong TCImplementation::Search(uchar const * pattern, TextPosition m, TextPosition *spResult, TextPosition *epResult) const 
 {
     // use the FM-search replacing function Occ(c,1,i) with alphabetrank->rank(c,i)
@@ -1168,16 +940,11 @@ ulong TCImplementation::SearchLessThan(uchar const * pattern, TextPosition m, Te
 
 
 TCImplementation::~TCImplementation() {
-#ifdef CSA_TEST_BWT
-    delete dynFMI;
-#endif
     delete alphabetrank;       
     delete sampled;
     delete suffixes;
     delete suffixDocId;
-
-    delete endmarkerDocId;
-    delete emptyTextRank;
+    delete Doc;
 }
 
 void TCImplementation::makewavelet(uchar *bwt)
@@ -1251,7 +1018,7 @@ void TCImplementation::maketables()
     BlockArray* tmpSuffix = new BlockArray(sampleLength, ceilLog2n);
 
     // Mapping from end-markers to doc ID's:
-    endmarkerDocId = new BlockArray(numberOfTexts, Tools::CeilLog2(numberOfTexts));
+    BlockArray *endmarkerDocId = new BlockArray(numberOfTexts, Tools::CeilLog2(numberOfTexts));
   
     ulong *sampledpositions = new ulong[n/W+1];
     for (ulong i=0;i<n/W+1;i++)
@@ -1328,6 +1095,29 @@ void TCImplementation::maketables()
     delete positions;
 //    delete textLength;
     delete textStartPos;
+
+
+    uint *tmp = new uint[numberOfTexts]; // FIXME Silly...
+//    cout << "Doc: ";
+    for (unsigned i = 0; i < numberOfTexts; ++i)
+    {
+        tmp[i] = ((*endmarkerDocId)[i] + 1) % numberOfTexts;
+        //      cout << tmp[i] << ", ";
+    }
+//    cout << endl;
+    delete endmarkerDocId;
+    alphabet_mapper * am = new alphabet_mapper_none();
+    static_bitsequence_builder * bmb = new static_bitsequence_builder_brw32(16); // FIXME samplerate?
+    wt_coder * wtc = new wt_coder_binary(tmp, numberOfTexts, am);
+    Doc = new static_sequence_wvtree(tmp, numberOfTexts, wtc, bmb, am);
+    delete bmb;
+    delete [] tmp;
+
+    /*    document_result res = Doc->access(1, 2, 0, 1);
+    cout << "result: ";
+    for (document_result::iterator it = res.begin(); it != res.end(); ++it)
+        cout << *it << ", ";
+        cout << endl;*/
 }
 
 
index 5e488db..b74f705 100644 (file)
@@ -43,8 +43,6 @@
 namespace SXSI 
 {
 
-// Un-comment to compare BWT against a BWT generated from class dynFMI:
-//#define CSA_TEST_BWT
 
 /**
  * Implementation of the TextCollection interface
@@ -125,18 +123,12 @@ private:
 
     // Total number of texts in the collection
     unsigned numberOfTexts;
-    // Total number of texts including empty texts
-    unsigned numberOfAllTexts;
     // Length of the longest text
     ulong maxTextLength;
 
     // Array of document id's in the order of end-markers in BWT
     // Access by endmarkerDocId[rank_$(L, p) - 1].
-    BlockArray *endmarkerDocId;
-
-    // FIXME Replace with a more succinct data structure
-    // Note: Empty texts are already handled inside XMLTree class.
-    BSGAP *emptyTextRank; // FIXME Remove
+    static_sequence *Doc;
 
     // Following are not part of the public API
     uchar * BWT(uchar *);
@@ -161,7 +153,50 @@ private:
     
         return alphabetrank->rank(0, ep) - ranksp;
     }
-    unsigned CountEndmarkers(TextPosition, TextPosition, DocId, DocId) const;
+
+    /**
+     * Count end-markers in given interval and
+     * within docIds [min,max]
+     */
+    inline unsigned CountEndmarkers(TextPosition sp, TextPosition ep, DocId min, DocId max) const
+    {
+        if (sp != 0)
+            sp = alphabetrank->rank(0, sp - 1);
+        ep = alphabetrank->rank(0, ep);
+        if (ep == 0)
+            return 0;
+        
+        return Doc->count(sp, ep-1, min, max);
+    }
+    
+    /**
+     * Enumerate all end-markers in given interval
+     */
+    inline document_result EnumerateEndmarkers(TextPosition sp, TextPosition ep) const
+    {
+        if (sp != 0)
+            sp = alphabetrank->rank(0, sp - 1);
+        ep = alphabetrank->rank(0, ep);
+        if (ep == 0)
+            return document_result();
+        
+        return Doc->accessAll(sp, ep-1);
+    }
+
+    /**
+     * Enumerate end-markers in given interval and
+     * within docIds [min,max]
+     */
+    inline document_result EnumerateEndmarkers(TextPosition sp, TextPosition ep, DocId min, DocId max) const
+    {
+        if (sp != 0)
+            sp = alphabetrank->rank(0, sp - 1);
+        ep = alphabetrank->rank(0, ep);
+        if (ep == 0)
+            return document_result();
+        
+        return Doc->access(sp, ep-1, min, max);
+    }
 }; // class TCImplementation
 
 } // namespace SXSI
index dad5c88..1e34ab0 100644 (file)
@@ -25,9 +25,6 @@
 #include <vector>
 #include <utility> // Defines std::pair.
 
-// Default samplerate for suffix array samples
-#define TEXTCOLLECTION_DEFAULT_SAMPLERATE 64
-
 namespace SXSI
 {