diff --git a/pool.c b/pool.c index cc55df9..4641afc 100644 --- a/pool.c +++ b/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; diff --git a/pool.h b/pool.h index 683b551..100dd76 100644 --- a/pool.h +++ b/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); diff --git a/tile-join.cc b/tile-join.cc index af02b0d..89f9e8c 100644 --- a/tile-join.cc +++ b/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); } }