Load r-tree search data structure from shared memory

This commit is contained in:
Dennis Luxen 2013-09-24 12:07:34 +02:00
parent e35a78e3cf
commit bbf03e3060
3 changed files with 53 additions and 31 deletions

View File

@ -70,7 +70,7 @@ static boost::thread_specific_ptr<boost::filesystem::ifstream> thread_local_rtre
template<class DataT, bool UseSharedMemory = false> template<class DataT, bool UseSharedMemory = false>
class StaticRTree : boost::noncopyable { class StaticRTree : boost::noncopyable {
private: public:
struct RectangleInt2D { struct RectangleInt2D {
RectangleInt2D() : RectangleInt2D() :
min_lon(INT_MAX), min_lon(INT_MAX),
@ -242,6 +242,16 @@ private:
typedef RectangleInt2D RectangleT; typedef RectangleInt2D RectangleT;
struct TreeNode {
TreeNode() : child_count(0), child_is_on_disk(false) {}
RectangleT minimum_bounding_rectangle;
uint32_t child_count:31;
bool child_is_on_disk:1;
uint32_t children[RTREE_BRANCHING_FACTOR];
};
private:
struct WrappedInputElement { struct WrappedInputElement {
explicit WrappedInputElement( explicit WrappedInputElement(
const uint32_t _array_index, const uint32_t _array_index,
@ -264,14 +274,6 @@ private:
DataT objects[RTREE_LEAF_NODE_SIZE]; DataT objects[RTREE_LEAF_NODE_SIZE];
}; };
struct TreeNode {
TreeNode() : child_count(0), child_is_on_disk(false) {}
RectangleT minimum_bounding_rectangle;
uint32_t child_count:31;
bool child_is_on_disk:1;
uint32_t children[RTREE_BRANCHING_FACTOR];
};
struct QueryCandidate { struct QueryCandidate {
explicit QueryCandidate( explicit QueryCandidate(
const uint32_t n_id, const uint32_t n_id,
@ -454,14 +456,13 @@ public:
//SimpleLogger().Write() << m_element_count << " elements in leafs"; //SimpleLogger().Write() << m_element_count << " elements in leafs";
} }
//Read-only operation for queries
explicit StaticRTree( explicit StaticRTree(
const TreeNode * tree_node_ptr, TreeNode * tree_node_ptr,
const uint32_t number_of_nodes, const uint32_t number_of_nodes,
const boost::filesystem::path & leaf_file const boost::filesystem::path & leaf_file
) : m_leaf_node_filename(leaf_file.string()), ) : m_search_tree(tree_node_ptr, number_of_nodes),
m_search_tree(tree_node_ptr, number_of_nodes) m_leaf_node_filename(leaf_file.string())
{ {
//open leaf node file and store thread specific pointer //open leaf node file and store thread specific pointer
if ( !boost::filesystem::exists( leaf_file ) ) { if ( !boost::filesystem::exists( leaf_file ) ) {
throw OSRMException("mem index file does not exist"); throw OSRMException("mem index file does not exist");
@ -477,6 +478,7 @@ public:
//SimpleLogger().Write() << tree_size << " nodes in search tree"; //SimpleLogger().Write() << tree_size << " nodes in search tree";
//SimpleLogger().Write() << m_element_count << " elements in leafs"; //SimpleLogger().Write() << m_element_count << " elements in leafs";
} }
//Read-only operation for queries
/* /*
inline void FindKNearestPhantomNodesForCoordinate( inline void FindKNearestPhantomNodesForCoordinate(
const FixedPointCoordinate & location, const FixedPointCoordinate & location,

View File

@ -56,7 +56,7 @@ private:
typename ShM<NodeID, false>::vector m_via_node_list; typename ShM<NodeID, false>::vector m_via_node_list;
typename ShM<unsigned, false>::vector m_name_ID_list; typename ShM<unsigned, false>::vector m_name_ID_list;
typename ShM<TurnInstruction, false>::vector m_turn_instruction_list; typename ShM<TurnInstruction, false>::vector m_turn_instruction_list;
StaticRTree<RTreeLeaf, false> * m_static_rtree; StaticRTree<RTreeLeaf, false> * m_static_rtree;
void LoadTimestamp(const boost::filesystem::path & timestamp_path) { void LoadTimestamp(const boost::filesystem::path & timestamp_path) {

View File

@ -37,12 +37,14 @@ template<class EdgeDataT>
class SharedDataFacade : public BaseDataFacade<EdgeDataT> { class SharedDataFacade : public BaseDataFacade<EdgeDataT> {
private: private:
typedef BaseDataFacade<EdgeDataT> super; typedef EdgeDataT EdgeData;
typedef StaticGraph<typename super::EdgeData, true> QueryGraph; typedef BaseDataFacade<EdgeData> super;
typedef typename StaticGraph<typename super::EdgeData, true>::_StrNode GraphNode; typedef StaticGraph<EdgeData, true> QueryGraph;
typedef typename StaticGraph<typename super::EdgeData, true>::_StrEdge GraphEdge; typedef typename StaticGraph<EdgeData, true>::_StrNode GraphNode;
typedef typename QueryGraph::InputEdge InputEdge; typedef typename StaticGraph<EdgeData, true>::_StrEdge GraphEdge;
typedef typename super::RTreeLeaf RTreeLeaf; typedef typename QueryGraph::InputEdge InputEdge;
typedef typename super::RTreeLeaf RTreeLeaf;
typedef typename StaticRTree<RTreeLeaf, true>::TreeNode RTreeNode;
unsigned m_check_sum; unsigned m_check_sum;
unsigned m_number_of_nodes; unsigned m_number_of_nodes;
@ -75,17 +77,16 @@ private:
SharedMemoryFactory::Get(R_SEARCH_TREE_SIZE)->Ptr() SharedMemoryFactory::Get(R_SEARCH_TREE_SIZE)->Ptr()
); );
SharedMemory * search_tree = SharedMemoryFactory::Get(R_SEARCH_TREE); SharedMemory * search_tree = SharedMemoryFactory::Get(R_SEARCH_TREE);
typedef StaticRTree<RTreeLeaf, true> TreeNode; RTreeNode * tree_ptr = static_cast<RTreeNode *>( search_tree->Ptr() );
TreeNode * tree_ptr = static_cast<TreeNode *>( search_tree->Ptr() ); m_static_rtree = new StaticRTree<RTreeLeaf, true>(
// m_static_rtree = new StaticRTree<RTreeLeaf, true>( tree_ptr,
// tree_ptr, tree_size,
// tree_size, file_index_path
// file_index_path );
// );
} }
void LoadGraph() { void LoadGraph() {
uint32_t number_of_nodes = *static_cast<unsigned *>( m_number_of_nodes = *static_cast<unsigned *>(
SharedMemoryFactory::Get(GRAPH_NODE_LIST_SIZE)->Ptr() SharedMemoryFactory::Get(GRAPH_NODE_LIST_SIZE)->Ptr()
); );
SharedMemory * graph_nodes = SharedMemoryFactory::Get(GRAPH_NODE_LIST); SharedMemory * graph_nodes = SharedMemoryFactory::Get(GRAPH_NODE_LIST);
@ -97,7 +98,7 @@ private:
SharedMemory * graph_edges = SharedMemoryFactory::Get(GRAPH_EDGE_LIST); SharedMemory * graph_edges = SharedMemoryFactory::Get(GRAPH_EDGE_LIST);
GraphEdge * graph_edges_ptr = static_cast<GraphEdge *>( graph_edges->Ptr() ); GraphEdge * graph_edges_ptr = static_cast<GraphEdge *>( graph_edges->Ptr() );
typename ShM<GraphNode, true>::vector node_list(graph_nodes_ptr, number_of_nodes); typename ShM<GraphNode, true>::vector node_list(graph_nodes_ptr, m_number_of_nodes);
typename ShM<GraphEdge, true>::vector edge_list(graph_edges_ptr, number_of_edges); typename ShM<GraphEdge, true>::vector edge_list(graph_edges_ptr, number_of_edges);
m_query_graph = new QueryGraph( m_query_graph = new QueryGraph(
node_list , node_list ,
@ -110,10 +111,29 @@ private:
uint32_t number_of_coordinates = *static_cast<unsigned *>( uint32_t number_of_coordinates = *static_cast<unsigned *>(
SharedMemoryFactory::Get(COORDINATE_LIST_SIZE)->Ptr() SharedMemoryFactory::Get(COORDINATE_LIST_SIZE)->Ptr()
); );
FixedPointCoordinate * graph_edges_ptr = static_cast<FixedPointCoordinate *>( FixedPointCoordinate * coordinate_list_ptr = static_cast<FixedPointCoordinate *>(
SharedMemoryFactory::Get(COORDINATE_LIST)->Ptr() SharedMemoryFactory::Get(COORDINATE_LIST)->Ptr()
); );
typename ShM<FixedPointCoordinate, true>::vector coordinate_list(
coordinate_list_ptr,
number_of_coordinates
);
m_coordinate_list.swap( coordinate_list );
uint32_t number_of_turn_instructions = *static_cast<unsigned *>(
SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST_SIZE)->Ptr()
);
TurnInstruction * turn_instruction_list_ptr = static_cast<TurnInstruction * >(
SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST)->Ptr()
);
typename ShM<TurnInstruction, true>::vector turn_instruction_list(
turn_instruction_list_ptr,
number_of_turn_instructions
);
m_turn_instruction_list.swap(turn_instruction_list);
} }
public: public:
SharedDataFacade( SharedDataFacade(