Making the string pool in the destination tile

This commit is contained in:
Eric Fischer 2015-08-20 14:50:26 -07:00
parent 863c9a5929
commit ed378681e4
3 changed files with 29 additions and 5 deletions

4
pool.c
View File

@ -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
View File

@ -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);

View File

@ -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);
}
}