mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-03-25 05:15:16 +00:00
Making the string pool in the destination tile
This commit is contained in:
parent
863c9a5929
commit
ed378681e4
4
pool.c
4
pool.c
@ -14,7 +14,7 @@ static int hash(const char *s) {
|
||||
return h;
|
||||
}
|
||||
|
||||
struct pool_val *pool(struct pool *p, char *s, int type) {
|
||||
struct pool_val *pool(struct pool *p, const char *s, int type) {
|
||||
int h = hash(s);
|
||||
struct pool_val **v = &(p->vals[h]);
|
||||
|
||||
@ -83,7 +83,7 @@ int is_pooled(struct pool *p, const char *s, int type) {
|
||||
void pool_free1(struct pool *p, void (*func)(void *)) {
|
||||
while (p->head != NULL) {
|
||||
if (func != NULL) {
|
||||
func(p->head->s);
|
||||
func((void *) p->head->s);
|
||||
}
|
||||
|
||||
struct pool_val *next = p->head->next;
|
||||
|
4
pool.h
4
pool.h
@ -1,5 +1,5 @@
|
||||
struct pool_val {
|
||||
char *s;
|
||||
const char *s;
|
||||
int type;
|
||||
int n;
|
||||
|
||||
@ -17,7 +17,7 @@ struct pool {
|
||||
int n;
|
||||
};
|
||||
|
||||
struct pool_val *pool(struct pool *p, char *s, int type);
|
||||
struct pool_val *pool(struct pool *p, const char *s, int type);
|
||||
void pool_free(struct pool *p);
|
||||
void pool_free_strings(struct pool *p);
|
||||
void pool_init(struct pool *p, int n);
|
||||
|
26
tile-join.cc
26
tile-join.cc
@ -100,6 +100,10 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
|
||||
*nlayers = ll + 1;
|
||||
}
|
||||
|
||||
struct pool keys, values;
|
||||
pool_init(&keys, 0);
|
||||
pool_init(&values, 0);
|
||||
|
||||
for (int f = 0; f < layer.features_size(); f++) {
|
||||
mapnik::vector::tile_feature feat = layer.features(f);
|
||||
mapnik::vector::tile_feature *outfeature = outlayer->add_features();
|
||||
@ -150,10 +154,30 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
|
||||
pool(file_keys[ll], strdup(key), type);
|
||||
}
|
||||
|
||||
printf("%d: %s=%s\n", type, key, value);
|
||||
struct pool_val *k, *v;
|
||||
|
||||
if (is_pooled(&keys, key, VT_STRING)) {
|
||||
k = pool(&keys, key, VT_STRING);
|
||||
} else {
|
||||
k = pool(&keys, strdup(key), VT_STRING);
|
||||
}
|
||||
|
||||
if (is_pooled(&values, value, type)) {
|
||||
v = pool(&values, value, type);
|
||||
} else {
|
||||
v = pool(&values, strdup(value), type);
|
||||
}
|
||||
|
||||
outfeature->add_tags(k->n);
|
||||
outfeature->add_tags(v->n);
|
||||
|
||||
printf("%d: %s=%s %d=%d\n", type, key, value, k->n, v->n);
|
||||
free(value);
|
||||
}
|
||||
}
|
||||
|
||||
pool_free_strings(&keys);
|
||||
pool_free_strings(&values);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user