Moving DataStructures to new data facade pattern
This commit is contained in:
parent
ac14a7b0da
commit
01d2d91ecc
@ -195,8 +195,7 @@ private:
|
|||||||
edges_input_stream.close();
|
edges_input_stream.close();
|
||||||
SimpleLogger().Write(logDEBUG)
|
SimpleLogger().Write(logDEBUG)
|
||||||
<< "Loaded " << number_of_edges << " orig edges";
|
<< "Loaded " << number_of_edges << " orig edges";
|
||||||
SimpleLogger().Write(logDEBUG)
|
SimpleLogger().Write(logDEBUG) << "Opening NN indices";
|
||||||
<< "Opening NN indices";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<FixedPointCoordinate> m_coordinate_list;
|
std::vector<FixedPointCoordinate> m_coordinate_list;
|
||||||
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
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( 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;
|
|
@ -18,48 +18,54 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SEARCHENGINE_H_
|
#ifndef SEARCHENGINE_H
|
||||||
#define SEARCHENGINE_H_
|
#define SEARCHENGINE_H
|
||||||
|
|
||||||
#include "Coordinate.h"
|
#include "Coordinate.h"
|
||||||
#include "NodeInformationHelpDesk.h"
|
#include "NodeInformationHelpDesk.h"
|
||||||
|
#include "SearchEngineData.h"
|
||||||
#include "PhantomNodes.h"
|
#include "PhantomNodes.h"
|
||||||
#include "QueryEdge.h"
|
#include "QueryEdge.h"
|
||||||
#include "SearchEngineData.h"
|
|
||||||
#include "../RoutingAlgorithms/AlternativePathRouting.h"
|
#include "../RoutingAlgorithms/AlternativePathRouting.h"
|
||||||
#include "../RoutingAlgorithms/ShortestPathRouting.h"
|
#include "../RoutingAlgorithms/ShortestPathRouting.h"
|
||||||
#include "../Server/DataStructures/QueryObjectsStorage.h"
|
|
||||||
|
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
template<class DataFacadeT>
|
||||||
class SearchEngine {
|
class SearchEngine {
|
||||||
private:
|
private:
|
||||||
SearchEngineData _queryData;
|
DataFacadeT * facade;
|
||||||
|
SearchEngineData engine_working_data;
|
||||||
public:
|
public:
|
||||||
ShortestPathRouting<SearchEngineData> shortestPath;
|
ShortestPathRouting<DataFacadeT> shortest_path;
|
||||||
AlternativeRouting<SearchEngineData> alternativePaths;
|
AlternativeRouting <DataFacadeT> alternative_path;
|
||||||
|
|
||||||
SearchEngine( QueryObjectsStorage * query_objects );
|
SearchEngine( DataFacadeT * facade )
|
||||||
~SearchEngine();
|
:
|
||||||
|
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
|
||||||
|
@ -20,40 +20,40 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
#include "SearchEngineData.h"
|
#include "SearchEngineData.h"
|
||||||
|
|
||||||
void SearchEngineData::InitializeOrClearFirstThreadLocalStorage() {
|
void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes) {
|
||||||
if(!forwardHeap.get()) {
|
if(!forwardHeap.get()) {
|
||||||
forwardHeap.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
forwardHeap.reset(new QueryHeap(number_of_nodes));
|
||||||
} else {
|
} else {
|
||||||
forwardHeap->Clear();
|
forwardHeap->Clear();
|
||||||
}
|
}
|
||||||
if(!backwardHeap.get()) {
|
if(!backwardHeap.get()) {
|
||||||
backwardHeap.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
backwardHeap.reset(new QueryHeap(number_of_nodes));
|
||||||
} else {
|
} else {
|
||||||
backwardHeap->Clear();
|
backwardHeap->Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchEngineData::InitializeOrClearSecondThreadLocalStorage() {
|
void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes) {
|
||||||
if(!forwardHeap2.get()) {
|
if(!forwardHeap2.get()) {
|
||||||
forwardHeap2.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
forwardHeap2.reset(new QueryHeap(number_of_nodes));
|
||||||
} else {
|
} else {
|
||||||
forwardHeap2->Clear();
|
forwardHeap2->Clear();
|
||||||
}
|
}
|
||||||
if(!backwardHeap2.get()) {
|
if(!backwardHeap2.get()) {
|
||||||
backwardHeap2.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
backwardHeap2.reset(new QueryHeap(number_of_nodes));
|
||||||
} else {
|
} else {
|
||||||
backwardHeap2->Clear();
|
backwardHeap2->Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchEngineData::InitializeOrClearThirdThreadLocalStorage() {
|
void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes) {
|
||||||
if(!forwardHeap3.get()) {
|
if(!forwardHeap3.get()) {
|
||||||
forwardHeap3.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
forwardHeap3.reset(new QueryHeap(number_of_nodes));
|
||||||
} else {
|
} else {
|
||||||
forwardHeap3->Clear();
|
forwardHeap3->Clear();
|
||||||
}
|
}
|
||||||
if(!backwardHeap3.get()) {
|
if(!backwardHeap3.get()) {
|
||||||
backwardHeap3.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
backwardHeap3.reset(new QueryHeap(number_of_nodes));
|
||||||
} else {
|
} else {
|
||||||
backwardHeap3->Clear();
|
backwardHeap3->Clear();
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
or see http://www.gnu.org/licenses/agpl.txt.
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef SEARCH_ENGINE_DATA_H
|
||||||
|
#define SEARCH_ENGINE_DATA_H
|
||||||
|
|
||||||
#include "BinaryHeap.h"
|
#include "BinaryHeap.h"
|
||||||
#include "QueryEdge.h"
|
#include "QueryEdge.h"
|
||||||
#include "StaticGraph.h"
|
#include "StaticGraph.h"
|
||||||
#include "../Server/DataStructures/QueryObjectsStorage.h"
|
|
||||||
|
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
@ -34,23 +36,16 @@ struct _HeapData {
|
|||||||
NodeID parent;
|
NodeID parent;
|
||||||
_HeapData( NodeID p ) : parent(p) { }
|
_HeapData( NodeID p ) : parent(p) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef StaticGraph<QueryEdge::EdgeData> QueryGraph;
|
typedef StaticGraph<QueryEdge::EdgeData> QueryGraph;
|
||||||
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> > QueryHeapType;
|
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, UnorderedMapStorage<NodeID, int> > QueryHeapType;
|
||||||
typedef boost::thread_specific_ptr<QueryHeapType> SearchEngineHeapPtr;
|
typedef boost::thread_specific_ptr<QueryHeapType> SearchEngineHeapPtr;
|
||||||
|
|
||||||
struct SearchEngineData {
|
struct SearchEngineData {
|
||||||
typedef QueryGraph Graph;
|
typedef QueryGraph QueryGraph;
|
||||||
typedef QueryHeapType QueryHeap;
|
typedef QueryHeapType QueryHeap;
|
||||||
SearchEngineData(QueryObjectsStorage * query_objects)
|
|
||||||
:
|
|
||||||
query_objects(query_objects),
|
|
||||||
graph(query_objects->graph),
|
|
||||||
nodeHelpDesk(query_objects->nodeHelpDesk)
|
|
||||||
{}
|
|
||||||
|
|
||||||
const QueryObjectsStorage * query_objects;
|
SearchEngineData() { }
|
||||||
const QueryGraph * graph;
|
|
||||||
const NodeInformationHelpDesk * nodeHelpDesk;
|
|
||||||
|
|
||||||
static SearchEngineHeapPtr forwardHeap;
|
static SearchEngineHeapPtr forwardHeap;
|
||||||
static SearchEngineHeapPtr backwardHeap;
|
static SearchEngineHeapPtr backwardHeap;
|
||||||
@ -59,9 +54,11 @@ struct SearchEngineData {
|
|||||||
static SearchEngineHeapPtr forwardHeap3;
|
static SearchEngineHeapPtr forwardHeap3;
|
||||||
static SearchEngineHeapPtr backwardHeap3;
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user