77 * For a full list of authors see the git log.
88 */
99
10- #include " logging.hpp"
1110#include " middle-ram.hpp"
11+
12+ #include " logging.hpp"
13+ #include " node-persistent-cache.hpp"
1214#include " options.hpp"
1315#include " output-requirements.hpp"
1416
@@ -75,6 +77,11 @@ middle_ram_t::middle_ram_t(std::shared_ptr<thread_pool_t> thread_pool,
7577 if (options->extra_attributes ) {
7678 m_store_options.untagged_nodes = true ;
7779 }
80+
81+ if (!options->flat_node_file .empty ()) {
82+ m_persistent_cache = std::make_shared<node_persistent_cache>(
83+ options->flat_node_file , options->droptemp );
84+ }
7885}
7986
8087void middle_ram_t::set_requirements (output_requirements const &requirements)
@@ -94,6 +101,7 @@ void middle_ram_t::set_requirements(output_requirements const &requirements)
94101
95102 log_debug (" Middle 'ram' options:" );
96103 log_debug (" locations: {}" , m_store_options.locations );
104+ log_debug (" locations_on_disk: {}" , !!m_persistent_cache);
97105 log_debug (" way_nodes: {}" , m_store_options.way_nodes );
98106 log_debug (" nodes: {}" , m_store_options.nodes );
99107 log_debug (" untagged_nodes: {}" , m_store_options.untagged_nodes );
@@ -107,8 +115,15 @@ void middle_ram_t::stop()
107115
108116 auto const mbyte = 1024 * 1024 ;
109117
110- log_debug (" Middle 'ram': Node locations: size={} bytes={}M" ,
111- m_node_locations.size (), m_node_locations.used_memory () / mbyte);
118+ if (m_persistent_cache) {
119+ log_debug (" Middle 'ram': Node locations on disk: size={} bytes={}M" ,
120+ m_persistent_cache->size (),
121+ m_persistent_cache->used_memory () / mbyte);
122+ } else {
123+ log_debug (" Middle 'ram': Node locations in memory: size={} bytes={}M" ,
124+ m_node_locations.size (),
125+ m_node_locations.used_memory () / mbyte);
126+ }
112127
113128 log_debug (" Middle 'ram': Way nodes data: size={} capacity={} bytes={}M" ,
114129 m_way_nodes_data.size (), m_way_nodes_data.capacity (),
@@ -180,7 +195,11 @@ void middle_ram_t::node(osmium::Node const &node)
180195 assert (node.visible ());
181196
182197 if (m_store_options.locations ) {
183- m_node_locations.set (node.id (), node.location ());
198+ if (m_persistent_cache) {
199+ m_persistent_cache->set (node.id (), node.location ());
200+ } else {
201+ m_node_locations.set (node.id (), node.location ());
202+ }
184203 }
185204
186205 if (m_store_options.nodes &&
@@ -222,7 +241,9 @@ void middle_ram_t::after_nodes()
222241 m_middle_state = middle_state::way;
223242#endif
224243
225- m_node_locations.log_stats ();
244+ if (!m_persistent_cache) {
245+ m_node_locations.log_stats ();
246+ }
226247}
227248
228249osmium::Location middle_ram_t::get_node_location (osmid_t id) const
@@ -237,10 +258,19 @@ std::size_t middle_ram_t::nodes_get_list(osmium::WayNodeList *nodes) const
237258 std::size_t count = 0 ;
238259
239260 if (m_store_options.locations ) {
240- for (auto &nr : *nodes) {
241- nr.set_location (m_node_locations.get (nr.ref ()));
242- if (nr.location ().valid ()) {
243- ++count;
261+ if (m_persistent_cache) {
262+ for (auto &nr : *nodes) {
263+ nr.set_location (m_persistent_cache->get (nr.ref ()));
264+ if (nr.location ().valid ()) {
265+ ++count;
266+ }
267+ }
268+ } else {
269+ for (auto &nr : *nodes) {
270+ nr.set_location (m_node_locations.get (nr.ref ()));
271+ if (nr.location ().valid ()) {
272+ ++count;
273+ }
244274 }
245275 }
246276 }
0 commit comments