diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index bee974874..bf91de99b 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -205,8 +205,7 @@ private: edges_input_stream.close(); SimpleLogger().Write(logDEBUG) << "Loaded " << number_of_edges << " orig edges"; - SimpleLogger().Write(logDEBUG) - << "Opening NN indices"; + SimpleLogger().Write(logDEBUG) << "Opening NN indices"; } std::vector m_coordinate_list; diff --git a/DataStructures/SearchEngine.cpp b/DataStructures/SearchEngine.cpp deleted file mode 100644 index a6cf1f838..000000000 --- a/DataStructures/SearchEngine.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - -Copyright (c) 2013, Project OSRM, Dennis Luxen, others -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list -of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this -list of conditions and the following disclaimer in the documentation and/or -other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -#include "SearchEngine.h" - -SearchEngine::SearchEngine( QueryObjectsStorage * query_objects ) : - _queryData(query_objects), - shortestPath(_queryData), - alternativePaths(_queryData) -{} - -SearchEngine::~SearchEngine() {} - -void SearchEngine::GetCoordinatesForNodeID( - NodeID id, - FixedPointCoordinate& result -) const { - result = _queryData.nodeHelpDesk->GetCoordinateOfNode(id); -} - -void SearchEngine::FindPhantomNodeForCoordinate( - const FixedPointCoordinate & location, - PhantomNode & result, - const 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 { - std::string result; - _queryData.query_objects->GetName(nameID, result); - return HTMLEntitize(result); -} - -SearchEngineHeapPtr SearchEngineData::forwardHeap; -SearchEngineHeapPtr SearchEngineData::backwardHeap; - -SearchEngineHeapPtr SearchEngineData::forwardHeap2; -SearchEngineHeapPtr SearchEngineData::backwardHeap2; - -SearchEngineHeapPtr SearchEngineData::forwardHeap3; -SearchEngineHeapPtr SearchEngineData::backwardHeap3; diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index 0d7d35dbe..37093f710 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -25,48 +25,54 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SEARCHENGINE_H_ -#define SEARCHENGINE_H_ +#ifndef SEARCHENGINE_H +#define SEARCHENGINE_H #include "Coordinate.h" #include "NodeInformationHelpDesk.h" +#include "SearchEngineData.h" #include "PhantomNodes.h" #include "QueryEdge.h" -#include "SearchEngineData.h" #include "../RoutingAlgorithms/AlternativePathRouting.h" #include "../RoutingAlgorithms/ShortestPathRouting.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../Util/StringUtil.h" #include "../typedefs.h" +#include + #include #include #include +template class SearchEngine { private: - SearchEngineData _queryData; - + DataFacadeT * facade; + SearchEngineData engine_working_data; public: - ShortestPathRouting shortestPath; - AlternativeRouting alternativePaths; + ShortestPathRouting shortest_path; + AlternativeRouting alternative_path; - SearchEngine( QueryObjectsStorage * query_objects ); - ~SearchEngine(); + SearchEngine( DataFacadeT * facade ) + : + facade (facade), + engine_working_data(facade), + shortest_path (facade, engine_working_data), + alternative_path (facade, engine_working_data) + {} - void GetCoordinatesForNodeID(NodeID id, FixedPointCoordinate& result) const; + ~SearchEngine() {} - void FindPhantomNodeForCoordinate( - const FixedPointCoordinate & location, - PhantomNode & result, - unsigned zoomLevel - ) const; - - NodeID GetNameIDForOriginDestinationNodeID( - const NodeID s, const NodeID t) const; - - std::string GetEscapedNameForNameID(const unsigned nameID) const; }; -#endif /* SEARCHENGINE_H_ */ +SearchEngineHeapPtr SearchEngineData::forwardHeap; +SearchEngineHeapPtr SearchEngineData::backwardHeap; + +SearchEngineHeapPtr SearchEngineData::forwardHeap2; +SearchEngineHeapPtr SearchEngineData::backwardHeap2; + +SearchEngineHeapPtr SearchEngineData::forwardHeap3; +SearchEngineHeapPtr SearchEngineData::backwardHeap3; + +#endif // SEARCHENGINE_H diff --git a/DataStructures/SearchEngineData.cpp b/DataStructures/SearchEngineData.cpp index 611da5b91..2a8bf23d2 100644 --- a/DataStructures/SearchEngineData.cpp +++ b/DataStructures/SearchEngineData.cpp @@ -27,40 +27,40 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SearchEngineData.h" -void SearchEngineData::InitializeOrClearFirstThreadLocalStorage() { +void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes) { if(!forwardHeap.get()) { - forwardHeap.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + forwardHeap.reset(new QueryHeap(number_of_nodes)); } else { forwardHeap->Clear(); } if(!backwardHeap.get()) { - backwardHeap.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + backwardHeap.reset(new QueryHeap(number_of_nodes)); } else { backwardHeap->Clear(); } } -void SearchEngineData::InitializeOrClearSecondThreadLocalStorage() { +void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes) { if(!forwardHeap2.get()) { - forwardHeap2.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + forwardHeap2.reset(new QueryHeap(number_of_nodes)); } else { forwardHeap2->Clear(); } if(!backwardHeap2.get()) { - backwardHeap2.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + backwardHeap2.reset(new QueryHeap(number_of_nodes)); } else { backwardHeap2->Clear(); } } -void SearchEngineData::InitializeOrClearThirdThreadLocalStorage() { +void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes) { if(!forwardHeap3.get()) { - forwardHeap3.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + forwardHeap3.reset(new QueryHeap(number_of_nodes)); } else { forwardHeap3->Clear(); } if(!backwardHeap3.get()) { - backwardHeap3.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes())); + backwardHeap3.reset(new QueryHeap(number_of_nodes)); } else { backwardHeap3->Clear(); } diff --git a/DataStructures/SearchEngineData.h b/DataStructures/SearchEngineData.h index 128cc092e..8003fa6f1 100644 --- a/DataStructures/SearchEngineData.h +++ b/DataStructures/SearchEngineData.h @@ -25,10 +25,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef SEARCH_ENGINE_DATA_H +#define SEARCH_ENGINE_DATA_H + #include "BinaryHeap.h" #include "QueryEdge.h" #include "StaticGraph.h" -#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../typedefs.h" @@ -41,23 +43,16 @@ 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(QueryObjectsStorage * query_objects) - : - query_objects(query_objects), - graph(query_objects->graph), - nodeHelpDesk(query_objects->nodeHelpDesk) - {} + typedef QueryGraph QueryGraph; + typedef QueryHeapType QueryHeap; - const QueryObjectsStorage * query_objects; - const QueryGraph * graph; - const NodeInformationHelpDesk * nodeHelpDesk; + SearchEngineData() { } static SearchEngineHeapPtr forwardHeap; static SearchEngineHeapPtr backwardHeap; @@ -66,9 +61,11 @@ struct SearchEngineData { static SearchEngineHeapPtr forwardHeap3; static SearchEngineHeapPtr backwardHeap3; - void InitializeOrClearFirstThreadLocalStorage(); + void InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes); - void InitializeOrClearSecondThreadLocalStorage(); + void InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes); - void InitializeOrClearThirdThreadLocalStorage(); + void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes); }; + +#endif // SEARCH_ENGINE_DATA_H