mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Store the hash in the tree instead of recalculating
This commit is contained in:
@@ -9,11 +9,13 @@
|
|||||||
#include "errors.hpp"
|
#include "errors.hpp"
|
||||||
#include "text.hpp"
|
#include "text.hpp"
|
||||||
|
|
||||||
int swizzlecmp(const char *a, unsigned long long ahash, const char *b, int btype) {
|
inline int swizzlecmp(const char *a, int atype, unsigned long long ahash, const char *b, int btype, unsigned long long bhash) {
|
||||||
unsigned long long bhash = fnv1a(b, btype);
|
|
||||||
|
|
||||||
if (ahash == bhash) {
|
if (ahash == bhash) {
|
||||||
|
if (atype == btype) {
|
||||||
return strcmp(a, b);
|
return strcmp(a, b);
|
||||||
|
} else {
|
||||||
|
return atype - btype;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return (int) ahash - (int) bhash;
|
return (int) ahash - (int) bhash;
|
||||||
}
|
}
|
||||||
@@ -43,9 +45,10 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (*sp != 0) {
|
while (*sp != 0) {
|
||||||
int cmp = swizzlecmp(s, hash,
|
int cmp = swizzlecmp(s, type, hash,
|
||||||
poolfile->map.c_str() + ((struct stringpool *) (treefile->map.c_str() + *sp))->off + 1,
|
poolfile->map.c_str() + ((struct stringpool *) (treefile->map.c_str() + *sp))->off + 1,
|
||||||
(poolfile->map.c_str() + ((struct stringpool *) (treefile->map.c_str() + *sp))->off)[0]);
|
(poolfile->map.c_str() + ((struct stringpool *) (treefile->map.c_str() + *sp))->off)[0],
|
||||||
|
((struct stringpool *) (treefile->map.c_str() + *sp))->hash);
|
||||||
|
|
||||||
if (cmp < 0) {
|
if (cmp < 0) {
|
||||||
sp = &(((struct stringpool *) (treefile->map.c_str() + *sp))->left);
|
sp = &(((struct stringpool *) (treefile->map.c_str() + *sp))->left);
|
||||||
@@ -148,6 +151,7 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
|
|||||||
tsp.left = 0;
|
tsp.left = 0;
|
||||||
tsp.right = 0;
|
tsp.right = 0;
|
||||||
tsp.off = off;
|
tsp.off = off;
|
||||||
|
tsp.hash = hash;
|
||||||
|
|
||||||
long long p = treefile->off;
|
long long p = treefile->off;
|
||||||
if (memfile_write(treefile, &tsp, sizeof(struct stringpool), in_memory) < 0) {
|
if (memfile_write(treefile, &tsp, sizeof(struct stringpool), in_memory) < 0) {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
struct stringpool {
|
struct stringpool {
|
||||||
unsigned long left = 0;
|
unsigned long left = 0;
|
||||||
unsigned long right = 0;
|
unsigned long right = 0;
|
||||||
|
|
||||||
unsigned long off = 0;
|
unsigned long off = 0;
|
||||||
|
size_t hash; // hash of the string at this node
|
||||||
};
|
};
|
||||||
|
|
||||||
long long addpool(struct memfile *poolfile, struct memfile *treefile, const char *s, char type, std::vector<ssize_t> &dedup);
|
long long addpool(struct memfile *poolfile, struct memfile *treefile, const char *s, char type, std::vector<ssize_t> &dedup);
|
||||||
|
|||||||
Reference in New Issue
Block a user