Change StaticRTree serialization constructor to static function
Since the constructor does not satisfy the requirements for a constructor (the RTree is not properly initialized) make it a static function instead.
This commit is contained in:
		
							parent
							
								
									8f05fc0a84
								
							
						
					
					
						commit
						a3dd9c3e57
					
				| @ -170,7 +170,10 @@ int Prepare::Process(int argc, char *argv[]) | |||||||
| 
 | 
 | ||||||
|     TIMER_STOP(expansion); |     TIMER_STOP(expansion); | ||||||
| 
 | 
 | ||||||
|     BuildRTree(node_based_edge_list); |     StaticRTree<EdgeBasedNode>::Build(node_based_edge_list, | ||||||
|  |                                       rtree_nodes_path.c_str(), | ||||||
|  |                                       rtree_leafs_path.c_str(), | ||||||
|  |                                       internal_to_external_node_map); | ||||||
| 
 | 
 | ||||||
|     IteratorbasedCRC32<std::vector<EdgeBasedNode>> crc32; |     IteratorbasedCRC32<std::vector<EdgeBasedNode>> crc32; | ||||||
|     const unsigned node_based_edge_list_CRC32 = |     const unsigned node_based_edge_list_CRC32 = | ||||||
| @ -544,16 +547,3 @@ void Prepare::WriteNodeMapping() | |||||||
|     internal_to_external_node_map.shrink_to_fit(); |     internal_to_external_node_map.shrink_to_fit(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 |  | ||||||
|     \brief Building rtree-based nearest-neighbor data structure |  | ||||||
| 
 |  | ||||||
|     Saves info to files: '.ramIndex' and '.fileIndex'. |  | ||||||
|  */ |  | ||||||
| void Prepare::BuildRTree(std::vector<EdgeBasedNode> &node_based_edge_list) |  | ||||||
| { |  | ||||||
|     SimpleLogger().Write() << "building r-tree ..."; |  | ||||||
|     StaticRTree<EdgeBasedNode>(node_based_edge_list, |  | ||||||
|                                rtree_nodes_path.c_str(), |  | ||||||
|                                rtree_leafs_path.c_str(), |  | ||||||
|                                internal_to_external_node_map); |  | ||||||
| } |  | ||||||
|  | |||||||
| @ -40,7 +40,6 @@ class Prepare | |||||||
|                                 DeallocatingVector<EdgeBasedEdge> &edgeBasedEdgeList, |                                 DeallocatingVector<EdgeBasedEdge> &edgeBasedEdgeList, | ||||||
|                                 EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile); |                                 EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile); | ||||||
|     void WriteNodeMapping(); |     void WriteNodeMapping(); | ||||||
|     void BuildRTree(std::vector<EdgeBasedNode> &node_based_edge_list); |  | ||||||
| 
 | 
 | ||||||
|   private: |   private: | ||||||
|     std::vector<NodeInfo> internal_to_external_node_map; |     std::vector<NodeInfo> internal_to_external_node_map; | ||||||
|  | |||||||
| @ -307,24 +307,24 @@ class StaticRTree | |||||||
|     StaticRTree(const StaticRTree &) = delete; |     StaticRTree(const StaticRTree &) = delete; | ||||||
| 
 | 
 | ||||||
|     // Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1]
 |     // Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1]
 | ||||||
