From aaa25e5d4810cd02fbd4bd04fc96480d08b31659 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 24 Jun 2013 14:11:53 -0400 Subject: [PATCH] De-template-izing some of the code for faster (re-)compile --- DataStructures/SearchEngine.cpp | 68 +++++++++++++++++++++++++++++ DataStructures/SearchEngineData.cpp | 60 +++++++++++++++++++++++++ DataStructures/SearchEngineData.h | 60 +++++++++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 DataStructures/SearchEngine.cpp create mode 100644 DataStructures/SearchEngineData.cpp create mode 100644 DataStructures/SearchEngineData.h diff --git a/DataStructures/SearchEngine.cpp b/DataStructures/SearchEngine.cpp new file mode 100644 index 000000000..48877a0dc --- /dev/null +++ b/DataStructures/SearchEngine.cpp @@ -0,0 +1,68 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + +#include "SearchEngine.h" + +SearchEngine::SearchEngine(QueryGraph * g, NodeInformationHelpDesk * nh, std::vector & n) : + _queryData(g, nh, n), + shortestPath(_queryData), + alternativePaths(_queryData) + {} + SearchEngine::~SearchEngine() {} + +void SearchEngine::GetCoordinatesForNodeID(NodeID id, _Coordinate& result) const { + result.lat = _queryData.nodeHelpDesk->getLatitudeOfNode(id); + result.lon = _queryData.nodeHelpDesk->getLongitudeOfNode(id); +} + +void SearchEngine::FindPhantomNodeForCoordinate(const _Coordinate & location, PhantomNode & result, unsigned zoomLevel) const { + _queryData.nodeHelpDesk->FindPhantomNodeForCoordinate(location, result, zoomLevel); +} + +NodeID SearchEngine::GetNameIDForOriginDestinationNodeID(const NodeID s, const NodeID t) const { + if(s == t){ + return 0; + } + EdgeID e = _queryData.graph->FindEdge(s, t); + if(e == UINT_MAX) { + e = _queryData.graph->FindEdge( t, s ); + } + if(UINT_MAX == e) { + return 0; + } + assert(e != UINT_MAX); + const QueryEdge::EdgeData ed = _queryData.graph->GetEdgeData(e); + return ed.id; +} + +std::string SearchEngine::GetEscapedNameForNameID(const unsigned nameID) const { + return ((nameID >= _queryData.names.size() || nameID == 0) ? std::string("") : HTMLEntitize(_queryData.names.at(nameID))); +} + +SearchEngineHeapPtr SearchEngineData::forwardHeap; +SearchEngineHeapPtr SearchEngineData::backwardHeap; + +SearchEngineHeapPtr SearchEngineData::forwardHeap2; +SearchEngineHeapPtr SearchEngineData::backwardHeap2; + +SearchEngineHeapPtr SearchEngineData::forwardHeap3; +SearchEngineHeapPtr SearchEngineData::backwardHeap3; + + \ No newline at end of file diff --git a/DataStructures/SearchEngineData.cpp b/DataStructures/SearchEngineData.cpp new file mode 100644 index 000000000..77492f69e --- /dev/null +++ b/DataStructures/SearchEngineData.cpp @@ -0,0 +1,60 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + +#include "SearchEngineData.h" + +void SearchEngineData::InitializeOrClearFirstThreadLocalStorage() { + if(!forwardHeap.get()) { + forwardHeap.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes())); + } else { + forwardHeap->Clear(); + } + if(!backwardHeap.get()) { + backwardHeap.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes())); + } else { + backwardHeap->Clear(); + } +} + +void SearchEngineData::InitializeOrClearSecondThreadLocalStorage() { + if(!forwardHeap2.get()) { + forwardHeap2.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes())); + } else { + forwardHeap2->Clear(); + } + if(!backwardHeap2.get()) { + backwardHeap2.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes())); + } else { + backwardHeap2->Clear(); + } +} + +void SearchEngineData::InitializeOrClearThirdThreadLocalStorage() { + if(!forwardHeap3.get()) { + forwardHeap3.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes())); + } else { + forwardHeap3->Clear(); + } + if(!backwardHeap3.get()) { + backwardHeap3.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes())); + } else { + backwardHeap3->Clear(); + } +} diff --git a/DataStructures/SearchEngineData.h b/DataStructures/SearchEngineData.h new file mode 100644 index 000000000..f9a2623a0 --- /dev/null +++ b/DataStructures/SearchEngineData.h @@ -0,0 +1,60 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + +#include "BinaryHeap.h" +#include "QueryEdge.h" +#include "NodeInformationHelpDesk.h" +#include "StaticGraph.h" + +#include "../typedefs.h" + +#include + +#include +#include + +struct _HeapData { + NodeID parent; + _HeapData( NodeID p ) : parent(p) { } +}; +typedef StaticGraph QueryGraph; +typedef BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage > QueryHeapType; +typedef boost::thread_specific_ptr SearchEngineHeapPtr; + +struct SearchEngineData { + typedef QueryGraph Graph; + typedef QueryHeapType QueryHeap; + SearchEngineData(QueryGraph * g, NodeInformationHelpDesk * nh, std::vector & n) :graph(g), nodeHelpDesk(nh), names(n) {} + const QueryGraph * graph; + NodeInformationHelpDesk * nodeHelpDesk; + std::vector & names; + static SearchEngineHeapPtr forwardHeap; + static SearchEngineHeapPtr backwardHeap; + static SearchEngineHeapPtr forwardHeap2; + static SearchEngineHeapPtr backwardHeap2; + static SearchEngineHeapPtr forwardHeap3; + static SearchEngineHeapPtr backwardHeap3; + + void InitializeOrClearFirstThreadLocalStorage(); + + void InitializeOrClearSecondThreadLocalStorage(); + + void InitializeOrClearThirdThreadLocalStorage(); +};