*
* 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();