Names vector of strings is now passes as reference

This commit is contained in:
DennisOSRM 2012-04-14 17:40:59 +02:00
parent dd03c6b168
commit 60ffe55565
4 changed files with 19 additions and 19 deletions

View File

@ -33,24 +33,25 @@ class NodeInformationHelpDesk{
public: public:
NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) { NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) {
readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
coordinateVector.reserve(numberOfNodes);
assert(0 == coordinateVector.size()); assert(0 == coordinateVector.size());
} }
//Todo: Shared memory mechanism //Todo: Shared memory mechanism
NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) { // NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) {
readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); // readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
} // }
~NodeInformationHelpDesk() { ~NodeInformationHelpDesk() {
delete readOnlyGrid; delete readOnlyGrid;
} }
void initNNGrid(ifstream& in) { void initNNGrid(std::ifstream& in) {
while(!in.eof()) {
NodeInfo b; NodeInfo b;
in.read((char *)&b, sizeof(b)); while(!in.eof()) {
in.read((char *)&b, sizeof(NodeInfo));
coordinateVector.push_back(_Coordinate(b.lat, b.lon)); coordinateVector.push_back(_Coordinate(b.lat, b.lon));
} }
std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
numberOfNodes = coordinateVector.size();
in.close(); in.close();
readOnlyGrid->OpenIndexFiles(); readOnlyGrid->OpenIndexFiles();
} }

View File

@ -44,14 +44,14 @@ class SearchEngine {
private: private:
const GraphT * _graph; const GraphT * _graph;
NodeInformationHelpDesk * nodeHelpDesk; NodeInformationHelpDesk * nodeHelpDesk;
std::vector<string> * _names; std::vector<string> & _names;
static HeapPtr _forwardHeap; static HeapPtr _forwardHeap;
static HeapPtr _backwardHeap; static HeapPtr _backwardHeap;
static HeapPtr _forwardHeap2; static HeapPtr _forwardHeap2;
static HeapPtr _backwardHeap2; static HeapPtr _backwardHeap2;
inline double absDouble(double input) { if(input < 0) return input*(-1); else return input;} inline double absDouble(double input) { if(input < 0) return input*(-1); else return input;}
public: public:
SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector<string> * n = new std::vector<string>()) : _graph(g), nodeHelpDesk(nh), _names(n) {} SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector<string> & n) : _graph(g), nodeHelpDesk(nh), _names(n) {}
~SearchEngine() {} ~SearchEngine() {}
inline const void GetCoordinatesForNodeID(NodeID id, _Coordinate& result) const { inline const void GetCoordinatesForNodeID(NodeID id, _Coordinate& result) const {
@ -377,7 +377,7 @@ public:
} }
inline std::string GetEscapedNameForNameID(const NodeID nameID) const { 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 { inline std::string GetEscapedNameForEdgeBasedEdgeID(const unsigned edgeID) const {

View File

@ -34,7 +34,7 @@ struct ObjectsForQueryStruct {
typedef QueryGraph::InputEdge InputEdge; typedef QueryGraph::InputEdge InputEdge;
NodeInformationHelpDesk * nodeHelpDesk; NodeInformationHelpDesk * nodeHelpDesk;
std::vector<std::string> * names; std::vector<std::string> names;
QueryGraph * graph; QueryGraph * graph;
unsigned checkSum; unsigned checkSum;
@ -61,7 +61,7 @@ struct ObjectsForQueryStruct {
std::ifstream namesInStream(namesPath.c_str(), ios::binary); std::ifstream namesInStream(namesPath.c_str(), ios::binary);
unsigned size(0); unsigned size(0);
namesInStream.read((char *)&size, sizeof(unsigned)); namesInStream.read((char *)&size, sizeof(unsigned));
names = new std::vector<std::string>(); // names = new std::vector<std::string>();
char buf[1024]; char buf[1024];
for(unsigned i = 0; i < size; ++i) { for(unsigned i = 0; i < size; ++i) {
@ -69,16 +69,16 @@ struct ObjectsForQueryStruct {
namesInStream.read((char *)&sizeOfString, sizeof(unsigned)); namesInStream.read((char *)&sizeOfString, sizeof(unsigned));
buf[sizeOfString] = '\0'; // instead of memset buf[sizeOfString] = '\0'; // instead of memset
namesInStream.read(buf, sizeOfString); namesInStream.read(buf, sizeOfString);
names->push_back(buf); names.push_back(buf);
} }
std::vector<std::string>(*names).swap(*names); std::vector<std::string>(names).swap(names);
hsgrInStream.close(); hsgrInStream.close();
namesInStream.close(); namesInStream.close();
INFO("All query data structures loaded"); INFO("All query data structures loaded");
} }
~ObjectsForQueryStruct() { ~ObjectsForQueryStruct() {
delete names; // delete names;
delete graph; delete graph;
delete nodeHelpDesk; delete nodeHelpDesk;
} }

View File

@ -47,17 +47,16 @@ or see http://www.gnu.org/licenses/agpl.txt.
class ViaRoutePlugin : public BasePlugin { class ViaRoutePlugin : public BasePlugin {
private: private:
NodeInformationHelpDesk * nodeHelpDesk; NodeInformationHelpDesk * nodeHelpDesk;
std::vector<std::string> * names; std::vector<std::string> & names;
StaticGraph<EdgeData> * graph; StaticGraph<EdgeData> * graph;
HashTable<std::string, unsigned> descriptorTable; HashTable<std::string, unsigned> descriptorTable;
std::string pluginDescriptorString; std::string pluginDescriptorString;
SearchEngine<EdgeData, StaticGraph<EdgeData> > * searchEngine; SearchEngine<EdgeData, StaticGraph<EdgeData> > * searchEngine;
public: 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; nodeHelpDesk = objects->nodeHelpDesk;
graph = objects->graph; graph = objects->graph;
names = objects->names;
searchEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names); searchEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names);