|     explicit StaticRTree(std::vector<EdgeDataT> &input_data_vector, |     static void Build(std::vector<EdgeDataT> &input_data_vector, | ||||||
|                          const std::string tree_node_filename, |                          const std::string tree_node_filename, | ||||||
|                          const std::string leaf_node_filename, |                          const std::string leaf_node_filename, | ||||||
|                          const std::vector<NodeInfo> &coordinate_list) |                          const std::vector<NodeInfo> &coordinate_list) | ||||||
|         : m_element_count(input_data_vector.size()), m_leaf_node_filename(leaf_node_filename) |  | ||||||
|     { |     { | ||||||
|         SimpleLogger().Write() << "constructing r-tree of " << m_element_count |         uint64_t element_count = input_data_vector.size(); | ||||||
|  |         SimpleLogger().Write() << "constructing r-tree of " << element_count | ||||||
|                                << " edge elements build on-top of " << coordinate_list.size() |                                << " edge elements build on-top of " << coordinate_list.size() | ||||||
|                                << " coordinates"; |                                << " coordinates"; | ||||||
| 
 | 
 | ||||||
|         TIMER_START(construction); |         TIMER_START(construction); | ||||||
|         std::vector<WrappedInputElement> input_wrapper_vector(m_element_count); |         std::vector<WrappedInputElement> input_wrapper_vector(element_count); | ||||||
| 
 | 
 | ||||||
|         HilbertCode get_hilbert_number; |         HilbertCode get_hilbert_number; | ||||||
| 
 | 
 | ||||||
|         // generate auxiliary vector of hilbert-values
 |         // generate auxiliary vector of hilbert-values
 | ||||||
|         tbb::parallel_for( |         tbb::parallel_for( | ||||||
|             tbb::blocked_range<uint64_t>(0, m_element_count), |             tbb::blocked_range<uint64_t>(0, element_count), | ||||||
|             [&input_data_vector, &input_wrapper_vector, &get_hilbert_number, &coordinate_list]( |             [&input_data_vector, &input_wrapper_vector, &get_hilbert_number, &coordinate_list]( | ||||||
|                 const tbb::blocked_range<uint64_t> &range) |                 const tbb::blocked_range<uint64_t> &range) | ||||||
|             { |             { | ||||||
| @ -351,7 +351,7 @@ class StaticRTree | |||||||
| 
 | 
 | ||||||
|         // open leaf file
 |         // open leaf file
 | ||||||
|         boost::filesystem::ofstream leaf_node_file(leaf_node_filename, std::ios::binary); |         boost::filesystem::ofstream leaf_node_file(leaf_node_filename, std::ios::binary); | ||||||
|         leaf_node_file.write((char *)&m_element_count, sizeof(uint64_t)); |         leaf_node_file.write((char *) &element_count, sizeof(uint64_t)); | ||||||
| 
 | 
 | ||||||
|         // sort the hilbert-value representatives
 |         // sort the hilbert-value representatives
 | ||||||
|         tbb::parallel_sort(input_wrapper_vector.begin(), input_wrapper_vector.end()); |         tbb::parallel_sort(input_wrapper_vector.begin(), input_wrapper_vector.end()); | ||||||
| @ -359,7 +359,7 @@ class StaticRTree | |||||||
| 
 | 
 | ||||||
|         // pack M elements into leaf node and write to leaf file
 |         // pack M elements into leaf node and write to leaf file
 | ||||||
|         uint64_t processed_objects_count = 0; |         uint64_t processed_objects_count = 0; | ||||||
|         while (processed_objects_count < m_element_count) |         while (processed_objects_count < element_count) | ||||||
|         { |         { | ||||||
| 
 | 
 | ||||||
|             LeafNode current_leaf; |             LeafNode current_leaf; | ||||||
| @ -369,7 +369,7 @@ class StaticRTree | |||||||
|             for (uint32_t current_element_index = 0; LEAF_NODE_SIZE > current_element_index; |             for (uint32_t current_element_index = 0; LEAF_NODE_SIZE > current_element_index; | ||||||
|                  ++current_element_index) |                  ++current_element_index) | ||||||
|             { |             { | ||||||
|                 if (m_element_count > (processed_objects_count + current_element_index)) |                 if (element_count > (processed_objects_count + current_element_index)) | ||||||
|                 { |                 { | ||||||
|                     uint32_t index_of_next_object = |                     uint32_t index_of_next_object = | ||||||
|                         input_wrapper_vector[processed_objects_count + current_element_index] |                         input_wrapper_vector[processed_objects_count + current_element_index] | ||||||
| @ -395,6 +395,8 @@ class StaticRTree | |||||||
|         // close leaf file
 |         // close leaf file
 | ||||||
|         leaf_node_file.close(); |         leaf_node_file.close(); | ||||||
| 
 | 
 | ||||||
|  |         typename ShM<TreeNode, UseSharedMemory>::vector search_tree; | ||||||
|  | 
 | ||||||
|         uint32_t processing_level = 0; |         uint32_t processing_level = 0; | ||||||
|         while (1 < tree_nodes_in_level.size()) |         while (1 < tree_nodes_in_level.size()) | ||||||
|         { |         { | ||||||
| @ -413,8 +415,8 @@ class StaticRTree | |||||||
|                         TreeNode ¤t_child_node = |                         TreeNode ¤t_child_node = | ||||||
|                             tree_nodes_in_level[processed_tree_nodes_in_level]; |                             tree_nodes_in_level[processed_tree_nodes_in_level]; | ||||||
|                         // add tree node to parent entry
 |                         // add tree node to parent entry
 | ||||||
|                         parent_node.children[current_child_node_index] = m_search_tree.size(); |                         parent_node.children[current_child_node_index] = search_tree.size(); | ||||||
|                         m_search_tree.emplace_back(current_child_node); |                         search_tree.emplace_back(current_child_node); | ||||||
|                         // merge MBRs
 |                         // merge MBRs
 | ||||||
|                         parent_node.minimum_bounding_rectangle.MergeBoundingBoxes( |                         parent_node.minimum_bounding_rectangle.MergeBoundingBoxes( | ||||||
|                             current_child_node.minimum_bounding_rectangle); |                             current_child_node.minimum_bounding_rectangle); | ||||||
| @ -430,18 +432,18 @@ class StaticRTree | |||||||
|         } |         } | ||||||
|         BOOST_ASSERT_MSG(1 == tree_nodes_in_level.size(), "tree broken, more than one root node"); |         BOOST_ASSERT_MSG(1 == tree_nodes_in_level.size(), "tree broken, more than one root node"); | ||||||
|         // last remaining entry is the root node, store it
 |         // last remaining entry is the root node, store it
 | ||||||
|         m_search_tree.emplace_back(tree_nodes_in_level[0]); |         search_tree.emplace_back(tree_nodes_in_level[0]); | ||||||
| 
 | 
 | ||||||
|         // reverse and renumber tree to have root at index 0
 |         // reverse and renumber tree to have root at index 0
 | ||||||
|         std::reverse(m_search_tree.begin(), m_search_tree.end()); |         std::reverse(search_tree.begin(), search_tree.end()); | ||||||
| 
 | 
 | ||||||
|         uint32_t search_tree_size = m_search_tree.size(); |         uint32_t search_tree_size = search_tree.size(); | ||||||
|         tbb::parallel_for(tbb::blocked_range<uint32_t>(0, search_tree_size), |         tbb::parallel_for(tbb::blocked_range<uint32_t>(0, search_tree_size), | ||||||
|                           [this, &search_tree_size](const tbb::blocked_range<uint32_t> &range) |         [&search_tree, &search_tree_size](const tbb::blocked_range<uint32_t> &range) | ||||||
|         { |         { | ||||||
|             for (uint32_t i = range.begin(); i != range.end(); ++i) |             for (uint32_t i = range.begin(); i != range.end(); ++i) | ||||||
|             { |             { | ||||||
|                 TreeNode ¤t_tree_node = this->m_search_tree[i]; |                 TreeNode ¤t_tree_node = search_tree[i]; | ||||||
|                 for (uint32_t j = 0; j < current_tree_node.child_count; ++j) |                 for (uint32_t j = 0; j < current_tree_node.child_count; ++j) | ||||||
|                 { |                 { | ||||||
|                     const uint32_t old_id = current_tree_node.children[j]; |                     const uint32_t old_id = current_tree_node.children[j]; | ||||||
| @ -454,10 +456,10 @@ class StaticRTree | |||||||
|         // open tree file
 |         // open tree file
 | ||||||
|         boost::filesystem::ofstream tree_node_file(tree_node_filename, std::ios::binary); |         boost::filesystem::ofstream tree_node_file(tree_node_filename, std::ios::binary); | ||||||
| 
 | 
 | ||||||
|         uint32_t size_of_tree = m_search_tree.size(); |         uint32_t size_of_tree = search_tree.size(); | ||||||
|         BOOST_ASSERT_MSG(0 < size_of_tree, "tree empty"); |         BOOST_ASSERT_MSG(0 < size_of_tree, "tree empty"); | ||||||
|         tree_node_file.write((char *) &size_of_tree, sizeof(uint32_t)); |         tree_node_file.write((char *) &size_of_tree, sizeof(uint32_t)); | ||||||
|         tree_node_file.write((char *)&m_search_tree[0], sizeof(TreeNode) * size_of_tree); |         tree_node_file.write((char *) &search_tree[0], sizeof(TreeNode) * size_of_tree); | ||||||
|         // close tree node file.
 |         // close tree node file.
 | ||||||
|         tree_node_file.close(); |         tree_node_file.close(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user