mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
change hash function to fnv1a (#48)
change mbtiles hash function from hashCode to fnv1a.
This commit is contained in:
+7
-6
@@ -100,13 +100,14 @@ sqlite3 *mbtiles_open(char *dbname, char **argv, int forcetable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
// Store tiles by a hash of their contents. node-mbtiles uses MD5,
|
// Store tiles by a hash of their contents (fnv1a 64-bit)
|
||||||
// but I am resisting adding the dependency, so instead here is
|
// http://www.isthe.com/chongo/tech/comp/fnv/
|
||||||
// everybody's first hash function. It is the same as Java's String.hashCode(),
|
const unsigned long long fnv_offset_basis = 14695981039346656037u;
|
||||||
// https://docs.oracle.com/javase/6/docs/api/java/lang/String.html#hashCode()
|
const unsigned long long fnv_prime = 1099511628211u;
|
||||||
unsigned long long h = 0;
|
unsigned long long h = fnv_offset_basis;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
h = h * 31 + data[i];
|
h ^= (unsigned char) data[i];
|
||||||
|
h *= fnv_prime;
|
||||||
}
|
}
|
||||||
std::string hash = std::to_string(h);
|
std::string hash = std::to_string(h);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user