diff --git a/main.cpp b/main.cpp index 038495e0..d4738acd 100644 --- a/main.cpp +++ b/main.cpp @@ -479,10 +479,10 @@ void do_read_parallel(char *map, long long len, long long initial_offset, const sst.resize(CPUS); pthread_t pthreads[CPUS]; - std::vector > file_subkeys; + std::vector > file_subkeys; for (size_t i = 0; i < CPUS; i++) { - file_subkeys.push_back(std::set()); + file_subkeys.push_back(std::set()); } for (size_t i = 0; i < CPUS; i++) { diff --git a/mbtiles.cpp b/mbtiles.cpp index 5af9168c..f56ea043 100644 --- a/mbtiles.cpp +++ b/mbtiles.cpp @@ -196,21 +196,21 @@ void mbtiles_erase_zoom(sqlite3 *outdb, int z) { } } -bool type_and_string::operator<(const type_and_string &o) const { - if (string < o.string) { +bool serial_val::operator<(const serial_val &o) const { + if (s < o.s) { return true; } - if (string == o.string && type < o.type) { + if (s == o.s && type < o.type) { return true; } return false; } -bool type_and_string::operator!=(const type_and_string &o) const { +bool serial_val::operator!=(const serial_val &o) const { if (type != o.type) { return true; } - if (string != o.string) { + if (s != o.s) { return true; } return false; @@ -338,15 +338,15 @@ void tilestats(std::map const &layermap1, size_t el vals++; state.nospace = true; - state.json_write_stringified(value.string); + state.json_write_stringified(value.s); } else { - std::string trunc = truncate16(value.string, 256); + std::string trunc = truncate16(value.s, 256); - if (trunc.size() == value.string.size()) { + if (trunc.size() == value.s.size()) { vals++; state.nospace = true; - state.json_write_string(value.string); + state.json_write_string(value.s); } } } @@ -861,7 +861,7 @@ std::map merge_layermaps(std::vectorsecond.file_keys.find(attribname); if (fk2 == out_entry->second.file_keys.end()) { - out_entry->second.file_keys.insert(std::pair(attribname, fk->second)); + out_entry->second.file_keys.insert(std::pair(attribname, fk->second)); } else { for (auto val : fk->second.sample_values) { auto pt = std::lower_bound(fk2->second.sample_values.begin(), fk2->second.sample_values.end(), val); @@ -901,14 +901,14 @@ std::map merge_layermaps(std::vector &file_keys, std::string const &attrib, type_and_string const &val) { +void add_to_file_keys(std::map &file_keys, std::string const &attrib, serial_val const &val) { if (val.type == mvt_null) { return; } auto fka = file_keys.find(attrib); if (fka == file_keys.end()) { - file_keys.insert(std::pair(attrib, type_and_string_stats())); + file_keys.insert(std::pair(attrib, tilestat())); fka = file_keys.find(attrib); } @@ -918,7 +918,7 @@ void add_to_file_keys(std::map &file_keys, s } if (val.type == mvt_double) { - double d = atof(val.string.c_str()); + double d = atof(val.s.c_str()); if (d < fka->second.min) { fka->second.min = d; diff --git a/mbtiles.hpp b/mbtiles.hpp index 956b0550..52c19517 100644 --- a/mbtiles.hpp +++ b/mbtiles.hpp @@ -9,16 +9,8 @@ extern size_t max_tilestats_attributes; extern size_t max_tilestats_sample_values; extern size_t max_tilestats_values; -struct type_and_string { - int type = 0; - std::string string = ""; - - bool operator<(const type_and_string &o) const; - bool operator!=(const type_and_string &o) const; -}; - -struct type_and_string_stats { - std::vector sample_values = std::vector(); // sorted +struct tilestat { + std::vector sample_values = std::vector(); // sorted double min = INFINITY; double max = -INFINITY; int type = 0; @@ -26,7 +18,7 @@ struct type_and_string_stats { struct layermap_entry { size_t id = 0; - std::map file_keys{}; + std::map file_keys{}; int minzoom = 0; int maxzoom = 0; std::string description = ""; @@ -84,7 +76,7 @@ void mbtiles_close(sqlite3 *outdb, const char *pgm); std::map merge_layermaps(std::vector > const &maps); std::map merge_layermaps(std::vector > const &maps, bool trunc); -void add_to_file_keys(std::map &file_keys, std::string const &layername, type_and_string const &val); +void add_to_file_keys(std::map &file_keys, std::string const &layername, serial_val const &val); unsigned long long fnv1a(std::string const &s); diff --git a/plugin.cpp b/plugin.cpp index 33407eb9..30ee0fdb 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -274,9 +274,9 @@ std::vector parse_layers(int fd, int z, unsigned x, unsigned y, std:: mvt_value v = stringified_to_mvt_value(tp, s.c_str()); l->second.tag(feature, std::string(properties->value.object.keys[i]->value.string.string), v); - type_and_string attrib; + serial_val attrib; attrib.type = tp; - attrib.string = s; + attrib.s = s; add_to_file_keys(fk->second.file_keys, std::string(properties->value.object.keys[i]->value.string.string), attrib); } @@ -515,8 +515,8 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std:: sf.full_keys.push_back(std::string(properties->value.object.keys[i]->value.string.string)); sf.full_values.push_back(v); - type_and_string attrib; - attrib.string = v.s; + serial_val attrib; + attrib.s = v.s; attrib.type = v.type; if (!postfilter) { diff --git a/serial.cpp b/serial.cpp index 5a9d7ae5..7317a851 100644 --- a/serial.cpp +++ b/serial.cpp @@ -827,12 +827,8 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) { if (!sst->filters) { for (size_t i = 0; i < sf.full_keys.size(); i++) { - type_and_string attrib; - attrib.type = sf.full_values[i].type; - attrib.string = sf.full_values[i].s; - auto fk = sst->layermap->find(sf.layername); - add_to_file_keys(fk->second.file_keys, sf.full_keys[i], attrib); + add_to_file_keys(fk->second.file_keys, sf.full_keys[i], sf.full_values[i]); } } diff --git a/serial.hpp b/serial.hpp index 9467cd07..05e6d4ea 100644 --- a/serial.hpp +++ b/serial.hpp @@ -38,6 +38,9 @@ void deserialize_byte(char **f, signed char *n); struct serial_val { int type = 0; std::string s = ""; + + bool operator<(const serial_val &o) const; + bool operator!=(const serial_val &o) const; }; struct serial_feature { diff --git a/tile-join.cpp b/tile-join.cpp index 18652271..32ed5a52 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -167,7 +167,7 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map> attributes; + std::map> attributes; std::vector key_order; for (size_t t = 0; t + 1 < feat.tags.size(); t += 2) { @@ -206,11 +206,11 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map>(key, std::pair(val, tas))); + attributes.insert(std::pair>(key, std::pair(val, tas))); key_order.push_back(key); } @@ -253,14 +253,14 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map>(joinkey, std::pair(outval, tas))); + attributes.insert(std::pair>(joinkey, std::pair(outval, tas))); key_order.push_back(joinkey); } } diff --git a/tile.cpp b/tile.cpp index bdd9df56..5b9f8ef2 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1822,11 +1822,7 @@ void add_tilestats(std::string const &layername, int z, std::vectorsecond.file_keys, key, attrib); + add_to_file_keys(fk->second.file_keys, key, val); } void preserve_attribute(attribute_op op, serial_feature &, char *stringpool, long long *pool_off, std::string &key, serial_val &val, partial &p) {