From 60ffe55565f45c508457a99e591e2724889fa7a0 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Sat, 14 Apr 2012 17:40:59 +0200 Subject: [PATCH] Names vector of strings is now passes as reference --- DataStructures/NodeInformationHelpDesk.h | 17 +++++++++-------- DataStructures/SearchEngine.h | 6 +++--- Plugins/ObjectForPluginStruct.h | 10 +++++----- Plugins/ViaRoutePlugin.h | 5 ++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 5d8fbdc25..51eb2bad2 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -33,25 +33,26 @@ class NodeInformationHelpDesk{ public: NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) { readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); - coordinateVector.reserve(numberOfNodes); assert(0 == coordinateVector.size()); } //Todo: Shared memory mechanism - NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) { - readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); - } +// NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) { +// readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); +// } ~NodeInformationHelpDesk() { delete readOnlyGrid; } - void initNNGrid(ifstream& in) { + void initNNGrid(std::ifstream& in) { + NodeInfo b; while(!in.eof()) { - NodeInfo b; - in.read((char *)&b, sizeof(b)); + in.read((char *)&b, sizeof(NodeInfo)); coordinateVector.push_back(_Coordinate(b.lat, b.lon)); } - in.close(); + std::vector<_Coordinate>(coordinateVector).swap(coordinateVector); + numberOfNodes = coordinateVector.size(); + in.close(); readOnlyGrid->OpenIndexFiles(); } diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index a73a98e77..719f01457 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -44,14 +44,14 @@ class SearchEngine { private: const GraphT * _graph; NodeInformationHelpDesk * nodeHelpDesk; - std::vector * _names; + std::vector & _names; static HeapPtr _forwardHeap; static HeapPtr _backwardHeap; static HeapPtr _forwardHeap2; static HeapPtr _backwardHeap2; inline double absDouble(double input) { if(input < 0) return input*(-1); else return input;} public: - SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector * n = new std::vector()) : _graph(g), nodeHelpDesk(nh), _names(n) {} + SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector & n) : _graph(g), nodeHelpDesk(nh), _names(n) {} ~SearchEngine() {} inline const void GetCoordinatesForNodeID(NodeID id, _Coordinate& result) const { @@ -377,7 +377,7 @@ public: } inline std::string GetEscapedNameForNameID(const NodeID nameID) const { - return ((nameID >= _names->size() || nameID == 0) ? std::string("") : HTMLEntitize(_names->at(nameID))); + return ((nameID >= _names.size() || nameID == 0) ? std::string("") : HTMLEntitize(_names.at(nameID))); } inline std::string GetEscapedNameForEdgeBasedEdgeID(const unsigned edgeID) const { diff --git a/Plugins/ObjectForPluginStruct.h b/Plugins/ObjectForPluginStruct.h index 50fd72732..631257d75 100644 --- a/Plugins/ObjectForPluginStruct.h +++ b/Plugins/ObjectForPluginStruct.h @@ -34,7 +34,7 @@ struct ObjectsForQueryStruct { typedef QueryGraph::InputEdge InputEdge; NodeInformationHelpDesk * nodeHelpDesk; - std::vector * names; + std::vector names; QueryGraph * graph; unsigned checkSum; @@ -61,7 +61,7 @@ struct ObjectsForQueryStruct { std::ifstream namesInStream(namesPath.c_str(), ios::binary); unsigned size(0); namesInStream.read((char *)&size, sizeof(unsigned)); - names = new std::vector(); +// names = new std::vector(); char buf[1024]; for(unsigned i = 0; i < size; ++i) { @@ -69,16 +69,16 @@ struct ObjectsForQueryStruct { namesInStream.read((char *)&sizeOfString, sizeof(unsigned)); buf[sizeOfString] = '\0'; // instead of memset namesInStream.read(buf, sizeOfString); - names->push_back(buf); + names.push_back(buf); } - std::vector(*names).swap(*names); + std::vector(names).swap(names); hsgrInStream.close(); namesInStream.close(); INFO("All query data structures loaded"); } ~ObjectsForQueryStruct() { - delete names; +// delete names; delete graph; delete nodeHelpDesk; } diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 317ee2593..032b9ec95 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -47,17 +47,16 @@ or see http://www.gnu.org/licenses/agpl.txt. class ViaRoutePlugin : public BasePlugin { private: NodeInformationHelpDesk * nodeHelpDesk; - std::vector * names; + std::vector & names; StaticGraph * graph; HashTable descriptorTable; std::string pluginDescriptorString; SearchEngine > * searchEngine; public: - ViaRoutePlugin(ObjectsForQueryStruct * objects, std::string psd = "viaroute") : pluginDescriptorString(psd) { + ViaRoutePlugin(ObjectsForQueryStruct * objects, std::string psd = "viaroute") : names(objects->names), pluginDescriptorString(psd) { nodeHelpDesk = objects->nodeHelpDesk; graph = objects->graph; - names = objects->names; searchEngine = new SearchEngine >(graph, nodeHelpDesk, names);