diff --git a/mvt.cpp b/mvt.cpp index 16481015..f00a1718 100644 --- a/mvt.cpp +++ b/mvt.cpp @@ -15,6 +15,7 @@ #include "milo/dtoa_milo.h" #include "errors.hpp" #include "serial.hpp" +#include "text.hpp" mvt_geometry::mvt_geometry(int nop, long long nx, long long ny) { this->op = nop; @@ -592,41 +593,25 @@ std::string mvt_value::toString() const { } void mvt_layer::tag(mvt_feature &feature, std::string const &key, mvt_value const &value) { - size_t ko, vo; - - // initialize lazily the first time anyone tags an attribute - // to save the time of doing it in decode, which never actually matters. - // only tile writers actually need this. - if (key_map.size() == 0) { - for (size_t i = 0; i < keys.size(); i++) { - key_map.emplace(keys[i], i); - } - for (size_t i = 0; i < values.size(); i++) { - value_map.emplace(values[i], i); - } - } - - std::unordered_map::iterator ki = key_map.find(key); - std::unordered_map::iterator vi = value_map.find(value); - - if (ki == key_map.end()) { - ko = keys.size(); + size_t key_hash = std::hash()(key) % dedup.size(); + if (dedup[key_hash] >= 0 && + dedup[key_hash] < (ssize_t) keys.size() && + keys[dedup[key_hash]] == key) { + } else { + dedup[key_hash] = keys.size(); keys.push_back(key); - key_map.emplace(key, ko); - } else { - ko = ki->second; } + feature.tags.push_back(dedup[key_hash]); - if (vi == value_map.end()) { - vo = values.size(); + size_t value_hash = std::hash()(value) % dedup.size(); + if (dedup[value_hash] >= 0 && + dedup[value_hash] < (ssize_t) values.size() && + values[dedup[value_hash]] == value) { + } else { + dedup[value_hash] = values.size(); values.push_back(value); - value_map.emplace(value, vo); - } else { - vo = vi->second; } - - feature.tags.push_back(ko); - feature.tags.push_back(vo); + feature.tags.push_back(dedup[value_hash]); } bool is_integer(const char *s, long long *v) { diff --git a/mvt.hpp b/mvt.hpp index ba0d5d57..cc33f7b3 100644 --- a/mvt.hpp +++ b/mvt.hpp @@ -174,8 +174,7 @@ struct mvt_layer { void tag(mvt_feature &feature, std::string const &key, mvt_value const &value); // For tracking the key-value constants already used in this layer - std::unordered_map key_map{}; - std::unordered_map value_map{}; + std::vector dedup = std::vector(65536, -1); }; struct mvt_tile {