Added index_mode flag
authornvalimak <nvalimak@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Mon, 30 Aug 2010 15:58:44 +0000 (15:58 +0000)
committernvalimak <nvalimak@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Mon, 30 Aug 2010 15:58:44 +0000 (15:58 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/TextCollection@906 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

TCImplementation.cpp
TCImplementation.h
TextCollection.cpp
TextCollection.h

index 130b1a2..1a29f25 100644 (file)
@@ -767,14 +767,16 @@ void TCImplementation::Save(FILE *file) const
  *
  * Throws a std::runtime_error exception on i/o error.
  * For more info, see TCImplementation::Save().
+ * 
+ * index_mode_t is defined in TextCollection.h and
+ * defaults to both the index and "naive" text.
+ * 
+ * Note: Samplerate can not be changed during load.
  */
-TCImplementation::TCImplementation(FILE *file, unsigned samplerate_)
+TCImplementation::TCImplementation(FILE *file, index_mode_t im, unsigned samplerate_)
     : n(0), samplerate(samplerate_), alphabetrank(0), sampled(0), suffixes(0), 
       suffixDocId(0), numberOfTexts(0), maxTextLength(0), Doc(0)
 {
-//    Tools::StartTimer();
-//    std::cout << std::endl << "Loading..."<< std::endl;
-
     uchar verFlag = 0;
     if (std::fread(&verFlag, 1, 1, file) != 1)
         throw std::runtime_error("TCImplementation::Load(): file read error (version flag).");
@@ -796,24 +798,25 @@ TCImplementation::TCImplementation(FILE *file, unsigned samplerate_)
     if (std::fread(&(this->bwtEndPos), sizeof(TextPosition), 1, file) != 1)
         throw std::runtime_error("TCImplementation::Load(): file read error (bwt end position).");
 
-//    std::cout << "Loading alphabet rank (" << Tools::GetTime() << " s)." << std::endl;
     alphabetrank = static_sequence::load(file);
-//    std::cout << "Loading samples (" << Tools::GetTime() << " s)." << std::endl;
+    if (im == index_mode_text_only) { delete alphabetrank; alphabetrank = 0; }
+
     sampled = static_bitsequence::load(file);
+    if (im == index_mode_text_only) { delete sampled; sampled = 0; }
     suffixes = new BlockArray(file);
+    if (im == index_mode_text_only) { delete suffixes; suffixes = 0; }
     suffixDocId = new BlockArray(file);
+    if (im == index_mode_text_only) { delete suffixDocId; suffixDocId = 0; }
 
     if (std::fread(&(this->numberOfTexts), sizeof(unsigned), 1, file) != 1)
         throw std::runtime_error("TCImplementation::Load(): file read error (numberOfTexts).");
     if (std::fread(&(this->maxTextLength), sizeof(ulong), 1, file) != 1)
         throw std::runtime_error("TCImplementation::Load(): file read error (maxTextLength).");
 
-//    std::cout << "Loading Doc (" << Tools::GetTime() << " s)." << std::endl;
     Doc = new ArrayDoc(file); //static_sequence::load(file);
-//    std::cout << "Loading text storage (" << Tools::GetTime() << " s)." << std::endl;
-    textStorage = TextStorage::Load(file);
+    if (im == index_mode_text_only) { delete Doc; Doc = 0; }
 
-//    std::cout << "Loading done(" << Tools::GetTime() << " s)." << std::endl;
+    textStorage = TextStorage::Load(file);
 
     // FIXME Construct data structures with new samplerate
     //maketables(); 
index ff5f713..ff5dff3 100644 (file)
@@ -140,7 +140,7 @@ public:
     full_result FullKErrors(uchar const *, unsigned) const;
 
     // Index from/to disk
-    TCImplementation(FILE *, unsigned);
+    TCImplementation(FILE *, index_mode_t, unsigned);
     void Save(FILE *) const;
 
 private:
index d099a3c..2aef067 100644 (file)
@@ -9,9 +9,9 @@ namespace SXSI
      *
      * See TCImplementation.h for more details.
      */
-    TextCollection * TextCollection::Load(FILE *fp, unsigned samplerate)
+    TextCollection * TextCollection::Load(FILE *fp, index_mode_t im, unsigned samplerate)
     {
-        TextCollection *result = new TCImplementation(fp, samplerate);
+        TextCollection *result = new TCImplementation(fp, im, samplerate);
         return result;
     }
 }
index dbc7982..2ea24ca 100644 (file)
@@ -42,16 +42,18 @@ namespace SXSI
         // Type for text position (FIXME ulong or long?)
         typedef ulong TextPosition;
 
+        // mode flag: Default includes both the index and "naive" text
+        enum index_mode_t { index_mode_default, index_mode_text_only }; // index_mode_index_only
+
         /**
          * Load from a file
          *
          * New samplerate can be given, otherwise will use the one specified in the save file!
-         * Note: This is not a static method; call InitTextCollection() first to get the object handle.
          *
          * Throws an exception if std::fread() fails.
          * 
          */
-        static TextCollection* Load(FILE *, unsigned samplerate = 0);
+        static TextCollection* Load(FILE *, index_mode_t = index_mode_default, unsigned samplerate = 0);
 
         /**
          * Save data structure into a file
@@ -197,6 +199,8 @@ namespace SXSI
         // Protected constructor; use TextCollectionBuilder
         TextCollection() { };
 
+//        index_mode_t indexMode;
+
         // No copy constructor or assignment
         TextCollection(TextCollection const&);
         TextCollection& operator = (TextCollection const&);