Skip to content

Commit ba8ef22

Browse files
committed
Refactor: Use idlist_t instead of osmium::index::IdSetSmall<osmid_t>
They are both basically the same class. We need a few functions from IdSetSmall though.
1 parent 65a9317 commit ba8ef22

File tree

11 files changed

+91
-61
lines changed

11 files changed

+91
-61
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ target_sources(osm2pgsql_lib PRIVATE
1919
geom-from-osm.cpp
2020
geom-functions.cpp
2121
geom-pole-of-inaccessibility.cpp
22+
idlist.cpp
2223
input.cpp
2324
logging.cpp
2425
middle.cpp

src/dependency-manager.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515

1616
void full_dependency_manager_t::node_changed(osmid_t id)
1717
{
18-
m_changed_nodes.set(id);
18+
m_changed_nodes.push_back(id);
1919
}
2020

2121
void full_dependency_manager_t::way_changed(osmid_t id)
2222
{
23-
m_changed_ways.set(id);
23+
m_changed_ways.push_back(id);
2424
}
2525

2626
void full_dependency_manager_t::relation_changed(osmid_t id)
2727
{
28-
m_changed_relations.set(id);
28+
m_changed_relations.push_back(id);
2929
}
3030

3131
void full_dependency_manager_t::after_nodes()
@@ -39,15 +39,13 @@ void full_dependency_manager_t::after_nodes()
3939
m_changed_nodes.clear();
4040
}
4141

42-
static osmium::index::IdSetSmall<osmid_t>
43-
set_diff(osmium::index::IdSetSmall<osmid_t> const &set,
44-
osmium::index::IdSetSmall<osmid_t> const &to_be_removed)
42+
static idlist_t set_diff(idlist_t const &set, idlist_t const &to_be_removed)
4543
{
46-
osmium::index::IdSetSmall<osmid_t> new_set;
44+
idlist_t new_set;
4745

4846
for (auto const id : set) {
4947
if (!to_be_removed.get_binary_search(id)) {
50-
new_set.set(id);
48+
new_set.push_back(id);
5149
}
5250
}
5351

@@ -92,7 +90,7 @@ void full_dependency_manager_t::after_relations()
9290
}
9391

9492
void full_dependency_manager_t::mark_parent_relations_as_pending(
95-
osmium::index::IdSetSmall<osmid_t> const &way_ids)
93+
idlist_t const &way_ids)
9694
{
9795
assert(m_rels_pending_tracker.empty());
9896
m_object_store->get_way_parents(way_ids, &m_rels_pending_tracker);
@@ -103,8 +101,7 @@ bool full_dependency_manager_t::has_pending() const noexcept
103101
return !m_ways_pending_tracker.empty() || !m_rels_pending_tracker.empty();
104102
}
105103

106-
idlist_t
107-
full_dependency_manager_t::get_ids(osmium::index::IdSetSmall<osmid_t> *tracker)
104+
idlist_t full_dependency_manager_t::get_ids(idlist_t *tracker)
108105
{
109106
tracker->sort_unique();
110107

src/dependency-manager.hpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include "idlist.hpp"
1414
#include "osmtypes.hpp"
1515

16-
#include <osmium/index/id_set.hpp>
17-
1816
#include <cassert>
1917
#include <memory>
2018
#include <utility>
@@ -59,8 +57,7 @@ class dependency_manager_t
5957
virtual void after_ways() {}
6058
virtual void after_relations() {}
6159

62-
virtual void mark_parent_relations_as_pending(
63-
osmium::index::IdSetSmall<osmid_t> const & /*way_ids*/)
60+
virtual void mark_parent_relations_as_pending(idlist_t const & /*way_ids*/)
6461
{
6562
}
6663

@@ -112,8 +109,7 @@ class full_dependency_manager_t : public dependency_manager_t
112109
void after_ways() override;
113110
void after_relations() override;
114111

115-
void mark_parent_relations_as_pending(
116-
osmium::index::IdSetSmall<osmid_t> const &ids) override;
112+
void mark_parent_relations_as_pending(idlist_t const &ids) override;
117113

118114
bool has_pending() const noexcept override;
119115

@@ -128,7 +124,7 @@ class full_dependency_manager_t : public dependency_manager_t
128124
}
129125

130126
private:
131-
static idlist_t get_ids(osmium::index::IdSetSmall<osmid_t> *tracker);
127+
static idlist_t get_ids(idlist_t *tracker);
132128

133129
std::shared_ptr<middle_t> m_object_store;
134130

@@ -140,7 +136,7 @@ class full_dependency_manager_t : public dependency_manager_t
140136
* the change file, too, and so we don't have to find out which ones they
141137
* are.
142138
*/
143-
osmium::index::IdSetSmall<osmid_t> m_changed_nodes;
139+
idlist_t m_changed_nodes;
144140

145141
/**
146142
* In append mode all new and changed ways will be added to this. After
@@ -149,17 +145,17 @@ class full_dependency_manager_t : public dependency_manager_t
149145
* relations that referenced deleted ways must be in the change file, too,
150146
* and so we don't have to find out which ones they are.
151147
*/
152-
osmium::index::IdSetSmall<osmid_t> m_changed_ways;
148+
idlist_t m_changed_ways;
153149

