diff --git a/geojson.c b/geojson.c index bc2a11f0..eb485415 100644 --- a/geojson.c +++ b/geojson.c @@ -129,11 +129,11 @@ int indexcmp(const void *v1, const void *v2) { } } -struct pool_val *pool(struct pool *p, char *s, int type) { +struct pool_val *pool1(struct pool *p, char *s, int type, int (*compare)(const char *, const char *)) { struct pool_val **v = &(p->vals); while (*v != NULL) { - int cmp = strcmp(s, (*v)->s); + int cmp = compare(s, (*v)->s); if (cmp == 0) { cmp = type - (*v)->type; @@ -167,6 +167,27 @@ struct pool_val *pool(struct pool *p, char *s, int type) { return *v; } +struct pool_val *pool(struct pool *p, char *s, int type) { + return pool1(p, s, type, strcmp); +} + +int llcmp(const char *v1, const char *v2) { + long long *ll1 = (long long *) v1; + long long *ll2 = (long long *) v2; + + if (*ll1 < *ll2) { + return -1; + } else if (*ll1 > *ll2) { + return 1; + } else { + return 0; + } +} + +struct pool_val *pool_long_long(struct pool *p, long long *s, int type) { + return pool1(p, (char *) s, type, llcmp); +} + void pool_free(struct pool *p) { while (p->head != NULL) { struct pool_val *next = p->head->next; diff --git a/tile.cc b/tile.cc index 5f6656f2..dbf59381 100644 --- a/tile.cc +++ b/tile.cc @@ -145,6 +145,12 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned values.head = NULL; values.tail = NULL; + struct pool dup; + dup.n = 1; + dup.vals = NULL; + dup.head = NULL; + dup.tail = NULL; + double interval = 1; double seq = 0; @@ -170,6 +176,12 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned } if (t == VT_POINT || draw(&meta, NULL, z, tx, ty, detail)) { + struct pool_val *pv = pool_long_long(&dup, &i->fpos, 0); + if (pv->n == 0) { + continue; + } + pv->n = 0; + meta = metabase + i->fpos; deserialize_int(&meta, &t); @@ -220,6 +232,8 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned } } pool_free(&keys); + pool_free(&values); + pool_free(&dup); std::string s; std::string compressed; diff --git a/tile.h b/tile.h index 8ff23d5d..a9d7714b 100644 --- a/tile.h +++ b/tile.h @@ -37,6 +37,7 @@ struct pool { void deserialize_int(char **f, int *n); struct pool_val *deserialize_string(char **f, struct pool *p, int type); struct pool_val *pool(struct pool *p, char *s, int type); +struct pool_val *pool_long_long(struct pool *p, long long *val, int type); void pool_free(struct pool *p);