mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 09:55:41 +02:00
Move management of the mmap of indices out of either function
This commit is contained in:
@@ -1073,24 +1073,16 @@ static double round_droprate(double r) {
|
|||||||
return std::round(r * 100000.0) / 100000.0;
|
return std::round(r * 100000.0) / 100000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct index *calc_zooms_and_dropping(const int indexfd, const std::atomic<long long> &indexpos,
|
void calc_zooms_and_dropping(
|
||||||
const bool guess_maxzoom, const bool guess_cluster_maxzoom,
|
struct index *map, const long long indices,
|
||||||
const double dist_sum, const size_t dist_count,
|
const bool guess_maxzoom, const bool guess_cluster_maxzoom,
|
||||||
const double area_sum,
|
const double dist_sum, const size_t dist_count,
|
||||||
sqlite3 *outdb, const char *pgm,
|
const double area_sum,
|
||||||
int &maxzoom, const int minimum_maxzoom, int &basezoom, const int minzoom,
|
sqlite3 *outdb, const char *pgm,
|
||||||
const int basezoom_marker_width,
|
int &maxzoom, const int minimum_maxzoom, int &basezoom, const int minzoom,
|
||||||
double &droprate, const double gamma,
|
const int basezoom_marker_width,
|
||||||
bool &fix_dropping) {
|
double &droprate, const double gamma,
|
||||||
struct index *map = (struct index *) mmap(NULL, indexpos, PROT_READ, MAP_PRIVATE, indexfd, 0);
|
bool &fix_dropping) {
|
||||||
if (map == MAP_FAILED) {
|
|
||||||
perror("mmap index for basezoom");
|
|
||||||
exit(EXIT_MEMORY);
|
|
||||||
}
|
|
||||||
madvise(map, indexpos, MADV_SEQUENTIAL);
|
|
||||||
madvise(map, indexpos, MADV_WILLNEED);
|
|
||||||
long long indices = indexpos / sizeof(struct index);
|
|
||||||
|
|
||||||
if (guess_maxzoom) {
|
if (guess_maxzoom) {
|
||||||
double mean = 0;
|
double mean = 0;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
@@ -1483,16 +1475,11 @@ static struct index *calc_zooms_and_dropping(const int indexfd, const std::atomi
|
|||||||
|
|
||||||
fix_dropping = true;
|
fix_dropping = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fix_feature_minzooms(const bool fix_dropping, const int geomfd,
|
void fix_feature_minzooms(const bool fix_dropping, const int geomfd,
|
||||||
const int indexfd, const std::atomic<long long> &indexpos,
|
struct index *map, const long long indices,
|
||||||
struct index *map,
|
|
||||||
const int maxzoom, const int basezoom, const double droprate, const double gamma) {
|
const int maxzoom, const int basezoom, const double droprate, const double gamma) {
|
||||||
long long indices = indexpos / sizeof(struct index);
|
|
||||||
|
|
||||||
if (fix_dropping || drop_denser > 0) {
|
if (fix_dropping || drop_denser > 0) {
|
||||||
// Fix up the minzooms for features, now that we really know the base zoom
|
// Fix up the minzooms for features, now that we really know the base zoom
|
||||||
// and drop rate.
|
// and drop rate.
|
||||||
@@ -1507,8 +1494,6 @@ void fix_feature_minzooms(const bool fix_dropping, const int geomfd,
|
|||||||
perror("mmap geom for fixup");
|
perror("mmap geom for fixup");
|
||||||
exit(EXIT_MEMORY);
|
exit(EXIT_MEMORY);
|
||||||
}
|
}
|
||||||
madvise(geom, indexpos, MADV_SEQUENTIAL);
|
|
||||||
madvise(geom, indexpos, MADV_WILLNEED);
|
|
||||||
|
|
||||||
struct drop_state ds[maxzoom + 1];
|
struct drop_state ds[maxzoom + 1];
|
||||||
prep_drop_states(ds, maxzoom, basezoom, droprate);
|
prep_drop_states(ds, maxzoom, basezoom, droprate);
|
||||||
@@ -1561,13 +1546,6 @@ void fix_feature_minzooms(const bool fix_dropping, const int geomfd,
|
|||||||
|
|
||||||
munmap(geom, geomst.st_size);
|
munmap(geom, geomst.st_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
madvise(map, indexpos, MADV_DONTNEED);
|
|
||||||
munmap(map, indexpos);
|
|
||||||
|
|
||||||
if (close(indexfd) != 0) {
|
|
||||||
perror("close sorted index");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void radix(std::vector<struct reader> &readers, int nreaders, FILE *geomfile, FILE *indexfile, const char *tmpdir, std::atomic<long long> *geompos, int maxzoom, int basezoom, double droprate, double gamma) {
|
void radix(std::vector<struct reader> &readers, int nreaders, FILE *geomfile, FILE *indexfile, const char *tmpdir, std::atomic<long long> *geompos, int maxzoom, int basezoom, double droprate, double gamma) {
|
||||||
@@ -2793,22 +2771,37 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
|||||||
exit(EXIT_NODATA);
|
exit(EXIT_NODATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct index *map = (struct index *) mmap(NULL, indexpos, PROT_READ, MAP_PRIVATE, indexfd, 0);
|
||||||
|
if (map == MAP_FAILED) {
|
||||||
|
perror("mmap index for basezoom");
|
||||||
|
exit(EXIT_MEMORY);
|
||||||
|
}
|
||||||
|
madvise(map, indexpos, MADV_SEQUENTIAL);
|
||||||
|
madvise(map, indexpos, MADV_WILLNEED);
|
||||||
|
long long indices = indexpos / sizeof(struct index);
|
||||||
|
|
||||||
bool fix_dropping = false;
|
bool fix_dropping = false;
|
||||||
struct index *map = calc_zooms_and_dropping(indexfd, indexpos,
|
calc_zooms_and_dropping(map, indices,
|
||||||
guess_maxzoom, guess_cluster_maxzoom,
|
guess_maxzoom, guess_cluster_maxzoom,
|
||||||
dist_sum, dist_count,
|
dist_sum, dist_count,
|
||||||
area_sum,
|
area_sum,
|
||||||
outdb, pgm,
|
outdb, pgm,
|
||||||
maxzoom, minimum_maxzoom, basezoom, minzoom,
|
maxzoom, minimum_maxzoom, basezoom, minzoom,
|
||||||
basezoom_marker_width,
|
basezoom_marker_width,
|
||||||
droprate, gamma,
|
droprate, gamma,
|
||||||
fix_dropping);
|
fix_dropping);
|
||||||
|
|
||||||
fix_feature_minzooms(fix_dropping, geomfd,
|
fix_feature_minzooms(fix_dropping, geomfd,
|
||||||
indexfd, indexpos,
|
map, indices,
|
||||||
map,
|
|
||||||
maxzoom, basezoom, droprate, gamma);
|
maxzoom, basezoom, droprate, gamma);
|
||||||
|
|
||||||
|
madvise(map, indexpos, MADV_DONTNEED);
|
||||||
|
munmap(map, indexpos);
|
||||||
|
|
||||||
|
if (close(indexfd) != 0) {
|
||||||
|
perror("close sorted index");
|
||||||
|
}
|
||||||
|
|
||||||
/* Traverse and split the geometries for each zoom level */
|
/* Traverse and split the geometries for each zoom level */
|
||||||
|
|
||||||
struct stat geomst;
|
struct stat geomst;
|
||||||
|
|||||||
Reference in New Issue
Block a user