From bf3cd37b49ce6fee3faa36e81e37d0cb6c9b19c9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 24 Sep 2013 12:07:34 +0200 Subject: [PATCH] Load r-tree search data structure from shared memory --- DataStructures/StaticRTree.h | 30 +++++++------ Server/DataStructures/InternalDataFacade.h | 2 +- Server/DataStructures/SharedDataFacade.h | 52 +++++++++++++++------- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 702022848..67c2b116d 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -66,7 +66,7 @@ static boost::thread_specific_ptr thread_local_rtre template class StaticRTree : boost::noncopyable { -private: +public: struct RectangleInt2D { RectangleInt2D() : min_lon(INT_MAX), @@ -238,6 +238,16 @@ private: 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 { explicit WrappedInputElement( const uint32_t _array_index, @@ -260,14 +270,6 @@ private: 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 { explicit QueryCandidate( const uint32_t n_id, @@ -450,14 +452,13 @@ public: //SimpleLogger().Write() << m_element_count << " elements in leafs"; } - //Read-only operation for queries explicit StaticRTree( - const TreeNode * tree_node_ptr, + TreeNode * tree_node_ptr, const uint32_t number_of_nodes, 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 if ( !boost::filesystem::exists( leaf_file ) ) { throw OSRMException("mem index file does not exist"); @@ -473,6 +474,7 @@ public: //SimpleLogger().Write() << tree_size << " nodes in search tree"; //SimpleLogger().Write() << m_element_count << " elements in leafs"; } + //Read-only operation for queries /* inline void FindKNearestPhantomNodesForCoordinate( const FixedPointCoordinate & location, diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index b62290a3c..f8eeac827 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -56,7 +56,7 @@ private: typename ShM::vector m_via_node_list; typename ShM::vector m_name_ID_list; typename ShM::vector m_turn_instruction_list; - StaticRTree * m_static_rtree; + StaticRTree * m_static_rtree; void LoadTimestamp(const boost::filesystem::path & timestamp_path) { diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 305ca850c..61f3e2bdf 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -37,12 +37,14 @@ template class SharedDataFacade : public BaseDataFacade { private: - typedef BaseDataFacade super; - typedef StaticGraph QueryGraph; - typedef typename StaticGraph::_StrNode GraphNode; - typedef typename StaticGraph::_StrEdge GraphEdge; - typedef typename QueryGraph::InputEdge InputEdge; - typedef typename super::RTreeLeaf RTreeLeaf; + typedef EdgeDataT EdgeData; + typedef BaseDataFacade super; + typedef StaticGraph QueryGraph; + typedef typename StaticGraph::_StrNode GraphNode; + typedef typename StaticGraph::_StrEdge GraphEdge; + typedef typename QueryGraph::InputEdge InputEdge; + typedef typename super::RTreeLeaf RTreeLeaf; + typedef typename StaticRTree::TreeNode RTreeNode; unsigned m_check_sum; unsigned m_number_of_nodes; @@ -75,17 +77,16 @@ private: SharedMemoryFactory::Get(R_SEARCH_TREE_SIZE)->Ptr() ); SharedMemory * search_tree = SharedMemoryFactory::Get(R_SEARCH_TREE); - typedef StaticRTree TreeNode; - TreeNode * tree_ptr = static_cast( search_tree->Ptr() ); - // m_static_rtree = new StaticRTree( - // tree_ptr, - // tree_size, - // file_index_path - // ); + RTreeNode * tree_ptr = static_cast( search_tree->Ptr() ); + m_static_rtree = new StaticRTree( + tree_ptr, + tree_size, + file_index_path + ); } void LoadGraph() { - uint32_t number_of_nodes = *static_cast( + m_number_of_nodes = *static_cast( SharedMemoryFactory::Get(GRAPH_NODE_LIST_SIZE)->Ptr() ); SharedMemory * graph_nodes = SharedMemoryFactory::Get(GRAPH_NODE_LIST); @@ -97,7 +98,7 @@ private: SharedMemory * graph_edges = SharedMemoryFactory::Get(GRAPH_EDGE_LIST); GraphEdge * graph_edges_ptr = static_cast( graph_edges->Ptr() ); - typename ShM::vector node_list(graph_nodes_ptr, number_of_nodes); + typename ShM::vector node_list(graph_nodes_ptr, m_number_of_nodes); typename ShM::vector edge_list(graph_edges_ptr, number_of_edges); m_query_graph = new QueryGraph( node_list , @@ -110,10 +111,29 @@ private: uint32_t number_of_coordinates = *static_cast( SharedMemoryFactory::Get(COORDINATE_LIST_SIZE)->Ptr() ); - FixedPointCoordinate * graph_edges_ptr = static_cast( + FixedPointCoordinate * coordinate_list_ptr = static_cast( SharedMemoryFactory::Get(COORDINATE_LIST)->Ptr() ); + typename ShM::vector coordinate_list( + coordinate_list_ptr, + number_of_coordinates + ); + m_coordinate_list.swap( coordinate_list ); + uint32_t number_of_turn_instructions = *static_cast( + SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST_SIZE)->Ptr() + ); + + TurnInstruction * turn_instruction_list_ptr = static_cast( + SharedMemoryFactory::Get(TURN_INSTRUCTION_LIST)->Ptr() + ); + + typename ShM::vector turn_instruction_list( + turn_instruction_list_ptr, + number_of_turn_instructions + ); + + m_turn_instruction_list.swap(turn_instruction_list); } public: SharedDataFacade(