mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-03 08:55:41 +02:00
Get rid of the type_and_string near-synonym for serial_val
This commit is contained in:
@@ -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<std::set<type_and_string> > file_subkeys;
|
||||
std::vector<std::set<serial_val> > file_subkeys;
|
||||
|
||||
for (size_t i = 0; i < CPUS; i++) {
|
||||
file_subkeys.push_back(std::set<type_and_string>());
|
||||
file_subkeys.push_back(std::set<serial_val>());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < CPUS; i++) {
|
||||
|
||||
+13
-13
@@ -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<std::string, layermap_entry> 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<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::
|
||||
auto fk2 = out_entry->second.file_keys.find(attribname);
|
||||
|
||||
if (fk2 == out_entry->second.file_keys.end()) {
|
||||
out_entry->second.file_keys.insert(std::pair<std::string, type_and_string_stats>(attribname, fk->second));
|
||||
out_entry->second.file_keys.insert(std::pair<std::string, tilestat>(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<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::
|
||||
return out;
|
||||
}
|
||||
|
||||
void add_to_file_keys(std::map<std::string, type_and_string_stats> &file_keys, std::string const &attrib, type_and_string const &val) {
|
||||
void add_to_file_keys(std::map<std::string, tilestat> &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<std::string, type_and_string_stats>(attrib, type_and_string_stats()));
|
||||
file_keys.insert(std::pair<std::string, tilestat>(attrib, tilestat()));
|
||||
fka = file_keys.find(attrib);
|
||||
}
|
||||
|
||||
@@ -918,7 +918,7 @@ void add_to_file_keys(std::map<std::string, type_and_string_stats> &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;
|
||||
|
||||
+4
-12
@@ -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<type_and_string> sample_values = std::vector<type_and_string>(); // sorted
|
||||
struct tilestat {
|
||||
std::vector<serial_val> sample_values = std::vector<serial_val>(); // 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<std::string, type_and_string_stats> file_keys{};
|
||||
std::map<std::string, tilestat> 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<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps);
|
||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps, bool trunc);
|
||||
|
||||
void add_to_file_keys(std::map<std::string, type_and_string_stats> &file_keys, std::string const &layername, type_and_string const &val);
|
||||
void add_to_file_keys(std::map<std::string, tilestat> &file_keys, std::string const &layername, serial_val const &val);
|
||||
|
||||
unsigned long long fnv1a(std::string const &s);
|
||||
|
||||
|
||||
+4
-4
@@ -274,9 +274,9 @@ std::vector<mvt_layer> 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) {
|
||||
|
||||
+1
-5
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+7
-7
@@ -167,7 +167,7 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<st
|
||||
outfeature.id = feat.id;
|
||||
}
|
||||
|
||||
std::map<std::string, std::pair<mvt_value, type_and_string>> attributes;
|
||||
std::map<std::string, std::pair<mvt_value, serial_val>> attributes;
|
||||
std::vector<std::string> 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<st
|
||||
}
|
||||
|
||||
if (include.count(std::string(key)) || (!exclude_all && exclude.count(std::string(key)) == 0 && exclude_attributes.count(std::string(key)) == 0)) {
|
||||
type_and_string tas;
|
||||
serial_val tas;
|
||||
tas.type = type;
|
||||
tas.string = value;
|
||||
tas.s = value;
|
||||
|
||||
attributes.insert(std::pair<std::string, std::pair<mvt_value, type_and_string>>(key, std::pair<mvt_value, type_and_string>(val, tas)));
|
||||
attributes.insert(std::pair<std::string, std::pair<mvt_value, serial_val>>(key, std::pair<mvt_value, serial_val>(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<st
|
||||
attributes.erase(fa);
|
||||
}
|
||||
|
||||
type_and_string tas;
|
||||
serial_val tas;
|
||||
tas.type = outval.type;
|
||||
tas.string = joinval;
|
||||
tas.s = joinval;
|
||||
|
||||
// Convert from double to int if the joined attribute is an integer
|
||||
outval = stringified_to_mvt_value(outval.type, joinval.c_str());
|
||||
|
||||
attributes.insert(std::pair<std::string, std::pair<mvt_value, type_and_string>>(joinkey, std::pair<mvt_value, type_and_string>(outval, tas)));
|
||||
attributes.insert(std::pair<std::string, std::pair<mvt_value, serial_val>>(joinkey, std::pair<mvt_value, serial_val>(outval, tas)));
|
||||
key_order.push_back(joinkey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1822,11 +1822,7 @@ void add_tilestats(std::string const &layername, int z, std::vector<std::map<std
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
type_and_string attrib;
|
||||
attrib.type = val.type;
|
||||
attrib.string = val.s;
|
||||
|
||||
add_to_file_keys(fk->second.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) {
|
||||
|
||||
Reference in New Issue
Block a user