154150
/**
155151
* In append mode all new and changed relations will be added to this.
156152
* This is then used to remove already processed relations from the
157153
* pending list.
158154
*/
159-
osmium::index::IdSetSmall<osmid_t> m_changed_relations;
155+
idlist_t m_changed_relations;
160156

161-
osmium::index::IdSetSmall<osmid_t> m_ways_pending_tracker;
162-
osmium::index::IdSetSmall<osmid_t> m_rels_pending_tracker;
157+
idlist_t m_ways_pending_tracker;
158+
idlist_t m_rels_pending_tracker;
163159
};
164160

165161
#endif // OSM2PGSQL_DEPENDENCY_MANAGER_HPP

src/idlist.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* SPDX-License-Identifier: GPL-2.0-or-later
3+
*
4+
* This file is part of osm2pgsql (https://osm2pgsql.org/).
5+
*
6+
* Copyright (C) 2006-2023 by the osm2pgsql developer community.
7+
* For a full list of authors see the git log.
8+
*/
9+
10+
#include "idlist.hpp"
11+
12+
#include <algorithm>
13+
#include <iterator>
14+
#include <utility>
15+
16+
void idlist_t::sort_unique()
17+
{
18+
std::sort(m_list.begin(), m_list.end());
19+
const auto last = std::unique(m_list.begin(), m_list.end());
20+
m_list.erase(last, m_list.end());
21+
}
22+
23+
void idlist_t::merge_sorted(const idlist_t &other)
24+
{
25+
std::vector<osmid_t> new_list;
26+
27+
new_list.reserve(m_list.size() + other.m_list.size());
28+
std::set_union(m_list.cbegin(), m_list.cend(), other.m_list.cbegin(),
29+
other.m_list.cend(), std::back_inserter(new_list));
30+
31+
using std::swap;
32+
swap(new_list, m_list);
33+
}

src/idlist.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@ class idlist_t
3838

3939
auto end() const noexcept { return m_list.end(); }
4040

41+
auto cbegin() const noexcept { return m_list.cbegin(); }
42+
43+
auto cend() const noexcept { return m_list.cend(); }
44+
4145
osmid_t operator[](std::size_t n) const noexcept { return m_list[n]; }
4246

47+
bool get_binary_search(osmid_t id) const noexcept
48+
{
49+
return std::binary_search(m_list.cbegin(), m_list.cend(), id);
50+
}
51+
4352
void clear() { m_list.clear(); }
4453

4554
void push_back(osmid_t id) { m_list.push_back(id); }
@@ -64,6 +73,10 @@ class idlist_t
6473
return !(lhs == rhs);
6574
}
6675

76+
void sort_unique();
77+
78+
void merge_sorted(const idlist_t &other);
79+
6780
private:
6881
std::vector<osmid_t> m_list;
6982

src/middle-pgsql.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ static bool check_bucket_index(pg_conn_t const *db_connection,
5656
}
5757

5858
static void send_id_list(pg_conn_t const &db_connection,
59-
std::string const &table,
60-
osmium::index::IdSetSmall<osmid_t> const &ids)
59+
std::string const &table, idlist_t const &ids)
6160
{
6261
std::string data;
6362
for (auto const id : ids) {
@@ -71,13 +70,12 @@ static void send_id_list(pg_conn_t const &db_connection,
7170
}
7271

7372
static void load_id_list(pg_conn_t const &db_connection,
74-
std::string const &table,
75-
osmium::index::IdSetSmall<osmid_t> *ids)
73+
std::string const &table, idlist_t *ids)
7674
{
7775
auto const res = db_connection.exec(
7876
fmt::format("SELECT DISTINCT id FROM {} ORDER BY id", table));
7977
for (int n = 0; n < res.num_tuples(); ++n) {
80-
ids->set(osmium::string_to_object_id(res.get_value(n, 0)));
78+
ids->push_back(osmium::string_to_object_id(res.get_value(n, 0)));
8179
}
8280
}
8381

@@ -827,10 +825,9 @@ void middle_pgsql_t::node_delete(osmid_t osm_id)
827825
}
828826
}
829827

830-
void middle_pgsql_t::get_node_parents(
831-
osmium::index::IdSetSmall<osmid_t> const &changed_nodes,
832-
osmium::index::IdSetSmall<osmid_t> *parent_ways,
833-
osmium::index::IdSetSmall<osmid_t> *parent_relations) const
828+
void middle_pgsql_t::get_node_parents(idlist_t const &changed_nodes,
829+
idlist_t *parent_ways,
830+
idlist_t *parent_relations) const
834831
{
835832
util::timer_t timer;
836833

@@ -923,9 +920,8 @@ INSERT INTO osm2pgsql_changed_relations
923920
parent_ways->size(), parent_relations->size());
924921
}
925922

