-
-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy pathidlist.cpp
More file actions
54 lines (44 loc) · 1.3 KB
/
idlist.cpp
File metadata and controls
54 lines (44 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2026 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include "idlist.hpp"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <utility>
osmid_t idlist_t::pop_id()
{
assert(!m_list.empty());
auto const id = m_list.back();
m_list.pop_back();
return id;
}
void idlist_t::sort_unique()
{
std::sort(m_list.begin(), m_list.end());
auto const last = std::unique(m_list.begin(), m_list.end());
m_list.erase(last, m_list.end());
}
void idlist_t::merge_sorted(idlist_t const &other)
{
std::vector<osmid_t> new_list;
new_list.reserve(m_list.size() + other.m_list.size());
std::set_union(m_list.cbegin(), m_list.cend(), other.m_list.cbegin(),
other.m_list.cend(), std::back_inserter(new_list));
using std::swap;
swap(new_list, m_list);
}
void idlist_t::remove_ids_if_in(idlist_t const &other)
{
std::vector<osmid_t> new_list;
new_list.reserve(m_list.size());
std::set_difference(m_list.cbegin(), m_list.cend(), other.m_list.cbegin(),
other.m_list.cend(), std::back_inserter(new_list));
using std::swap;
swap(new_list, m_list);
}