mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Making the string pool in the destination tile
This commit is contained in:
@@ -14,7 +14,7 @@ static int hash(const char *s) {
|
|||||||
return h;
|
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);
|
int h = hash(s);
|
||||||
struct pool_val **v = &(p->vals[h]);
|
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 *)) {
|
void pool_free1(struct pool *p, void (*func)(void *)) {
|
||||||
while (p->head != NULL) {
|
while (p->head != NULL) {
|
||||||
if (func != NULL) {
|
if (func != NULL) {
|
||||||
func(p->head->s);
|
func((void *) p->head->s);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pool_val *next = p->head->next;
|
struct pool_val *next = p->head->next;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
struct pool_val {
|
struct pool_val {
|
||||||
char *s;
|
const char *s;
|
||||||
int type;
|
int type;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ struct pool {
|
|||||||
int n;
|
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(struct pool *p);
|
||||||
void pool_free_strings(struct pool *p);
|
void pool_free_strings(struct pool *p);
|
||||||
void pool_init(struct pool *p, int n);
|
void pool_init(struct pool *p, int n);
|
||||||
|
|||||||
+25
-1
@@ -100,6 +100,10 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
|
|||||||
*nlayers = ll + 1;
|
*nlayers = ll + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct pool keys, values;
|
||||||
|
pool_init(&keys, 0);
|
||||||
|
pool_init(&values, 0);
|
||||||
|
|
||||||
for (int f = 0; f < layer.features_size(); f++) {
|
for (int f = 0; f < layer.features_size(); f++) {
|
||||||
mapnik::vector::tile_feature feat = layer.features(f);
|
mapnik::vector::tile_feature feat = layer.features(f);
|
||||||
mapnik::vector::tile_feature *outfeature = outlayer->add_features();
|
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);
|
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);
|
free(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pool_free_strings(&keys);
|
||||||
|
pool_free_strings(&values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user