*
* 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).");
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();
// 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
// Protected constructor; use TextCollectionBuilder
TextCollection() { };
+// index_mode_t indexMode;
+
// No copy constructor or assignment
TextCollection(TextCollection const&);
TextCollection& operator = (TextCollection const&);