Added RLCSA index option
[SXSI/TextCollection.git] / TextStorage.cpp
index 77c61ac..beac53a 100644 (file)
@@ -65,7 +65,7 @@ TextStorage * TextStorage::Load(std::FILE *file)
 }
 
 TextStorage::TextStorage(std::FILE * file)
-    : n_(0), offsets_(0), numberOfTexts_(0)
+    : n_(0), offsets_(0), offit_(0), numberOfTexts_(0)
 {
    if (std::fread(&(this->n_), sizeof(TextPosition), 1, file) != 1)
         throw std::runtime_error("TextStorage::Load(): file read error (n_).");
@@ -74,6 +74,7 @@ TextStorage::TextStorage(std::FILE * file)
         throw std::runtime_error("TextStorage::Load(): file read error (numberOfTexts_).");
 
     offsets_ = new CSA::DeltaVector(file);   
+    offit_ = new CSA::DeltaVector::Iterator(*offsets_);
 }
 
 void TextStorage::Save(FILE *file, char type) const
@@ -142,10 +143,10 @@ uchar * TextStorageLzIndex::GetText(TextCollection::DocId docId) const
 {
     assert(docId < (TextCollection::DocId)numberOfTexts_);
 
-    TextPosition from = offsets_->select(docId);
+    TextPosition from = offit_->select(docId);
     TextPosition to = 0;
     if (docId < (TextCollection::DocId)numberOfTexts_ - 1)
-        to = offsets_->select(docId + 1) - 1;
+        to = offit_->select(docId + 1) - 1;
     else
         to = n_-1;
 
@@ -162,10 +163,10 @@ uchar * TextStorageLzIndex::GetText(TextCollection::DocId i, TextCollection::Doc
     assert(i < (TextCollection::DocId)numberOfTexts_);
     assert(j < (TextCollection::DocId)numberOfTexts_);
 
-    TextPosition from = offsets_->select(i);
+    TextPosition from = offit_->select(i);
     TextPosition to = 0;
     if (j < (TextCollection::DocId)numberOfTexts_ - 1)
-        to = offsets_->select(j + 1) - 1;
+        to = offit_->select(j + 1) - 1;
     else
         to = n_-1;
 
@@ -177,7 +178,7 @@ uchar * TextStorageLzIndex::GetText(TextCollection::DocId i, TextCollection::Doc
     while (i < j && i < (TextCollection::DocId)numberOfTexts_)
     {        
         ++i;
-        text[offsets_->select(i) - 1 - from] = 0;
+        text[offit_->select(i) - 1 - from] = 0;
     }
     text[l-1] = 0;
     return text;