mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 10:25:41 +02:00
Give the constant pool its own source file
This commit is contained in:
@@ -10,7 +10,7 @@ vector_tile.pb.cc vector_tile.pb.h: vector_tile.proto
|
|||||||
|
|
||||||
PG=
|
PG=
|
||||||
|
|
||||||
tippecanoe: geojson.o jsonpull.o vector_tile.pb.o tile.o clip.o
|
tippecanoe: geojson.o jsonpull.o vector_tile.pb.o tile.o clip.o pool.o
|
||||||
g++ $(PG) -O3 -g -Wall -o $@ $^ -lm -lz -lprotobuf-lite -lsqlite3
|
g++ $(PG) -O3 -g -Wall -o $@ $^ -lm -lz -lprotobuf-lite -lsqlite3
|
||||||
|
|
||||||
libjsonpull.a: jsonpull.o
|
libjsonpull.a: jsonpull.o
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "jsonpull.h"
|
#include "jsonpull.h"
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
|
#include "pool.h"
|
||||||
|
|
||||||
int low_detail = 10;
|
int low_detail = 10;
|
||||||
int full_detail = 12;
|
int full_detail = 12;
|
||||||
@@ -133,107 +134,6 @@ int indexcmp(const void *v1, const void *v2) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = compare(s, (*v)->s);
|
|
||||||
|
|
||||||
if (cmp == 0) {
|
|
||||||
cmp = type - (*v)->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmp == 0) {
|
|
||||||
return *v;
|
|
||||||
} else if (cmp < 0) {
|
|
||||||
v = &((*v)->left);
|
|
||||||
} else {
|
|
||||||
v = &((*v)->right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*v = malloc(sizeof(struct pool_val));
|
|
||||||
(*v)->left = NULL;
|
|
||||||
(*v)->right = NULL;
|
|
||||||
(*v)->next = NULL;
|
|
||||||
(*v)->s = s;
|
|
||||||
(*v)->type = type;
|
|
||||||
(*v)->n = p->n++;
|
|
||||||
|
|
||||||
if (p->tail != NULL) {
|
|
||||||
p->tail->next = *v;
|
|
||||||
}
|
|
||||||
p->tail = *v;
|
|
||||||
if (p->head == NULL) {
|
|
||||||
p->head = *v;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *v;
|
|
||||||
}
|
|
||||||
|
|
||||||
int is_pooled(struct pool *p, char *s, int type) {
|
|
||||||
struct pool_val **v = &(p->vals);
|
|
||||||
|
|
||||||
while (*v != NULL) {
|
|
||||||
int cmp = strcmp(s, (*v)->s);
|
|
||||||
|
|
||||||
if (cmp == 0) {
|
|
||||||
cmp = type - (*v)->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmp == 0) {
|
|
||||||
return 1;
|
|
||||||
} else if (cmp < 0) {
|
|
||||||
v = &((*v)->left);
|
|
||||||
} else {
|
|
||||||
v = &((*v)->right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
free(p->head);
|
|
||||||
p->head = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
p->head = NULL;
|
|
||||||
p->tail = NULL;
|
|
||||||
p->vals = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void pool_init(struct pool *p, int n) {
|
|
||||||
p->n = n;
|
|
||||||
p->vals = NULL;
|
|
||||||
p->head = NULL;
|
|
||||||
p->tail = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream) {
|
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream) {
|
||||||
size_t w = fwrite(ptr, size, nitems, stream);
|
size_t w = fwrite(ptr, size, nitems, stream);
|
||||||
if (w != nitems) {
|
if (w != nitems) {
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "pool.h"
|
||||||
|
|
||||||
|
static 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 = compare(s, (*v)->s);
|
||||||
|
|
||||||
|
if (cmp == 0) {
|
||||||
|
cmp = type - (*v)->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmp == 0) {
|
||||||
|
return *v;
|
||||||
|
} else if (cmp < 0) {
|
||||||
|
v = &((*v)->left);
|
||||||
|
} else {
|
||||||
|
v = &((*v)->right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*v = malloc(sizeof(struct pool_val));
|
||||||
|
(*v)->left = NULL;
|
||||||
|
(*v)->right = NULL;
|
||||||
|
(*v)->next = NULL;
|
||||||
|
(*v)->s = s;
|
||||||
|
(*v)->type = type;
|
||||||
|
(*v)->n = p->n++;
|
||||||
|
|
||||||
|
if (p->tail != NULL) {
|
||||||
|
p->tail->next = *v;
|
||||||
|
}
|
||||||
|
p->tail = *v;
|
||||||
|
if (p->head == NULL) {
|
||||||
|
p->head = *v;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int is_pooled(struct pool *p, char *s, int type) {
|
||||||
|
struct pool_val **v = &(p->vals);
|
||||||
|
|
||||||
|
while (*v != NULL) {
|
||||||
|
int cmp = strcmp(s, (*v)->s);
|
||||||
|
|
||||||
|
if (cmp == 0) {
|
||||||
|
cmp = type - (*v)->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmp == 0) {
|
||||||
|
return 1;
|
||||||
|
} else if (cmp < 0) {
|
||||||
|
v = &((*v)->left);
|
||||||
|
} else {
|
||||||
|
v = &((*v)->right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct pool_val *pool(struct pool *p, char *s, int type) {
|
||||||
|
return pool1(p, s, type, strcmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static 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;
|
||||||
|
free(p->head);
|
||||||
|
p->head = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->head = NULL;
|
||||||
|
p->tail = NULL;
|
||||||
|
p->vals = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pool_init(struct pool *p, int n) {
|
||||||
|
p->n = n;
|
||||||
|
p->vals = NULL;
|
||||||
|
p->head = NULL;
|
||||||
|
p->tail = NULL;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
struct pool_val {
|
||||||
|
char *s;
|
||||||
|
int type;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
struct pool_val *left;
|
||||||
|
struct pool_val *right;
|
||||||
|
|
||||||
|
struct pool_val *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pool {
|
||||||
|
struct pool_val *vals;
|
||||||
|
|
||||||
|
struct pool_val *head;
|
||||||
|
struct pool_val *tail;
|
||||||
|
int n;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
void pool_init(struct pool *p, int n);
|
||||||
|
int is_pooled(struct pool *p, char *s, int type);
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
|
#include "pool.h"
|
||||||
#include "clip.h"
|
#include "clip.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,35 +11,10 @@
|
|||||||
#define VT_NUMBER 2
|
#define VT_NUMBER 2
|
||||||
#define VT_BOOLEAN 7
|
#define VT_BOOLEAN 7
|
||||||
|
|
||||||
|
struct pool;
|
||||||
|
|
||||||
|
|
||||||
struct pool_val {
|
|
||||||
char *s;
|
|
||||||
int type;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
struct pool_val *left;
|
|
||||||
struct pool_val *right;
|
|
||||||
|
|
||||||
struct pool_val *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pool {
|
|
||||||
struct pool_val *vals;
|
|
||||||
|
|
||||||
struct pool_val *head;
|
|
||||||
struct pool_val *tail;
|
|
||||||
int n;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void deserialize_int(char **f, int *n);
|
void deserialize_int(char **f, int *n);
|
||||||
struct pool_val *deserialize_string(char **f, struct pool *p, int type);
|
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);
|
|
||||||
void pool_init(struct pool *p, int n);
|
|
||||||
|
|
||||||
|
|
||||||
struct index {
|
struct index {
|
||||||
|
|||||||
Reference in New Issue
Block a user