mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Move string hashing from mbtiles to text
This commit is contained in:
-13
@@ -101,19 +101,6 @@ sqlite3 *mbtiles_open(char *dbname, char **argv, int forcetable) {
|
|||||||
return outdb;
|
return outdb;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long fnv1a(std::string const &s) {
|
|
||||||
// Store tiles by a hash of their contents (fnv1a 64-bit)
|
|
||||||
// http://www.isthe.com/chongo/tech/comp/fnv/
|
|
||||||
const unsigned long long fnv_offset_basis = 14695981039346656037u;
|
|
||||||
const unsigned long long fnv_prime = 1099511628211u;
|
|
||||||
unsigned long long h = fnv_offset_basis;
|
|
||||||
for (size_t i = 0; i < s.size(); i++) {
|
|
||||||
h ^= (unsigned char) s[i];
|
|
||||||
h *= fnv_prime;
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mbtiles_write_tile(sqlite3 *outdb, int z, int tx, int ty, const char *data, int size) {
|
void mbtiles_write_tile(sqlite3 *outdb, int z, int tx, int ty, const char *data, int size) {
|
||||||
std::string hash = std::to_string(fnv1a(std::string(data, size)));
|
std::string hash = std::to_string(fnv1a(std::string(data, size)));
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,4 @@ std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::
|
|||||||
|
|
||||||
void add_to_tilestats(std::map<std::string, tilestat> &tilestats, std::string const &layername, serial_val const &val);
|
void add_to_tilestats(std::map<std::string, tilestat> &tilestats, std::string const &layername, serial_val const &val);
|
||||||
|
|
||||||
unsigned long long fnv1a(std::string const &s);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -184,3 +184,31 @@ char *dtoa_milo(double val) {
|
|||||||
}
|
}
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long long fnv1a(std::string const &s) {
|
||||||
|
// Store tiles by a hash of their contents (fnv1a 64-bit)
|
||||||
|
// http://www.isthe.com/chongo/tech/comp/fnv/
|
||||||
|
const unsigned long long fnv_offset_basis = 14695981039346656037u;
|
||||||
|
const unsigned long long fnv_prime = 1099511628211u;
|
||||||
|
unsigned long long h = fnv_offset_basis;
|
||||||
|
for (size_t i = 0; i < s.size(); i++) {
|
||||||
|
h ^= (unsigned char) s[i];
|
||||||
|
h *= fnv_prime;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long long fnv1a(const char *s, char additional) {
|
||||||
|
// Store tiles by a hash of their contents (fnv1a 64-bit)
|
||||||
|
// http://www.isthe.com/chongo/tech/comp/fnv/
|
||||||
|
const unsigned long long fnv_offset_basis = 14695981039346656037u;
|
||||||
|
const unsigned long long fnv_prime = 1099511628211u;
|
||||||
|
unsigned long long h = fnv_offset_basis;
|
||||||
|
for (size_t i = 0; s[i] != '\0'; i++) {
|
||||||
|
h ^= (unsigned char) s[i];
|
||||||
|
h *= fnv_prime;
|
||||||
|
}
|
||||||
|
h ^= (unsigned char) additional;
|
||||||
|
h *= fnv_prime;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,5 +8,7 @@ const char *utf8_next(const char *s, long *c);
|
|||||||
std::string truncate16(std::string const &s, size_t runes);
|
std::string truncate16(std::string const &s, size_t runes);
|
||||||
int integer_zoom(std::string where, std::string text);
|
int integer_zoom(std::string where, std::string text);
|
||||||
std::string format_commandline(int argc, char **argv);
|
std::string format_commandline(int argc, char **argv);
|
||||||
|
unsigned long long fnv1a(std::string const &s);
|
||||||
|
unsigned long long fnv1a(const char *s, char additional);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user