926-
void middle_pgsql_t::get_way_parents(
927-
osmium::index::IdSetSmall<osmid_t> const &changed_ways,
928-
osmium::index::IdSetSmall<osmid_t> *parent_relations) const
923+
void middle_pgsql_t::get_way_parents(idlist_t const &changed_ways,
924+
idlist_t *parent_relations) const
929925
{
930926
util::timer_t timer;
931927

src/middle-pgsql.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <osmium/index/nwr_array.hpp>
2525

2626
#include "db-copy-mgr.hpp"
27+
#include "idlist.hpp"
2728
#include "middle.hpp"
2829
#include "pgsql.hpp"
2930

@@ -117,14 +118,11 @@ struct middle_pgsql_t : public middle_t
117118
void after_ways() override;
118119
void after_relations() override;
119120

120-
void get_node_parents(
121-
osmium::index::IdSetSmall<osmid_t> const &changed_nodes,
122-
osmium::index::IdSetSmall<osmid_t> *parent_ways,
123-
osmium::index::IdSetSmall<osmid_t> *parent_relations) const override;
121+
void get_node_parents(idlist_t const &changed_nodes, idlist_t *parent_ways,
122+
idlist_t *parent_relations) const override;
124123

125-
void get_way_parents(
126-
osmium::index::IdSetSmall<osmid_t> const &changed_ways,
127-
osmium::index::IdSetSmall<osmid_t> *parent_relations) const override;
124+
void get_way_parents(idlist_t const &changed_ways,
125+
idlist_t *parent_relations) const override;
128126

129127
class table_desc
130128
{

src/middle.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
* For a full list of authors see the git log.
1111
*/
1212

13-
#include <osmium/index/id_set.hpp>
1413
#include <osmium/memory/buffer.hpp>
1514
#include <osmium/osm/entity_bits.hpp>
1615

1716
#include <memory>
1817

18+
#include "idlist.hpp"
1919
#include "osmtypes.hpp"
2020
#include "thread-pool.hpp"
2121

@@ -149,16 +149,14 @@ class middle_t
149149
#endif
150150
}
151151

152-
virtual void get_node_parents(
153-
osmium::index::IdSetSmall<osmid_t> const & /*changed_nodes*/,
154-
osmium::index::IdSetSmall<osmid_t> * /*parent_ways*/,
155-
osmium::index::IdSetSmall<osmid_t> * /*parent_relations*/) const
152+
virtual void get_node_parents(idlist_t const & /*changed_nodes*/,
153+
idlist_t * /*parent_ways*/,
154+
idlist_t * /*parent_relations*/) const
156155
{
157156
}
158157

159-
virtual void get_way_parents(
160-
osmium::index::IdSetSmall<osmid_t> const & /*changed_ways*/,
161-
osmium::index::IdSetSmall<osmid_t> * /*parent_relations*/) const
158+
virtual void get_way_parents(idlist_t const & /*changed_ways*/,
159+
idlist_t * /*parent_relations*/) const
162160
{
163161
}
164162

src/output-flex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ void output_flex_t::select_relation_members()
998998
"integer way ids."};
999999
}
10001000

1001-
m_stage2_way_ids->set(id);
1001+
m_stage2_way_ids->push_back(id);
10021002
});
10031003

10041004
lua_pop(lua_state(), 2); // return value (a table), ways field (a table)
@@ -1486,7 +1486,7 @@ void output_flex_t::init_lua(std::string const &filename)
14861486
lua_remove(lua_state(), 1); // global "osm2pgsql"
14871487
}
14881488

1489-
idset_t const &output_flex_t::get_marked_way_ids()
1489+
idlist_t const &output_flex_t::get_marked_way_ids()
14901490
{
14911491
if (m_stage2_way_ids->empty()) {
14921492
log_info("Skipping stage 1c (no marked ways).");

src/output-flex.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include "flex-table-column.hpp"
1717
#include "flex-table.hpp"
1818
#include "geom.hpp"
19+
#include "idlist.hpp"
1920
#include "output.hpp"
2021

21-
#include <osmium/index/id_set.hpp>
2222
#include <osmium/osm/item_type.hpp>
2323

2424
#include <lua.hpp>
@@ -35,8 +35,6 @@ class geom_transform_t;
3535
class thread_pool_t;
3636
struct options_t;
3737

38-
using idset_t = osmium::index::IdSetSmall<osmid_t>;
39-
4038
/**
4139
* When C++ code is called from the Lua code we sometimes need to know
4240
* in what context this happens. These are the possible contexts.
@@ -128,7 +126,7 @@ class output_flex_t : public output_t
128126

129127
void wait() override;
130128

131-
idset_t const &get_marked_way_ids() override;
129+
idlist_t const &get_marked_way_ids() override;
132130
void reprocess_marked() override;
133131

134132
void pending_way(osmid_t id) override;
@@ -295,7 +293,7 @@ class output_flex_t : public output_t
295293

296294
// This is shared between all clones of the output and must only be
297295
// accessed while protected using the lua_mutex.
298-
std::shared_ptr<idset_t> m_stage2_way_ids = std::make_shared<idset_t>();
296+
std::shared_ptr<idlist_t> m_stage2_way_ids = std::make_shared<idlist_t>();
299297

300298
std::shared_ptr<db_copy_thread_t> m_copy_thread;
301299

0 commit comments

Comments
 (0)