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,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();
}

View File

@ -44,14 +44,14 @@ class SearchEngine {
private:
const GraphT * _graph;
NodeInformationHelpDesk * nodeHelpDesk;
std::vector<string> * _names;
std::vector<string> & _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<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() {}
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 {

View File

@ -34,7 +34,7 @@ struct ObjectsForQueryStruct {
typedef QueryGraph::InputEdge InputEdge;
NodeInformationHelpDesk * nodeHelpDesk;
std::vector<std::string> * names;
std::vector<std::string> 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<std::string>();
// names = new std::vector<std::string>();
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<std::string>(*names).swap(*names);
std::vector<std::string>(names).swap(names);
hsgrInStream.close();
namesInStream.close();
INFO("All query data structures loaded");
}
~ObjectsForQueryStruct() {
delete names;
// delete names;
delete graph;
delete nodeHelpDesk;
}

View File

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