From a30722caa5a1baeda92ed4d4a36a00a5b826a2cc Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Wed, 24 Jan 2024 12:41:01 -0800 Subject: [PATCH] More switches from maps to unordered_maps --- attribute.cpp | 8 ++++---- attribute.hpp | 8 ++++---- clip.cpp | 8 ++++---- evaluator.cpp | 8 ++++---- evaluator.hpp | 4 ++-- geometry.hpp | 4 ++-- main.cpp | 14 +++++++------- overzoom.cpp | 2 +- serial.cpp | 2 +- serial.hpp | 4 ++-- tile-join.cpp | 2 +- tile.cpp | 11 ++++++----- tile.hpp | 2 +- 13 files changed, 39 insertions(+), 38 deletions(-) diff --git a/attribute.cpp b/attribute.cpp index 1b12c960..b01104f1 100644 --- a/attribute.cpp +++ b/attribute.cpp @@ -1,12 +1,12 @@ #include -#include +#include #include "attribute.hpp" #include "errors.hpp" #include "serial.hpp" #include "jsonpull/jsonpull.h" #include "milo/dtoa_milo.h" -void set_attribute_accum(std::map &attribute_accum, std::string name, std::string type) { +void set_attribute_accum(std::unordered_map &attribute_accum, std::string name, std::string type) { attribute_op t; if (type == "sum") { @@ -31,7 +31,7 @@ void set_attribute_accum(std::map &attribute_accum, s attribute_accum.insert(std::pair(name, t)); } -void set_attribute_accum(std::map &attribute_accum, const char *arg, char **argv) { +void set_attribute_accum(std::unordered_map &attribute_accum, const char *arg, char **argv) { if (*arg == '{') { json_pull *jp = json_begin_string(arg); json_object *o = json_read_tree(jp); @@ -79,7 +79,7 @@ void set_attribute_accum(std::map &attribute_accum, c set_attribute_accum(attribute_accum, name, type); } -void preserve_attribute(attribute_op op, std::string &key, serial_val &val, std::vector &full_keys, std::vector &full_values, std::map &attribute_accum_state) { +void preserve_attribute(attribute_op op, std::string &key, serial_val &val, std::vector &full_keys, std::vector &full_values, std::unordered_map &attribute_accum_state) { for (size_t i = 0; i < full_keys.size(); i++) { if (key == full_keys[i]) { switch (op) { diff --git a/attribute.hpp b/attribute.hpp index c4d999e9..9d8ca41c 100644 --- a/attribute.hpp +++ b/attribute.hpp @@ -2,7 +2,7 @@ #define ATTRIBUTE_HPP #include -#include +#include enum attribute_op { op_sum, @@ -21,8 +21,8 @@ struct accum_state { struct serial_val; -void set_attribute_accum(std::map &attribute_accum, std::string name, std::string type); -void set_attribute_accum(std::map &attribute_accum, const char *arg, char **argv); -void preserve_attribute(attribute_op op, std::string &key, serial_val &val, std::vector &full_keys, std::vector &full_values, std::map &attribute_accum_state); +void set_attribute_accum(std::unordered_map &attribute_accum, std::string name, std::string type); +void set_attribute_accum(std::unordered_map &attribute_accum, const char *arg, char **argv); +void preserve_attribute(attribute_op op, std::string &key, serial_val &val, std::vector &full_keys, std::vector &full_values, std::unordered_map &attribute_accum_state); #endif diff --git a/clip.cpp b/clip.cpp index 67bcac6b..478a6b10 100644 --- a/clip.cpp +++ b/clip.cpp @@ -758,7 +758,7 @@ static std::vector> clip_poly1(std::vector const &keep, bool do_compress, std::vector> *next_overzoomed_tiles, - bool demultiply, json_object *filter, bool preserve_input_order, std::map const &attribute_accum) { + bool demultiply, json_object *filter, bool preserve_input_order, std::unordered_map const &attribute_accum) { mvt_tile tile; try { @@ -785,7 +785,7 @@ struct tile_feature { size_t seq = 0; }; -static void feature_out(std::vector const &features, mvt_layer &outlayer, std::set const &keep, std::map const &attribute_accum) { +static void feature_out(std::vector const &features, mvt_layer &outlayer, std::set const &keep, std::unordered_map const &attribute_accum) { // Add geometry to output feature mvt_feature outfeature; @@ -810,7 +810,7 @@ static void feature_out(std::vector const &features, mvt_layer &ou // attributes from the other features of the // multiplier cluster accumulated onto them - std::map attribute_accum_state; + std::unordered_map attribute_accum_state; std::vector full_keys; std::vector full_values; @@ -873,7 +873,7 @@ static struct preservecmp { std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int ny, int detail, int buffer, std::set const &keep, bool do_compress, std::vector> *next_overzoomed_tiles, - bool demultiply, json_object *filter, bool preserve_input_order, std::map const &attribute_accum) { + bool demultiply, json_object *filter, bool preserve_input_order, std::unordered_map const &attribute_accum) { mvt_tile outtile; for (auto const &layer : tile.layers) { diff --git a/evaluator.cpp b/evaluator.cpp index 040f43f5..f895a7db 100644 --- a/evaluator.cpp +++ b/evaluator.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include "mvt.hpp" #include "evaluator.hpp" #include "errors.hpp" @@ -217,7 +217,7 @@ int compare(mvt_value one, json_object *two, bool &fail) { // 0: false // 1: true // -1: incomparable (sql null), treated as false in final output -static int eval(std::map const &feature, json_object *f, std::set &exclude_attributes) { +static int eval(std::unordered_map const &feature, json_object *f, std::set &exclude_attributes) { if (f != NULL) { if (f->type == JSON_TRUE) { return 1; @@ -611,7 +611,7 @@ static int eval(std::map const &feature, json_object *f, exit(EXIT_FILTER); } -bool evaluate(std::map const &feature, std::string const &layer, json_object *filter, std::set &exclude_attributes) { +bool evaluate(std::unordered_map const &feature, std::string const &layer, json_object *filter, std::set &exclude_attributes) { if (filter == NULL || filter->type != JSON_HASH) { fprintf(stderr, "Error: filter is not a hash: %s\n", json_stringify(filter)); exit(EXIT_JSON); @@ -667,7 +667,7 @@ json_object *parse_filter(const char *s) { bool evaluate(mvt_feature const &feat, mvt_layer const &layer, json_object *filter, std::set &exclude_attributes, int z) { if (filter != NULL) { - std::map attributes; + std::unordered_map attributes; for (size_t t = 0; t + 1 < feat.tags.size(); t += 2) { std::string key = layer.keys[feat.tags[t]]; diff --git a/evaluator.hpp b/evaluator.hpp index d8cc9e8b..b64fb095 100644 --- a/evaluator.hpp +++ b/evaluator.hpp @@ -1,13 +1,13 @@ #ifndef EVALUATOR_HPP #define EVALUATOR HPP -#include +#include #include #include #include "jsonpull/jsonpull.h" #include "mvt.hpp" -bool evaluate(std::map const &feature, std::string const &layer, json_object *filter, std::set &exclude_attributes); +bool evaluate(std::unordered_map const &feature, std::string const &layer, json_object *filter, std::set &exclude_attributes); json_object *parse_filter(const char *s); json_object *read_filter(const char *fname); diff --git a/geometry.hpp b/geometry.hpp index c4fa4d85..d1006002 100644 --- a/geometry.hpp +++ b/geometry.hpp @@ -104,12 +104,12 @@ std::string overzoom(mvt_tile tile, int oz, int ox, int oy, int nz, int nx, int int detail, int buffer, std::set const &keep, bool do_compress, std::vector> *next_overzoomed_tiles, bool demultiply, json_object *filter, bool preserve_input_order, - std::map const &attribute_accum); + std::unordered_map const &attribute_accum); std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny, int detail, int buffer, std::set const &keep, bool do_compress, std::vector> *next_overzoomed_tiles, bool demultiply, json_object *filter, bool preserve_input_order, - std::map const &attribute_accum); + std::unordered_map const &attribute_accum); #endif diff --git a/main.cpp b/main.cpp index c0e72f60..3f065448 100644 --- a/main.cpp +++ b/main.cpp @@ -448,7 +448,7 @@ void *run_sort(void *v) { return NULL; } -void do_read_parallel(char *map, long long len, long long initial_offset, const char *reading, std::vector *readers, std::atomic *progress_seq, std::set *exclude, std::set *include, int exclude_all, int basezoom, int source, std::vector > *layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::map const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) { +void do_read_parallel(char *map, long long len, long long initial_offset, const char *reading, std::vector *readers, std::atomic *progress_seq, std::set *exclude, std::set *include, int exclude_all, int basezoom, int source, std::vector > *layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::unordered_map const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) { long long segs[CPUS + 1]; segs[0] = 0; segs[CPUS] = len; @@ -649,7 +649,7 @@ struct read_parallel_arg { unsigned *initial_y = NULL; std::string layername = ""; bool uses_gamma = false; - std::map const *attribute_types = NULL; + std::unordered_map const *attribute_types = NULL; double *dist_sum = NULL; size_t *dist_count = NULL; double *area_sum = NULL; @@ -693,7 +693,7 @@ void *run_read_parallel(void *v) { return NULL; } -void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::atomic *is_parsing, pthread_t *parallel_parser, bool &parser_created, const char *reading, std::vector *readers, std::atomic *progress_seq, std::set *exclude, std::set *include, int exclude_all, int basezoom, int source, std::vector > &layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::map const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) { +void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::atomic *is_parsing, pthread_t *parallel_parser, bool &parser_created, const char *reading, std::vector *readers, std::atomic *progress_seq, std::set *exclude, std::set *include, int exclude_all, int basezoom, int source, std::vector > &layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::unordered_map const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) { // This has to kick off an intermediate thread to start the parser threads, // so the main thread can get back to reading the next input stage while // the intermediate thread waits for the completion of the parser threads. @@ -1237,7 +1237,7 @@ int vertexcmp(const void *void1, const void *void2) { return 0; } -std::pair read_input(std::vector &sources, char *fname, int maxzoom, int minzoom, int basezoom, double basezoom_marker_width, sqlite3 *outdb, const char *outdir, std::set *exclude, std::set *include, int exclude_all, json_object *filter, double droprate, int buffer, const char *tmpdir, double gamma, int read_parallel, int forcetable, const char *attribution, bool uses_gamma, long long *file_bbox, long long *file_bbox1, long long *file_bbox2, const char *prefilter, const char *postfilter, const char *description, bool guess_maxzoom, bool guess_cluster_maxzoom, std::map const *attribute_types, const char *pgm, std::map const *attribute_accum, std::map const &attribute_descriptions, std::string const &commandline, int minimum_maxzoom) { +std::pair read_input(std::vector &sources, char *fname, int maxzoom, int minzoom, int basezoom, double basezoom_marker_width, sqlite3 *outdb, const char *outdir, std::set *exclude, std::set *include, int exclude_all, json_object *filter, double droprate, int buffer, const char *tmpdir, double gamma, int read_parallel, int forcetable, const char *attribution, bool uses_gamma, long long *file_bbox, long long *file_bbox1, long long *file_bbox2, const char *prefilter, const char *postfilter, const char *description, bool guess_maxzoom, bool guess_cluster_maxzoom, std::unordered_map const *attribute_types, const char *pgm, std::unordered_map const *attribute_accum, std::map const &attribute_descriptions, std::string const &commandline, int minimum_maxzoom) { int ret = EXIT_SUCCESS; std::vector readers; @@ -2845,7 +2845,7 @@ static bool has_name(struct option *long_options, int *pl) { return false; } -void set_attribute_type(std::map &attribute_types, const char *arg) { +void set_attribute_type(std::unordered_map &attribute_types, const char *arg) { const char *s = strchr(arg, ':'); if (s == NULL) { fprintf(stderr, "-T%s option must be in the form -Tname:type\n", arg); @@ -3005,8 +3005,8 @@ int main(int argc, char **argv) { bool guess_cluster_maxzoom = false; std::set exclude, include; - std::map attribute_types; - std::map attribute_accum; + std::unordered_map attribute_types; + std::unordered_map attribute_accum; std::map attribute_descriptions; int exclude_all = 0; int read_parallel = 0; diff --git a/overzoom.cpp b/overzoom.cpp index 1c9d365e..f1033d02 100644 --- a/overzoom.cpp +++ b/overzoom.cpp @@ -17,7 +17,7 @@ int buffer = 5; // tippecanoe-style: mvt buffer == extent * buffer / 256; bool demultiply = false; std::string filter; bool preserve_input_order = false; -std::map attribute_accum; +std::unordered_map attribute_accum; std::set keep; diff --git a/serial.cpp b/serial.cpp index cbb974a8..d7505ee6 100644 --- a/serial.cpp +++ b/serial.cpp @@ -878,7 +878,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) { return 1; } -void coerce_value(std::string const &key, int &vt, std::string &val, std::map const *attribute_types) { +void coerce_value(std::string const &key, int &vt, std::string &val, std::unordered_map const *attribute_types) { auto a = (*attribute_types).find(key); if (a != attribute_types->end()) { if (a->second == mvt_string) { diff --git a/serial.hpp b/serial.hpp index 05e6d4ea..fecbdf41 100644 --- a/serial.hpp +++ b/serial.hpp @@ -175,7 +175,7 @@ struct serialization_state { std::map *layermap = NULL; - std::map const *attribute_types = NULL; + std::unordered_map const *attribute_types = NULL; std::set *exclude = NULL; std::set *include = NULL; int exclude_all = 0; @@ -228,6 +228,6 @@ struct node { int nodecmp(const void *void1, const void *void2); int serialize_feature(struct serialization_state *sst, serial_feature &sf); -void coerce_value(std::string const &key, int &vt, std::string &val, std::map const *attribute_types); +void coerce_value(std::string const &key, int &vt, std::string &val, std::unordered_map const *attribute_types); #endif diff --git a/tile-join.cpp b/tile-join.cpp index 12cbfc03..10ff678e 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -699,7 +699,7 @@ struct tileset_reader { } if (source.layers.size() != 0) { - std::string ret = overzoom(source, parent_tile.z, parent_tile.x, parent_tile.y, tile.z, tile.x, tile.y, -1, buffer, std::set(), false, &next_overzoomed_tiles, false, NULL, false, std::map()); + std::string ret = overzoom(source, parent_tile.z, parent_tile.x, parent_tile.y, tile.z, tile.x, tile.y, -1, buffer, std::set(), false, &next_overzoomed_tiles, false, NULL, false, std::unordered_map()); return ret; } diff --git a/tile.cpp b/tile.cpp index 68c36bc4..8166a672 100644 --- a/tile.cpp +++ b/tile.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -537,7 +538,7 @@ struct partial { long long extent = 0; long long clustered = 0; std::set need_tilestats; - std::map attribute_accum_state; + std::unordered_map attribute_accum_state; }; struct partial_arg { @@ -1404,7 +1405,7 @@ struct write_tile_args { size_t feature_count_out = 0; const char *prefilter = NULL; const char *postfilter = NULL; - std::map const *attribute_accum = NULL; + std::unordered_map const *attribute_accum = NULL; bool still_dropping = false; int wrote_zoom = 0; size_t tiling_seg = 0; @@ -1593,7 +1594,7 @@ serial_feature next_feature(decompressor *geoms, std::atomic *geompos } if (filter != NULL) { - std::map attributes; + std::unordered_map attributes; std::string layername = (*layer_unmaps)[sf.segment][sf.layer]; std::set exclude_attributes; @@ -1846,7 +1847,7 @@ void promote_attribute(std::string const &key, partial &p, char *stringpool, lon } } -void preserve_attributes(std::map const *attribute_accum, serial_feature &sf, char *stringpool, long long *pool_off, partial &p) { +void preserve_attributes(std::unordered_map const *attribute_accum, serial_feature &sf, char *stringpool, long long *pool_off, partial &p) { for (size_t i = 0; i < sf.keys.size(); i++) { std::string key = stringpool + pool_off[sf.segment] + sf.keys[i] + 1; @@ -3117,7 +3118,7 @@ void *run_thread(void *vargs) { return NULL; } -int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic *midx, std::atomic *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector> &layermaps, const char *prefilter, const char *postfilter, std::map const *attribute_accum, struct json_object *filter, std::vector &strategies, int iz, struct node *shared_nodes_map, size_t nodepos) { +int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic *midx, std::atomic *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector> &layermaps, const char *prefilter, const char *postfilter, std::unordered_map const *attribute_accum, struct json_object *filter, std::vector &strategies, int iz, struct node *shared_nodes_map, size_t nodepos) { last_progress = 0; // The existing layermaps are one table per input thread. diff --git a/tile.hpp b/tile.hpp index 6155df0b..ede9d2ef 100644 --- a/tile.hpp +++ b/tile.hpp @@ -55,7 +55,7 @@ struct strategy { // long long write_tile(char **geom, char *stringpool, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int min_detail, int basezoom, sqlite3 *outdb, const char *outdir, double droprate, int buffer, const char *fname, FILE **geomfile, int file_minzoom, int file_maxzoom, double todo, char *geomstart, long long along, double gamma, int nlayers, std::atomic *strategy); -int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic *midx, std::atomic *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector > &layermap, const char *prefilter, const char *postfilter, std::map const *attribute_accum, struct json_object *filter, std::vector &strategies, int iz, struct node *shared_nodes_map, size_t nodepos); +int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic *midx, std::atomic *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector > &layermap, const char *prefilter, const char *postfilter, std::unordered_map const *attribute_accum, struct json_object *filter, std::vector &strategies, int iz, struct node *shared_nodes_map, size_t nodepos); int manage_gap(unsigned long long index, unsigned long long *previndex, double scale, double gamma, double *gap);