diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index d48c4ded9..97f2e26cb 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -144,10 +144,11 @@ static void getListOfIndexesForEdgeAndGridSize(_Coordinate& start, _Coordinate& bresenham(x1*32768, y1*32768, x2*32768, y2*32768, indexList); } +template class NNGrid { public: - NNGrid() { ramIndexTable.resize((1024*1024), UINT_MAX); } + NNGrid() { ramIndexTable.resize((1024*1024), UINT_MAX); if( WriteAccess) { entries = new stxxl::vector(); }} NNGrid(const char* rif, const char* iif) { ramIndexTable.resize((1024*1024), UINT_MAX); @@ -158,6 +159,11 @@ public: ~NNGrid() { if(ramInFile.is_open()) ramInFile.close(); if(indexInFile.is_open()) indexInFile.close(); + + if (WriteAccess) + { + delete entries; + } } void OpenIndexFiles() @@ -183,7 +189,7 @@ public: getListOfIndexesForEdgeAndGridSize(start, target, indexList); for(int i = 0; i < indexList.size(); i++) { - entries.push_back(GridEdgeData(edge, indexList[i].first, indexList[i].second)); + entries->push_back(GridEdgeData(edge, indexList[i].first, indexList[i].second)); } } @@ -192,18 +198,18 @@ public: double timestamp = get_timestamp(); //create index file on disk, old one is over written indexOutFile.open(fileIndexOut, std::ios::out | std::ios::binary | std::ios::trunc); - cout << "sorting grid data consisting of " << entries.size() << " edges..." << flush; + cout << "sorting grid data consisting of " << entries->size() << " edges..." << flush; //sort entries - stxxl::sort(entries.begin(), entries.end(), CompareGridEdgeDataByRamIndex(), 1024*1024*1024); + stxxl::sort(entries->begin(), entries->end(), CompareGridEdgeDataByRamIndex(), 1024*1024*1024); cout << "ok in " << (get_timestamp() - timestamp) << "s" << endl; std::vector entriesInFileWithRAMSameIndex; - unsigned indexInRamTable = entries.begin()->ramIndex; + unsigned indexInRamTable = entries->begin()->ramIndex; unsigned lastPositionInIndexFile = 0; unsigned numberOfUsedCells = 0; unsigned maxNumberOfRAMCellElements = 0; cout << "writing data ..." << flush; - Percent p(entries.size()); - for(stxxl::vector::iterator vt = entries.begin(); vt != entries.end(); vt++) + Percent p(entries->size()); + for(stxxl::vector::iterator vt = entries->begin(); vt != entries->end(); vt++) { p.printIncrement(); if(vt->ramIndex != indexInRamTable) @@ -587,7 +593,7 @@ private: ofstream indexOutFile; ifstream indexInFile; ifstream ramInFile; - stxxl::vector entries; + stxxl::vector * entries; std::vector ramIndexTable; //4 MB for first level index in RAM }; } diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 9c413d1e6..bcfd26af6 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -29,11 +29,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "NNGrid.h" #include "PhantomNodes.h" -typedef NNGrid::NNGrid Grid; +typedef NNGrid::NNGrid ReadOnlyGrid; class NodeInformationHelpDesk{ public: - NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput) { numberOfNodes = 0; int2ExtNodeMap = new vector<_Coordinate>(); g = new Grid(ramIndexInput,fileIndexInput); } + NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput) { numberOfNodes = 0; int2ExtNodeMap = new vector<_Coordinate>(); g = new ReadOnlyGrid(ramIndexInput,fileIndexInput); } ~NodeInformationHelpDesk() { delete int2ExtNodeMap; delete g; } void initNNGrid(ifstream& in) { @@ -61,7 +61,7 @@ public: } private: vector<_Coordinate> * int2ExtNodeMap; - Grid * g; + ReadOnlyGrid * g; unsigned numberOfNodes; }; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index e6f603f01..16168dadd 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -51,7 +51,7 @@ using namespace std; typedef ContractionCleanup::Edge::EdgeData EdgeData; typedef DynamicGraph::InputEdge GridEdge; -typedef NNGrid::NNGrid Grid; +typedef NNGrid::NNGrid WritableGrid; vector * int2ExtNodeMap = new vector(); @@ -88,7 +88,7 @@ int main (int argc, char *argv[]) strcat(fileIndexOut, ".fileIndex"); ofstream mapOutFile(nodeOut, ios::binary); - Grid * g = new Grid(); + WritableGrid * g = new WritableGrid(); cout << "building grid ..." << flush; Percent p(edgeList.size()); for(NodeID i = 0; i < edgeList.size(); i++)