mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 09:55:41 +02:00
Much faster to search and add to the string pool as a binary tree
This commit is contained in:
@@ -139,25 +139,42 @@ struct pool_val *pool(struct pool *p, char *s, int type) {
|
|||||||
|
|
||||||
if (cmp == 0) {
|
if (cmp == 0) {
|
||||||
return *v;
|
return *v;
|
||||||
|
} else if (cmp < 0) {
|
||||||
|
v = &((*v)->left);
|
||||||
|
} else {
|
||||||
|
v = &((*v)->right);
|
||||||
}
|
}
|
||||||
|
|
||||||
v = &((*v)->next);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*v = malloc(sizeof(struct pool_val));
|
*v = malloc(sizeof(struct pool_val));
|
||||||
|
(*v)->left = NULL;
|
||||||
|
(*v)->right = NULL;
|
||||||
(*v)->next = NULL;
|
(*v)->next = NULL;
|
||||||
(*v)->s = s;
|
(*v)->s = s;
|
||||||
(*v)->type = type;
|
(*v)->type = type;
|
||||||
(*v)->n = p->n++;
|
(*v)->n = p->n++;
|
||||||
|
|
||||||
|
if (p->tail != NULL) {
|
||||||
|
p->tail->next = *v;
|
||||||
|
}
|
||||||
|
p->tail = *v;
|
||||||
|
if (p->head == NULL) {
|
||||||
|
p->head = *v;
|
||||||
|
}
|
||||||
|
|
||||||
return *v;
|
return *v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pool_free(struct pool *p) {
|
void pool_free(struct pool *p) {
|
||||||
while (p->vals != NULL) {
|
while (p->head != NULL) {
|
||||||
struct pool_val *next = p->vals->next;
|
struct pool_val *next = p->head->next;
|
||||||
free(p->vals);
|
free(p->head);
|
||||||
p->vals = next;
|
p->head = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p->head = NULL;
|
||||||
|
p->tail = NULL;
|
||||||
|
p->vals = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned
|
|||||||
struct pool keys;
|
struct pool keys;
|
||||||
keys.n = 0;
|
keys.n = 0;
|
||||||
keys.vals = NULL;
|
keys.vals = NULL;
|
||||||
|
keys.head = NULL;
|
||||||
|
keys.tail = NULL;
|
||||||
|
|
||||||
struct index *i;
|
struct index *i;
|
||||||
//printf("tile -----------------------------------------------\n");
|
//printf("tile -----------------------------------------------\n");
|
||||||
@@ -165,7 +167,7 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct pool_val *pv;
|
struct pool_val *pv;
|
||||||
for (pv = keys.vals; pv != NULL; pv = pv->next) {
|
for (pv = keys.head; pv != NULL; pv = pv->next) {
|
||||||
layer->add_keys(pv->s, strlen(pv->s));
|
layer->add_keys(pv->s, strlen(pv->s));
|
||||||
}
|
}
|
||||||
pool_free(&keys);
|
pool_free(&keys);
|
||||||
|
|||||||
@@ -19,11 +19,17 @@ struct pool_val {
|
|||||||
int type;
|
int type;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
struct pool_val *left;
|
||||||
|
struct pool_val *right;
|
||||||
|
|
||||||
struct pool_val *next;
|
struct pool_val *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pool {
|
struct pool {
|
||||||
struct pool_val *vals;
|
struct pool_val *vals;
|
||||||
|
|
||||||
|
struct pool_val *head;
|
||||||
|
struct pool_val *tail;
|
||||||
int n;
|
int n;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user