Skip to content

Commit c3d5909

Browse files
committed
Documentation and various code cleanups
1 parent 232e316 commit c3d5909

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

src/idlist.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@
1010
#include "idlist.hpp"
1111

1212
#include <algorithm>
13+
#include <cassert>
1314
#include <iterator>
1415
#include <utility>
1516

17+
osmid_t idlist_t::pop_id()
18+
{
19+
assert(!m_list.empty());
20+
auto const id = m_list.back();
21+
m_list.pop_back();
22+
return id;
23+
}
24+
1625
void idlist_t::sort_unique()
1726
{
1827
std::sort(m_list.begin(), m_list.end());

src/idlist.hpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818

1919
#include "osmtypes.hpp"
2020

21-
#include <cassert>
2221
#include <vector>
2322

23+
/**
24+
* A list of OSM object ids. Internally this is a vector of ids.
25+
*
26+
* Some operations are only allowed when the list of ids is sorted and
27+
* without duplicates. Call sort_unique() to achieve this.
28+
*/
2429
class idlist_t
2530
{
2631
public:
@@ -51,20 +56,20 @@ class idlist_t
5156

5257
osmid_t operator[](std::size_t n) const noexcept { return m_list[n]; }
5358

54-
void clear() { m_list.clear(); }
59+
void clear() noexcept { m_list.clear(); }
5560

5661
void push_back(osmid_t id) { m_list.push_back(id); }
5762

5863
void reserve(std::size_t size) { m_list.reserve(size); }
5964

60-
osmid_t pop_id()
61-
{
62-
assert(!m_list.empty());
63-
auto const id = m_list.back();
64-
m_list.pop_back();
65-
return id;
66-
}
65+
/**
66+
* Remove id at the end of the list and return it.
67+
*
68+
* \pre \code !m_list.empty()) \endcode
69+
*/
70+
osmid_t pop_id();
6771

72+
/// List are equal if they contain the same ids in the same order.
6873
friend bool operator==(idlist_t const &lhs, idlist_t const &rhs) noexcept
6974
{
7075
return lhs.m_list == rhs.m_list;
@@ -75,13 +80,22 @@ class idlist_t
7580
return !(lhs == rhs);
7681
}
7782

83+
/**
84+
* Sort this list and remove duplicates.
85+
*/
7886
void sort_unique();
7987

88+
/**
89+
* Merge other list into this one.
90+
*
91+
* \pre Both lists must be sorted and without duplicates.
92+
*/
8093
void merge_sorted(idlist_t const &other);
8194

8295
/**
83-
* Remove all ids in this list that are also in the other list. Both
84-
* lists must be sorted.
96+
* Remove all ids in this list that are also in the other list.
97+
*
98+
* \pre Both lists must be sorted and without duplicates.
8599
*/
86100
void remove_ids_if_in(idlist_t const &other);
87101

src/middle.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
#include <memory>
1717

18-
#include "idlist.hpp"
1918
#include "osmtypes.hpp"
2019
#include "thread-pool.hpp"
2120

21+
class idlist_t;
22+
2223
struct options_t;
2324
struct output_requirements;
2425

src/pgsql-helper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
#include <cassert>
1515

1616
idlist_t get_ids_from_result(pg_result_t const &result) {
17-
idlist_t ids;
1817
assert(result.num_tuples() >= 0);
18+
19+
idlist_t ids;
1920
ids.reserve(static_cast<std::size_t>(result.num_tuples()));
2021

2122
for (int i = 0; i < result.num_tuples(); ++i) {

0 commit comments

Comments
 (0)