/* $Id: ftindexermem.h 5786 2010-10-22 04:24:20Z abehm $ Copyright (C) 2010 by The Regents of the University of California Redistribution of this file is permitted under the terms of the BSD license. Date: 04/04/2008 Author: Alexander Behm */ #ifndef _ftindexeruncompressed_h_ #define _ftindexeruncompressed_h_ #include "ftindexermemabs.h" template class FtIndexerMem; template struct FtIndexerTraits > { typedef TStringContainer StringContainer; typedef TInvList InvList; }; template > class FtIndexerMem : public FtIndexerMemAbs > { private: typedef FtIndexerMemAbs > SuperClass; public: typedef typename SuperClass::GramMap GramMap; #ifdef DEBUG_STAT typedef IndexStats IxStatsType; #endif FtIndexerMem(StringContainer* strContainer) : SuperClass(strContainer) { #ifdef DEBUG_STAT this->ixStats = new IndexStats(); #endif } FtIndexerMem(StringContainer* strContainer, GramGen* gramGenerator, unsigned maxStrLen = 150, unsigned maxChildNodes = 50) : SuperClass(strContainer, gramGenerator, maxStrLen, maxChildNodes) { #ifdef DEBUG_STAT this->ixStats = new IndexStats(); #endif } void prepare_Impl() {}; void addStringId_Impl(FilterTreeNode* leaf, const vector& gramCodes, unsigned stringId); CompressionArgs* getCompressionArgs_Impl() { return &(this->compressionArgs); } void saveIndex_Impl(const char* indexFileName); void loadIndex_Impl(const char* indexFileName); string getName() { return "FtIndexerMem"; } }; template void FtIndexerMem:: addStringId_Impl(FilterTreeNode* leaf, const vector& gramCodes, unsigned stringId) { typename SuperClass::GramMap& gramMap = leaf->gramMap; for(unsigned i = 0; i < gramCodes.size(); i++) { unsigned gramCode = gramCodes[i]; if (gramMap.find(gramCode) == gramMap.end()) { // a new gram GramListSimple* newGramList = new GramListSimple(); gramMap[gramCode] = newGramList; newGramList->getArray()->push_back(stringId); } else { // an existing gram GramList* gramList = gramMap[gramCode]; // avoid adding duplicate elements if(gramList->getArray()->back() != stringId) gramList->getArray()->push_back(stringId); } } } template void FtIndexerMem:: saveIndex_Impl(const char* indexFileName) { ofstream fpOut; fpOut.open(indexFileName, ios::out); if(fpOut.is_open()) { this->saveBasicInfo(fpOut); this->saveLeavesRec(this->filterTreeRoot, fpOut); fpOut.close(); } else cout << "ERROR: could not open file " << indexFileName << endl; } template void FtIndexerMem:: loadIndex_Impl(const char* indexFileName) { ifstream fpIn; fpIn.open(indexFileName, ios::in); if(fpIn.is_open()) { this->filterTypes.clear(); this->loadBasicInfo(fpIn); this->buildHollowTreeRecursive(this->filterTreeRoot, 0); this->loadLeavesRec(this->filterTreeRoot, fpIn); fpIn.close(); } else cout << "ERROR: could not open file " << indexFileName << endl; } #endif