Skip to content

Commit 3c1257e

Browse files
committed
Replace set_diff function by something a bit more sensible
1 parent 3b7fdc5 commit 3c1257e

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/dependency-manager.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,13 @@ void full_dependency_manager_t::after_nodes()
3939
m_changed_nodes.clear();
4040
}
4141

42-
static idlist_t set_diff(idlist_t const &set, idlist_t const &to_be_removed)
43-
{
44-
idlist_t new_set;
45-
46-
for (auto const id : set) {
47-
if (!to_be_removed.get_binary_search(id)) {
48-
new_set.push_back(id);
49-
}
50-
}
51-
52-
return new_set;
53-
}
54-
5542
void full_dependency_manager_t::after_ways()
5643
{
5744
if (!m_changed_ways.empty()) {
5845
if (!m_ways_pending_tracker.empty()) {
5946
// Remove ids from changed ways in the input data from
6047
// m_ways_pending_tracker, because they have already been processed.
61-
m_ways_pending_tracker =
62-
set_diff(m_ways_pending_tracker, m_changed_ways);
48+
m_ways_pending_tracker.remove_ids_if_in(m_changed_ways);
6349

6450
// Add the list of pending way ids to the list of changed ways,
6551
// because we need the parents for them, too.
@@ -83,8 +69,7 @@ void full_dependency_manager_t::after_relations()
8369
{
8470
// Remove ids from changed relations in the input data from
8571
// m_rels_pending_tracker, because they have already been processed.
86-
m_rels_pending_tracker =
87-
set_diff(m_rels_pending_tracker, m_changed_relations);
72+
m_rels_pending_tracker.remove_ids_if_in(m_changed_relations);
8873

8974
m_changed_relations.clear();
9075
}

src/idlist.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ void idlist_t::merge_sorted(idlist_t const &other)
3131
using std::swap;
3232
swap(new_list, m_list);
3333
}
34+
35+
void idlist_t::remove_ids_if_in(idlist_t const &other)
36+
{
37+
std::vector<osmid_t> new_list;
38+
39+
new_list.reserve(m_list.size());
40+
std::set_difference(m_list.cbegin(), m_list.cend(), other.m_list.cbegin(),
41+
other.m_list.cend(), std::back_inserter(new_list));
42+
43+
using std::swap;
44+
swap(new_list, m_list);
45+
}

src/idlist.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ class idlist_t
7777

7878
void merge_sorted(idlist_t const &other);
7979

80+
/**
81+
* Remove all ids in this list that are also in the other list. Both
82+
* lists must be sorted.
83+
*/
84+
void remove_ids_if_in(idlist_t const &other);
85+
8086
private:
8187
std::vector<osmid_t> m_list;
8288

0 commit comments

Comments
 (0)