1#ifndef OSMIUM_INDEX_RELATIONS_MAP_HPP
2#define OSMIUM_INDEX_RELATIONS_MAP_HPP
55 template <
typename TKey,
typename TKeyInternal,
typename TValue,
typename TValueInternal>
60 using key_type = TKey;
61 using value_type = TValue;
69 explicit kv_pair(
const key_type key_id) :
70 key(static_cast<TKeyInternal>(key_id)),
74 kv_pair(
const key_type key_id,
const value_type value_id) :
75 key(static_cast<TKeyInternal>(key_id)),
76 value(static_cast<TValueInternal>(value_id)) {
79 bool operator<(
const kv_pair& other)
const noexcept {
80 return std::tie(key, value) < std::tie(other.key, other.value);
83 bool operator==(
const kv_pair& other)
const noexcept {
84 return std::tie(key, value) == std::tie(other.key, other.value);
88 std::vector<kv_pair> m_map;
92 using const_iterator =
typename std::vector<kv_pair>::const_iterator;
94 void set(
const key_type key,
const value_type value) {
95 m_map.emplace_back(key, value);
98 typename std::enable_if<std::is_same<TKey, TValue>::value>
::type flip_in_place() {
99 for (
auto& p : m_map) {
101 swap(p.key, p.value);
105 flat_map<TValue, TValueInternal, TKey, TKeyInternal> flip_copy() {
106 flat_map<TValue, TValueInternal, TKey, TKeyInternal> map;
107 map.reserve(m_map.size());
109 for (
const auto& p : m_map) {
110 map.set(p.value, p.key);
117 std::sort(m_map.begin(), m_map.end());
118 const auto last = std::unique(m_map.begin(), m_map.end());
119 m_map.erase(last, m_map.end());
122 std::pair<const_iterator, const_iterator> get(
const key_type key)
const noexcept {
123 return std::equal_range(m_map.begin(), m_map.end(), kv_pair{key}, [](
const kv_pair& lhs,
const kv_pair& rhs) {
124 return lhs.key < rhs.key;
128 bool empty() const noexcept {
129 return m_map.empty();
132 std::size_t size() const noexcept {
136 void reserve(
const std::size_t size) {
211 template <typename TFunc>
213 const auto parents =
m_map.get(member_id);
214 for (
auto it = parents.first; it != parents.second; ++it) {
233 template <
typename TFunc>
235 const auto parents =
m_map.get(
id);
236 for (
auto it = parents.first; it != parents.second; ++it) {
247 return m_map.empty();
255 std::size_t
size() const noexcept {
264 inline RelationsMapIndex& RelationsMapIndex::operator=(RelationsMapIndex&&) noexcept(
std::is_nothrow_move_assignable<map_type>::value) = default;
274 m_member_to_parent(
std::move(map1)),
275 m_parent_to_member(
std::move(map2)) {
281 return m_member_to_parent;
285 return m_parent_to_member;
294 return m_member_to_parent.
empty();
302 std::size_t
size() const noexcept {
303 return m_member_to_parent.
size();
340 assert(
m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
341 m_map.set(member_id, relation_id);
348 assert(
m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
349 for (
const auto& member : relation.members()) {
351 m_map.set(member.positive_ref(), relation.positive_id());
362 assert(
m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
363 return m_map.empty();
371 std::size_t
size() const noexcept {
372 assert(
m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
385 assert(
m_valid &&
"You can't use the RelationsMap any more after calling build_index()");
400 assert(
m_valid &&
"You can't use the RelationsMap any more after calling build_member_to_parent_index()");
415 assert(
m_valid &&
"You can't use the RelationsMap any more after calling build_parent_to_member_index()");
416 m_map.flip_in_place();
431 assert(
m_valid &&
"You can't use the RelationsMap any more after calling build_indexes()");
432 auto reverse_map =
m_map.flip_copy();
433 reverse_map.sort_unique();
446 inline RelationsMapStash& RelationsMapStash::operator=(RelationsMapStash&&) noexcept(
std::is_nothrow_move_assignable<map_type>::value) = default;
Definition: relation.hpp:161
Definition: relations_map.hpp:169
RelationsMapIndex(const RelationsMapIndex &)=delete
std::size_t size() const noexcept
Definition: relations_map.hpp:255
void for_each(const osmium::unsigned_object_id_type id, TFunc &&func) const
Definition: relations_map.hpp:234
RelationsMapIndex(RelationsMapIndex &&) noexcept(std::is_nothrow_move_constructible< map_type >::value)
detail::flat_map< osmium::unsigned_object_id_type, uint32_t, osmium::unsigned_object_id_type, uint32_t > map_type
Definition: relations_map.hpp:175
map_type m_map
Definition: relations_map.hpp:177
RelationsMapIndex(map_type &&map)
Definition: relations_map.hpp:179
RelationsMapIndex()=delete
RelationsMapIndex & operator=(const RelationsMapIndex &)=delete
bool empty() const noexcept
Definition: relations_map.hpp:246
void for_each_parent(const osmium::unsigned_object_id_type member_id, TFunc &&func) const
Definition: relations_map.hpp:212
Definition: relations_map.hpp:266
const RelationsMapIndex & parent_to_member() const noexcept
Definition: relations_map.hpp:284
const RelationsMapIndex & member_to_parent() const noexcept
Definition: relations_map.hpp:280
std::size_t size() const noexcept
Definition: relations_map.hpp:302
bool empty() const noexcept
Definition: relations_map.hpp:293
RelationsMapIndex m_member_to_parent
Definition: relations_map.hpp:270
RelationsMapIndexes(RelationsMapIndex::map_type &&map1, RelationsMapIndex::map_type &&map2)
Definition: relations_map.hpp:273
RelationsMapIndex m_parent_to_member
Definition: relations_map.hpp:271
Definition: relations_map.hpp:313
RelationsMapIndex build_member_to_parent_index()
Definition: relations_map.hpp:399
RelationsMapStash(RelationsMapStash &&) noexcept(std::is_nothrow_move_constructible< map_type >::value)
bool m_valid
Definition: relations_map.hpp:321
detail::flat_map< osmium::unsigned_object_id_type, uint32_t, osmium::unsigned_object_id_type, uint32_t > map_type
Definition: relations_map.hpp:316
std::size_t size() const noexcept
Definition: relations_map.hpp:371
RelationsMapIndexes build_indexes()
Definition: relations_map.hpp:430
RelationsMapIndex build_parent_to_member_index()
Definition: relations_map.hpp:414
void add_members(const osmium::Relation &relation)
Definition: relations_map.hpp:347
RelationsMapStash & operator=(const RelationsMapStash &)=delete
map_type m_map
Definition: relations_map.hpp:318
bool empty() const noexcept
Definition: relations_map.hpp:361
RelationsMapStash(const RelationsMapStash &)=delete
void add(const osmium::unsigned_object_id_type member_id, const osmium::unsigned_object_id_type relation_id)
Definition: relations_map.hpp:339
RelationsMapStash()=default
RelationsMapIndex build_index()
Definition: relations_map.hpp:384
type
Definition: entity_bits.hpp:63
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
bool operator==(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:440
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
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:451
Definition: location.hpp:555