diff --git a/pool.cpp b/pool.cpp index 349f0c67..dddb12b9 100644 --- a/pool.cpp +++ b/pool.cpp @@ -1,18 +1,18 @@ #include #include #include +#include #include "memfile.hpp" #include "pool.hpp" #define POOL_WIDTH 256 static int hash(const char *s) { - int h = 0; + unsigned h = 0; for (; *s; s++) { - h = h * 37 + *s; + h = (h * 37 + *s) & ULONG_MAX; } - h = h & 0xFF; - return h; + return h & 0xFF; } struct pool_val *pool(struct pool *p, const char *s, int type) { diff --git a/tile.cpp b/tile.cpp index 9a235f45..4488783e 100644 --- a/tile.cpp +++ b/tile.cpp @@ -501,14 +501,14 @@ int manage_gap(unsigned long long index, unsigned long long *previndex, double s return 1; // Exact duplicate: can't fulfil the gap requirement } - if (std::exp(std::log((index - *previndex) / scale) * gamma) >= *gap) { + if (index < *previndex || std::exp(std::log((index - *previndex) / scale) * gamma) >= *gap) { // Dot is further from the previous than the nth root of the gap, // so produce it, and choose a new gap at the next point. *gap = 0; } else { return 1; } - } else { + } else if (index >= *previndex) { *gap = (index - *previndex) / scale; if (*gap == 0) { @@ -1182,8 +1182,17 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo if (threads > useful_threads) { threads = useful_threads; } + // Round down to a power of 2 - threads = 1 << (int) (std::log(threads) / std::log(2)); + for (int e = 0; e < 30; e++) { + if (threads >= (1 << e) && threads < (1 << (e + 1))) { + threads = 1 << e; + break; + } + } + if (threads >= (1 << 30)) { + threads = 1 << 30; + } // Assign temporary files to threads