1 #ifndef OSMIUM_INDEX_MAP_SPARSE_MEM_MAP_HPP
2 #define OSMIUM_INDEX_MAP_SPARSE_MEM_MAP_HPP
44 #include <osmium/io/detail/read_write.hpp>
46 #define OSMIUM_HAS_INDEX_MAP_SPARSE_MEM_MAP
58 template <
typename TId,
typename TValue>
65 static constexpr
size_t element_size =
sizeof(TId) +
sizeof(TValue) +
sizeof(
void*) * 4;
75 void set(const TId
id, const TValue value) final {
76 m_elements[id] = value;
79 const TValue
get(
const TId id)
const final {
80 auto it = m_elements.find(
id);
81 if (it == m_elements.end()) {
87 size_t size() const noexcept final {
88 return m_elements.size();
92 return element_size * m_elements.size();
100 using t =
typename std::map<TId, TValue>::value_type;
102 v.reserve(m_elements.size());
103 std::copy(m_elements.cbegin(), m_elements.cend(), std::back_inserter(v));
104 osmium::io::detail::reliable_write(fd, reinterpret_cast<const char*>(v.data()),
sizeof(t) * v.size());
115 #endif // OSMIUM_INDEX_MAP_SPARSE_MEM_MAP_HPP
Definition: sparse_mem_map.hpp:59
static constexpr size_t element_size
Definition: sparse_mem_map.hpp:65
void set(const TId id, const TValue value) final
Set the field with id to value.
Definition: sparse_mem_map.hpp:75
size_t used_memory() const noexceptfinal
Definition: sparse_mem_map.hpp:91
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
void clear() final
Definition: sparse_mem_map.hpp:95
size_t size() const noexceptfinal
Definition: sparse_mem_map.hpp:87
~SparseMemMap() noexceptfinal=default
void dump_as_list(const int fd) final
Definition: sparse_mem_map.hpp:99
std::map< TId, TValue > m_elements
Definition: sparse_mem_map.hpp:67