1 #ifndef OSMIUM_INDEX_MAP_SPARSE_MEM_MAP_HPP
2 #define OSMIUM_INDEX_MAP_SPARSE_MEM_MAP_HPP
45 #include <osmium/io/detail/read_write.hpp>
47 #define OSMIUM_HAS_INDEX_MAP_SPARSE_MEM_MAP
59 template <
typename TId,
typename TValue>
66 static constexpr
size_t element_size =
sizeof(TId) +
sizeof(TValue) +
sizeof(
void*) * 4;
76 void set(const TId
id, const TValue value) final {
77 m_elements[id] = value;
80 const TValue
get(
const TId id)
const final {
81 auto it = m_elements.find(
id);
82 if (it == m_elements.end()) {
88 size_t size() const noexcept final {
89 return m_elements.size();
93 return element_size * m_elements.size();
101 typedef typename std::map<TId, TValue>::value_type t;
103 v.reserve(m_elements.size());
104 std::copy(m_elements.cbegin(), m_elements.cend(), std::back_inserter(v));
105 osmium::io::detail::reliable_write(fd, reinterpret_cast<const char*>(v.data()),
sizeof(t) * v.size());
116 #endif // OSMIUM_INDEX_MAP_SPARSE_MEM_MAP_HPP
Definition: sparse_mem_map.hpp:60
static constexpr size_t element_size
Definition: sparse_mem_map.hpp:66
~SparseMemMap() noexcept final=default
size_t size() const noexcept final
Definition: sparse_mem_map.hpp:88
void set(const TId id, const TValue value) final
Set the field with id to value.
Definition: sparse_mem_map.hpp:76
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
OSMIUM_NORETURN void not_found_error(TKey key)
Definition: index.hpp:68
void clear() final
Definition: sparse_mem_map.hpp:96
size_t used_memory() const noexcept final
Definition: sparse_mem_map.hpp:92
void dump_as_list(const int fd) final
Definition: sparse_mem_map.hpp:100
std::map< TId, TValue > m_elements
Definition: sparse_mem_map.hpp:68