diff --git a/geometry.cpp b/geometry.cpp index 66cb5651..89cfed7a 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -578,8 +578,8 @@ drawvec reorder_lines(const drawvec &geom) { // instead of down and to the right // so that it will coalesce better - unsigned long long l1 = encode_index(coordinate_to_encodable(geom[0].x), coordinate_to_encodable(geom[0].y)); - unsigned long long l2 = encode_index(coordinate_to_encodable(geom[geom.size() - 1].x), coordinate_to_encodable(geom[geom.size() - 1].y)); + index_t l1 = encode_index(coordinate_to_encodable(geom[0].x), coordinate_to_encodable(geom[0].y)); + index_t l2 = encode_index(coordinate_to_encodable(geom[geom.size() - 1].x), coordinate_to_encodable(geom[geom.size() - 1].y)); if (l1 > l2) { drawvec out; diff --git a/main.cpp b/main.cpp index bf31232b..1c4c059b 100644 --- a/main.cpp +++ b/main.cpp @@ -283,13 +283,13 @@ static void insert(struct mergelist *m, struct mergelist **head, unsigned char * struct drop_state { double gap; - unsigned long long previndex; + index_t previndex; double interval; double seq; // floating point because interval is }; struct drop_densest { - unsigned long long gap; + index_t gap; size_t seq; bool operator<(const drop_densest &o) const { @@ -822,7 +822,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split for (size_t a = 0; a < indexst.st_size / sizeof(struct index); a++) { struct index ix = indexmap[a]; - unsigned long long which = (ix.ix << prefix) >> (64 - splitbits); + index_t which = (ix.ix << prefix) >> (2 * GLOBAL_DETAIL - splitbits); long long pos = sub_geompos[which]; fwrite_check(geommap + ix.start, ix.end - ix.start, 1, geomfiles[which], &sub_geompos[which], "geom"); @@ -2375,7 +2375,7 @@ std::pair read_input(std::vector &sources, char *fname, i bool changed = false; while (maxzoom < GLOBAL_DETAIL - full_detail && maxzoom < GLOBAL_DETAIL + 1 - low_detail && maxzoom < cluster_maxzoom && cluster_distance > 0) { - unsigned long long zoom_mingap = ((1LL << (GLOBAL_DETAIL - maxzoom)) / 256 * cluster_distance) * ((1LL << (GLOBAL_DETAIL - maxzoom)) / 256 * cluster_distance); + index_t zoom_mingap = ((1LL << (GLOBAL_DETAIL - maxzoom)) / 256 * cluster_distance) * ((1LL << (GLOBAL_DETAIL - maxzoom)) / 256 * cluster_distance); if (avg > zoom_mingap) { break; } @@ -2487,7 +2487,7 @@ std::pair read_input(std::vector &sources, char *fname, i long long count; long long fullcount; double gap; - unsigned long long previndex; + index_t previndex; } tile[MAX_ZOOM + 1], max[MAX_ZOOM + 1]; { @@ -2687,7 +2687,7 @@ std::pair read_input(std::vector &sources, char *fname, i if (drop_denser > 0) { std::vector ddv; - unsigned long long previndex = 0; + index_t previndex = 0; for (long long ip = 0; ip < indices; ip++) { if (map[ip].t == VT_POINT || diff --git a/main.hpp b/main.hpp index 25695e2f..cc578cc2 100644 --- a/main.hpp +++ b/main.hpp @@ -13,7 +13,7 @@ struct index { long long start = 0; long long end = 0; - unsigned long long ix = 0; + index_t ix = 0; short segment = 0; unsigned short t : 2; unsigned long long seq : (64 - 18); // pack with segment and t to stay in 32 bytes diff --git a/projection.cpp b/projection.cpp index e2262b17..7c973e88 100644 --- a/projection.cpp +++ b/projection.cpp @@ -9,8 +9,8 @@ #define UINT_BITS 32 -unsigned long long (*encode_index)(unsigned int wx, unsigned int wy) = NULL; -void (*decode_index)(unsigned long long index, unsigned *wx, unsigned *wy) = NULL; +index_t (*encode_index)(unsigned int wx, unsigned int wy) = NULL; +void (*decode_index)(index_t index, unsigned *wx, unsigned *wy) = NULL; struct projection projections[] = { {"EPSG:4326", lonlat2tile, tile2lonlat, "urn:ogc:def:crs:OGC:1.3:CRS84"}, @@ -154,7 +154,7 @@ unsigned long long encode_hilbert(unsigned int wx, unsigned int wy) { return hilbert_xy2d(1LL << UINT_BITS, wx, wy); } -void decode_hilbert(unsigned long long index, unsigned *wx, unsigned *wy) { +void decode_hilbert(index_t index, unsigned *wx, unsigned *wy) { hilbert_d2xy(1LL << UINT_BITS, index, wx, wy); } @@ -176,7 +176,7 @@ unsigned long long encode_quadkey(unsigned int wx, unsigned int wy) { static std::atomic decodex[256]; static std::atomic decodey[256]; -void decode_quadkey(unsigned long long index, unsigned *wx, unsigned *wy) { +void decode_quadkey(index_t index, unsigned *wx, unsigned *wy) { static std::atomic initialized(0); if (!initialized) { for (size_t ix = 0; ix < 256; ix++) { diff --git a/projection.hpp b/projection.hpp index 789849ec..47983162 100644 --- a/projection.hpp +++ b/projection.hpp @@ -2,6 +2,7 @@ #define PROJECTION_HPP #define GLOBAL_DETAIL 32 +typedef unsigned long long index_t; void lonlat2tile(double lon, double lat, int zoom, long long *x, long long *y); void epsg3857totile(double ix, double iy, int zoom, long long *x, long long *y); @@ -19,14 +20,14 @@ struct projection { extern struct projection *projection; extern struct projection projections[]; -extern unsigned long long (*encode_index)(unsigned int wx, unsigned int wy); -extern void (*decode_index)(unsigned long long index, unsigned *wx, unsigned *wy); +extern index_t (*encode_index)(unsigned int wx, unsigned int wy); +extern void (*decode_index)(index_t index, unsigned *wx, unsigned *wy); unsigned long long encode_quadkey(unsigned int wx, unsigned int wy); -void decode_quadkey(unsigned long long index, unsigned *wx, unsigned *wy); +void decode_quadkey(index_t index, unsigned *wx, unsigned *wy); unsigned long long encode_hilbert(unsigned int wx, unsigned int wy); -void decode_hilbert(unsigned long long index, unsigned *wx, unsigned *wy); +void decode_hilbert(index_t index, unsigned *wx, unsigned *wy); unsigned coordinate_to_encodable(long long coord); long long decoded_to_coordinate(unsigned coord); diff --git a/serial.cpp b/serial.cpp index f3d088ec..4ed6ed75 100644 --- a/serial.cpp +++ b/serial.cpp @@ -682,7 +682,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std:: *(sst->area_sum) += extent; } - unsigned long long bbox_index; + index_t bbox_index; long long midx, midy; if (sf.t == VT_POINT) { diff --git a/serial.hpp b/serial.hpp index 2e8ed3d5..d1231950 100644 --- a/serial.hpp +++ b/serial.hpp @@ -67,8 +67,8 @@ struct serial_feature { int tippecanoe_maxzoom = -1; drawvec geometry = drawvec(); - unsigned long long index = 0; - unsigned long long label_point = 0; + index_t index = 0; + index_t label_point = 0; long long extent = 0; // These fields are not directly serialized, but are used diff --git a/shared_borders.cpp b/shared_borders.cpp index 2a1bd2ee..614baba1 100644 --- a/shared_borders.cpp +++ b/shared_borders.cpp @@ -367,7 +367,7 @@ bool find_common_edges(std::vector &features, int z, int line_de struct merge_order { ssize_t edge = 0; - unsigned long long gap = 0; + index_t gap = 0; size_t p1 = 0; size_t p2 = 0; diff --git a/tile.cpp b/tile.cpp index 1466d5a7..55b55044 100644 --- a/tile.cpp +++ b/tile.cpp @@ -705,7 +705,7 @@ static void *simplification_worker(void *v) { // get rid of the --gamma option. It does something with the feature spacing to calculate // whether each feature should be kept or is in a dense enough context that it should // be dropped -int manage_gap(unsigned long long index, unsigned long long *previndex, double scale, double gamma, double *gap) { +int manage_gap(index_t index, index_t *previndex, double scale, double gamma, double *gap) { if (gamma > 0) { if (*gap > 0) { if (index == *previndex) { @@ -742,7 +742,7 @@ int manage_gap(unsigned long long index, unsigned long long *previndex, double s // of features that survived the previous gap-choosing, so it first needs to calculate // and sort the gaps between them before deciding which new gap threshold will satisfy // the need to keep only the requested fraction of features. -static unsigned long long choose_mingap(std::vector const &indices, double f) { +static index_t choose_mingap(std::vector const &indices, double f) { unsigned long long bot = ULLONG_MAX; unsigned long long top = 0; @@ -885,8 +885,8 @@ struct write_tile_args { std::vector> *layermaps = NULL; std::vector> *layer_unmaps = NULL; size_t pass = 0; - unsigned long long mingap = 0; - unsigned long long mingap_out = 0; + index_t mingap = 0; + index_t mingap_out = 0; long long minextent = 0; long long minextent_out = 0; unsigned long long mindrop_sequence = 0; @@ -1488,7 +1488,7 @@ bool drop_feature_unless_it_can_be_added_to_a_multiplier_cluster(layer_features return false; // did not drop because nothing could be found to accumulate attributes onto } -long long write_tile(decompressor *geoms, std::atomic *geompos_in, char *global_stringpool, int z, const unsigned tx, const unsigned ty, const int detail, int min_detail, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, compressor **geomfile, int minzoom, int maxzoom, double todo, std::atomic *along, long long alongminus, double gamma, int child_shards, long long *pool_off, long long *initial_x, long long *initial_y, std::atomic *running, double simplification, std::vector> *layermaps, std::vector> *layer_unmaps, size_t tiling_seg, size_t pass, unsigned long long mingap, long long minextent, unsigned long long mindrop_sequence, const char *prefilter, const char *postfilter, json_object *filter, write_tile_args *arg, atomic_strategy *strategy, bool compressed_input, node *shared_nodes_map, size_t nodepos, std::vector const &unidecode_data) { +long long write_tile(decompressor *geoms, std::atomic *geompos_in, char *global_stringpool, int z, const unsigned tx, const unsigned ty, const int detail, int min_detail, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, compressor **geomfile, int minzoom, int maxzoom, double todo, std::atomic *along, long long alongminus, double gamma, int child_shards, long long *pool_off, long long *initial_x, long long *initial_y, std::atomic *running, double simplification, std::vector> *layermaps, std::vector> *layer_unmaps, size_t tiling_seg, size_t pass, index_t mingap, long long minextent, unsigned long long mindrop_sequence, const char *prefilter, const char *postfilter, json_object *filter, write_tile_args *arg, atomic_strategy *strategy, bool compressed_input, node *shared_nodes_map, size_t nodepos, std::vector const &unidecode_data) { double merge_fraction = 1; double mingap_fraction = 1; double minextent_fraction = 1; @@ -1525,8 +1525,8 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch long long count = 0; double accum_area = 0; - unsigned long long previndex = 0, density_previndex = 0, merge_previndex = 0; - unsigned long long extent_previndex = 0; + index_t previndex = 0, density_previndex = 0, merge_previndex = 0; + index_t extent_previndex = 0; double scale = (double) (1LL << (64 - 2 * (z + 8))); double gap = 0, density_gap = 0; double spacing = 0; @@ -1870,7 +1870,7 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch } } - unsigned long long sfindex = sf.index; + index_t sfindex = sf.index; if (sf.geometry.size() > 0) { if (lead_features_count > max_tile_size || (lead_features_count + other_multiplier_cluster_features_count > max_tile_features && !prevent[P_FEATURE_LIMIT])) { @@ -2361,7 +2361,7 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch continue; } else if (mingap < ULONG_MAX && (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_COALESCE_DENSEST_AS_NEEDED] || additional[A_CLUSTER_DENSEST_AS_NEEDED])) { mingap_fraction = mingap_fraction * max_tile_features / totalsize * 0.90; - unsigned long long mg = choose_mingap(indices, mingap_fraction); + index_t mg = choose_mingap(indices, mingap_fraction); if (mg <= mingap) { mg = (mingap + 1) * 1.5; @@ -2468,7 +2468,7 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch line_detail++; // to keep it the same when the loop decrements it } else if (mingap < ULONG_MAX && (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_COALESCE_DENSEST_AS_NEEDED] || additional[A_CLUSTER_DENSEST_AS_NEEDED])) { mingap_fraction = mingap_fraction * scaled_max_tile_size / (kept_adjust * compressed.size()) * 0.90; - unsigned long long mg = choose_mingap(indices, mingap_fraction); + index_t mg = choose_mingap(indices, mingap_fraction); if (mg <= mingap) { double nmg = (mingap + 1) * 1.5; @@ -2831,8 +2831,7 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *global_stringpool, std:: size_t zoom_tile_size = 0; size_t zoom_feature_count = 0; - // yes, these need to be 32, not GLOBAL_DETAIL, because clusters operate on indices, not coordinates - unsigned long long zoom_mingap = ((1LL << (32 - z)) / 256 * cluster_distance) * ((1LL << (32 - z)) / 256 * cluster_distance); + index_t zoom_mingap = (index_t) ((1LL << (GLOBAL_DETAIL - z)) / 256 * cluster_distance) * ((1LL << (GLOBAL_DETAIL - z)) / 256 * cluster_distance); for (size_t pass = 0;; pass++) { pthread_t pthreads[threads]; diff --git a/tile.hpp b/tile.hpp index 868f55a4..17ff37ae 100644 --- a/tile.hpp +++ b/tile.hpp @@ -57,6 +57,6 @@ struct 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, long long *initial_x, long long *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 basezoom, double droprate, std::vector const &unidecode_data); -int manage_gap(unsigned long long index, unsigned long long *previndex, double scale, double gamma, double *gap); +int manage_gap(index_t index, index_t *previndex, double scale, double gamma, double *gap); #endif diff --git a/write_json.cpp b/write_json.cpp index bdf1e852..303ab75c 100644 --- a/write_json.cpp +++ b/write_json.cpp @@ -268,7 +268,7 @@ void write_coords(json_writer &state, lonlat const &ll, double scale) { } } -void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool write_dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale) { +void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool write_dropped, index_t index, long long sequence, long long extent, bool complain, json_writer &state, double scale) { for (size_t f = 0; f < layer.features.size(); f++) { mvt_feature const &feat = layer.features[f]; diff --git a/write_json.hpp b/write_json.hpp index 523b027b..a690c93f 100644 --- a/write_json.hpp +++ b/write_json.hpp @@ -61,7 +61,7 @@ struct json_writer { void adds(std::string const &s); }; -void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale); +void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, index_t index, long long sequence, long long extent, bool complain, json_writer &state, double scale); void fprintq(FILE *f, const char *s); #endif