From dc7089879e9f9be764eea82840f9676619a32d28 Mon Sep 17 00:00:00 2001 From: Colin Dellow Date: Tue, 7 Nov 2023 23:19:22 -0500 Subject: [PATCH] Actually use the smaller data structures Also fix the way entries are inserted into the deques - I'd really done a good job of screwing up the PR. :) --- include/osm_store.h | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/include/osm_store.h b/include/osm_store.h index 912f3f8f..8e7f2796 100644 --- a/include/osm_store.h +++ b/include/osm_store.h @@ -80,7 +80,7 @@ class NodeStore public: using element_t = std::pair; using internal_element_t = std::pair; - using map_t = std::deque>; + using map_t = std::deque>; void reopen() { @@ -122,17 +122,9 @@ class NodeStore return size; } - // @brief Insert a latp/lon pair. - // @param i OSM ID of a node - // @param coord a latp/lon pair to be inserted - // @invariant The OSM ID i must be larger than previously inserted OSM IDs of nodes - // (though unnecessarily for current impl, future impl may impose that) - void insert_back(NodeID i, LatpLon coord) { - mLatpLons[shardPart(i)]->push_back(std::make_pair(idPart(i), coord)); - } - void insert_back(std::vector const &element) { uint32_t newEntries[NODE_SHARDS] = {}; + std::vector iterators; // Before taking the lock, do a pass to find out how much // to grow each backing collection @@ -142,13 +134,17 @@ class NodeStore std::lock_guard lock(mutex); for (auto i = 0; i < NODE_SHARDS; i++) { - if (newEntries[i] == 0) continue; auto size = mLatpLons[i]->size(); mLatpLons[i]->resize(size + newEntries[i]); + iterators.push_back(mLatpLons[i]->begin() + size); } for (auto it = element.begin(); it != element.end(); it++) { - insert_back(it->first, it->second); + uint32_t shard = shardPart(it->first); + uint32_t id = idPart(it->first); + + *iterators[shard] = std::make_pair(id, it->second); + iterators[shard]++; } } @@ -505,12 +501,6 @@ class OSMStore void shapes_sort(unsigned int threadNum = 1); void generated_sort(unsigned int threadNum = 1); - void nodes_insert_back(NodeID i, LatpLon coord) { - if(!use_compact_nodes) - nodes.insert_back(i, coord); - else - compact_nodes.insert_back(i, coord); - } void nodes_insert_back(std::vector const &new_nodes) { if(!use_compact_nodes) nodes.insert_back(new_nodes);