44#include < cstddef>
55#include < cstdint>
66#include < map>
7+ #include < mutex>
78#include < unordered_map>
89#include < vector>
910
1213template <std::size_t N>
1314class GeoMap {
1415public:
15- GeoMap () noexcept = default ;
16- ~GeoMap () noexcept = default ;
16+ constexpr GeoMap () noexcept = default;
17+ constexpr ~GeoMap () noexcept = default ;
1718
18- void resize (std::size_t hash, std::size_t idx, std::size_t num, std::uint32_t mode) noexcept {
19+ constexpr void resize (std::size_t hash, std::size_t idx, std::size_t num, std::uint32_t mode) noexcept {
1920 if (mode == 0u ) {
2021 clear (hash);
2122 return ;
@@ -42,7 +43,7 @@ class GeoMap {
4243 return ;
4344 }
4445
45- void write (std::size_t hash, std::size_t idx, std::size_t pos, const Geo &geo) noexcept {
46+ constexpr void write (std::size_t hash, std::size_t idx, std::size_t pos, const Geo &geo) noexcept {
4647 const auto [id, offset] = calc_block_pos (pos);
4748
4849 auto it_hash = map.find (hash);
@@ -58,7 +59,7 @@ class GeoMap {
5859 return ;
5960 }
6061
61- [[nodiscard]] Geo *read (std::size_t hash, std::size_t idx, std::size_t pos) noexcept {
62+ [[nodiscard]] constexpr const Geo *read (std::size_t hash, std::size_t idx, std::size_t pos) const noexcept {
6263 const auto [id, offset] = calc_block_pos (pos);
6364
6465 if (auto block = get_block (hash, idx, id); block && (*block)[offset].get_flag ())
@@ -67,8 +68,9 @@ class GeoMap {
6768 return nullptr ;
6869 }
6970
70- void clear () noexcept { MapData{}.swap (map); }
71- void clear (std::size_t hash) noexcept {
71+ constexpr void clear () noexcept { MapData{}.swap (map); }
72+
73+ constexpr void clear (std::size_t hash) noexcept {
7274 auto it_hash = map.find (hash);
7375 if (it_hash == map.end ())
7476 return ;
@@ -80,13 +82,16 @@ class GeoMap {
8082 }
8183
8284private:
83- using BlockMap = std::map<std::size_t , std::array<Geo, N>>;
85+ using Block = std::array<Geo, N>;
86+ using BlockMap = std::map<std::size_t , Block>;
8487 using MapData = std::unordered_map<std::size_t , std::vector<BlockMap>>;
8588 MapData map{};
8689
87- std::array<std::size_t , 2 > calc_block_pos (std::size_t v) const { return {v / N, v % N}; }
90+ [[nodiscard]] constexpr std::array<std::size_t , 2 > calc_block_pos (std::size_t v) const noexcept {
91+ return {v / N, v % N};
92+ }
8893
89- std::array<Geo, N> *get_block (std::size_t hash, std::size_t idx, std::size_t id) {
94+ [[nodiscard]] constexpr const Block *get_block (std::size_t hash, std::size_t idx, std::size_t id) const noexcept {
9095 auto it_hash = map.find (hash);
9196 if (it_hash == map.end ())
9297 return nullptr ;
0 commit comments