name_list --> name_char_data and name_offsets
-Use stxxl vectors with char and unsigned int containers -Write out the entire character vector to fil -Cap the names at length 255 during the parsing so we reduce the amount of memory used by stxxl vectors and we can do a direct writing of the character vector to .names
This commit is contained in:
		
							parent
							
								
									5b782a783a
								
							
						
					
					
						commit
						da91d342f7
					
				| @ -55,7 +55,8 @@ ExtractionContainers::ExtractionContainers() | |||||||
| { | { | ||||||
|     // Check if stxxl can be instantiated
 |     // Check if stxxl can be instantiated
 | ||||||
|     stxxl::vector<unsigned> dummy_vector; |     stxxl::vector<unsigned> dummy_vector; | ||||||
|     name_list.push_back(""); |     name_char_data.push_back('\0'); | ||||||
|  |     name_offsets.push_back(1); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ExtractionContainers::~ExtractionContainers() | ExtractionContainers::~ExtractionContainers() | ||||||
| @ -64,7 +65,8 @@ ExtractionContainers::~ExtractionContainers() | |||||||
|     used_node_id_list.clear(); |     used_node_id_list.clear(); | ||||||
|     all_nodes_list.clear(); |     all_nodes_list.clear(); | ||||||
|     all_edges_list.clear(); |     all_edges_list.clear(); | ||||||
|     name_list.clear(); |     name_char_data.clear(); | ||||||
|  |     name_offsets.clear(); | ||||||
|     restrictions_list.clear(); |     restrictions_list.clear(); | ||||||
|     way_start_end_id_list.clear(); |     way_start_end_id_list.clear(); | ||||||
| } | } | ||||||
| @ -116,27 +118,20 @@ void ExtractionContainers::WriteNames(const std::string& names_file_name) const | |||||||
|     boost::filesystem::ofstream name_file_stream(names_file_name, std::ios::binary); |     boost::filesystem::ofstream name_file_stream(names_file_name, std::ios::binary); | ||||||
| 
 | 
 | ||||||
|     unsigned total_length = 0; |     unsigned total_length = 0; | ||||||
|     std::vector<unsigned> name_lengths; | 
 | ||||||
|     for (const std::string &temp_string : name_list) |     for (const unsigned &name_offset : name_offsets) | ||||||
|     { |     { | ||||||
|         const unsigned string_length = |         total_length += name_offset; | ||||||
|             std::min(static_cast<unsigned>(temp_string.length()), 255u); |  | ||||||
|         name_lengths.push_back(string_length); |  | ||||||
|         total_length += string_length; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // builds and writes the index
 |     // builds and writes the index
 | ||||||
|     RangeTable<> name_index_range(name_lengths); |     RangeTable<> name_index_range(name_offsets); | ||||||
|     name_file_stream << name_index_range; |     name_file_stream << name_index_range; | ||||||
| 
 | 
 | ||||||
|     name_file_stream.write((char *)&total_length, sizeof(unsigned)); |     name_file_stream.write((char *)&total_length, sizeof(unsigned)); | ||||||
|  | 
 | ||||||
|     // write all chars consecutively
 |     // write all chars consecutively
 | ||||||
|     for (const std::string &temp_string : name_list) |     name_file_stream.write((const char *)&name_char_data[0], name_char_data.size()); | ||||||
|     { |  | ||||||
|         const unsigned string_length = |  | ||||||
|             std::min(static_cast<unsigned>(temp_string.length()), 255u); |  | ||||||
|         name_file_stream.write(temp_string.c_str(), string_length); |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     name_file_stream.close(); |     name_file_stream.close(); | ||||||
|     TIMER_STOP(write_name_index); |     TIMER_STOP(write_name_index); | ||||||
|  | |||||||
| @ -70,7 +70,8 @@ class ExtractionContainers | |||||||
|     STXXLNodeIDVector used_node_id_list; |     STXXLNodeIDVector used_node_id_list; | ||||||
|     STXXLNodeVector all_nodes_list; |     STXXLNodeVector all_nodes_list; | ||||||
|     STXXLEdgeVector all_edges_list; |     STXXLEdgeVector all_edges_list; | ||||||
|     std::vector<std::string> name_list; |     stxxl::vector<char> name_char_data; | ||||||
|  |     std::vector<unsigned> name_offsets; | ||||||
|     STXXLRestrictionsVector restrictions_list; |     STXXLRestrictionsVector restrictions_list; | ||||||
|     STXXLWayIDStartEndVector way_start_end_id_list; |     STXXLWayIDStartEndVector way_start_end_id_list; | ||||||
|     std::unordered_map<OSMNodeID, NodeID> external_to_internal_node_id_map; |     std::unordered_map<OSMNodeID, NodeID> external_to_internal_node_id_map; | ||||||
|  | |||||||
| @ -153,10 +153,21 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti | |||||||
| 
 | 
 | ||||||
|     // Get the unique identifier for the street name
 |     // Get the unique identifier for the street name
 | ||||||
|     const auto &string_map_iterator = string_map.find(parsed_way.name); |     const auto &string_map_iterator = string_map.find(parsed_way.name); | ||||||
|     unsigned name_id = external_memory.name_list.size(); |     unsigned name_id = external_memory.name_offsets.size(); | ||||||
|     if (string_map.end() == string_map_iterator) |     if (string_map.end() == string_map_iterator) | ||||||
|     { |     { | ||||||
|         external_memory.name_list.push_back(parsed_way.name); |         unsigned name_length = 0; | ||||||
|  |         for (const char &c : parsed_way.name) | ||||||
|  |         { | ||||||
|  |             // Cap name length at 255 characters
 | ||||||
|  |             if (name_length == 255u) | ||||||
|  |             { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |             external_memory.name_char_data.push_back(c); | ||||||
|  |             name_length++; | ||||||
|  |         } | ||||||
|  |         external_memory.name_offsets.push_back(name_length); | ||||||
|         string_map.insert(std::make_pair(parsed_way.name, name_id)); |         string_map.insert(std::make_pair(parsed_way.name, name_id)); | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user