1 #ifndef OSMIUM_INDEX_RELATIONS_MAP_HPP 2 #define OSMIUM_INDEX_RELATIONS_MAP_HPP 51 template <
typename TKey,
typename TKeyInternal,
typename TValue,
typename TValueInternal>
56 using key_type = TKey;
57 using value_type = TValue;
65 explicit kv_pair(key_type key_id) :
66 key(static_cast<TKeyInternal>(key_id)),
70 kv_pair(key_type key_id, value_type value_id) :
71 key(static_cast<TKeyInternal>(key_id)),
72 value(static_cast<TValueInternal>(value_id)) {
75 bool operator<(
const kv_pair& other)
const noexcept {
76 return std::tie(key, value) < std::tie(other.key, other.value);
79 bool operator==(
const kv_pair& other)
const noexcept {
80 return std::tie(key, value) == std::tie(other.key, other.value);
84 std::vector<kv_pair> m_map;
88 using const_iterator =
typename std::vector<kv_pair>::const_iterator;
90 void set(key_type key, value_type value) {
91 m_map.emplace_back(key, value);
95 std::sort(m_map.begin(), m_map.end());
96 const auto last = std::unique(m_map.begin(), m_map.end());
97 m_map.erase(last, m_map.end());
100 std::pair<const_iterator, const_iterator>
get(key_type key)
const noexcept {
101 return std::equal_range(m_map.begin(), m_map.end(), kv_pair{key}, [](
const kv_pair& lhs,
const kv_pair& rhs) {
102 return lhs.key < rhs.key;
106 bool empty() const noexcept {
107 return m_map.empty();
110 size_t size() const noexcept {
151 m_map(
std::move(map)) {
178 template <
typename Func>
180 const auto parents = m_map.get(member_id);
181 for (
auto it = parents.first; it != parents.second; ++it) {
182 std::forward<Func>(func)(it->value);
192 return m_map.empty();
235 void add(osmium::unsigned_object_id_type member_id, osmium::unsigned_object_id_type relation_id) {
236 assert(m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
237 m_map.set(member_id, relation_id);
244 assert(m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
245 for (
const auto& member : relation.
members()) {
247 m_map.set(member.positive_ref(), relation.
positive_id());
258 assert(m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
259 return m_map.empty();
268 assert(m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
278 assert(m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
292 #endif // OSMIUM_INDEX_RELATIONS_MAP_HPP RelationMemberList & members()
Definition: relation.hpp:185
constexpr bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:221
Definition: relation.hpp:168
RelationsMapIndex build_index()
Definition: relations_map.hpp:277
uint64_t unsigned_object_id_type
Type for OSM object (node, way, or relation) IDs where we only allow positive IDs.
Definition: types.hpp:46
Definition: reader_iterator.hpp:39
Definition: relations_map.hpp:141
size_t size() const noexcept
Definition: relations_map.hpp:267
bool empty() const noexcept
Definition: relations_map.hpp:191
detail::flat_map< osmium::unsigned_object_id_type, uint32_t, osmium::unsigned_object_id_type, uint32_t > map_type
Definition: relations_map.hpp:146
RelationsMapIndex(map_type &&map)
Definition: relations_map.hpp:150
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:447
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
void add(osmium::unsigned_object_id_type member_id, osmium::unsigned_object_id_type relation_id)
Definition: relations_map.hpp:235
Definition: relations_map.hpp:211
map_type m_map
Definition: relations_map.hpp:148
void add_members(const osmium::Relation &relation)
Definition: relations_map.hpp:243
void for_each_parent(osmium::unsigned_object_id_type member_id, Func &&func) const
Definition: relations_map.hpp:179
detail::flat_map< osmium::unsigned_object_id_type, uint32_t, osmium::unsigned_object_id_type, uint32_t > map_type
Definition: relations_map.hpp:214
map_type m_map
Definition: relations_map.hpp:216
size_t size() const noexcept
Definition: relations_map.hpp:200
unsigned_object_id_type positive_id() const noexcept
Get absolute value of the ID of this object.
Definition: object.hpp:131
bool empty() const noexcept
Definition: relations_map.hpp:257