From eedb0850b2be427fa31ea9b313961b1d53e874b3 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Thu, 18 Sep 2014 17:25:33 -0700 Subject: [PATCH] Factor out code for finding ranges within the index --- geojson.c | 56 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/geojson.c b/geojson.c index 9e03477..17a9b26 100644 --- a/geojson.c +++ b/geojson.c @@ -289,29 +289,33 @@ void deserialize_string(char **f) { printf("%s", s); } - -void range_lookup(struct index *ix, long long n, char *metabase, unsigned long long start, unsigned long long end, int z_lookup, int z, unsigned x, unsigned y) { +void range_search(struct index *ix, long long n, unsigned long long start, unsigned long long end, struct index **pstart, struct index **pend) { struct index istart, iend; istart.index = start; iend.index = end; + *pstart = search(&istart, ix, n, sizeof(struct index), indexcmp); + *pend = search(&iend, ix, n, sizeof(struct index), indexcmp); + + if (*pend >= ix + n) { + *pend = ix + n - 1; + } + while (*pstart > ix && indexcmp(*pstart - 1, &istart) == 0) { + (*pstart)--; + } + if (indexcmp(*pstart, &istart) < 0) { + (*pstart)++; + } + if (indexcmp(*pend, &iend) > 0) { + (*pend)--; + } +} + +void range_lookup(struct index *ix, long long n, char *metabase, unsigned long long start, unsigned long long end, int z_lookup, int z, unsigned x, unsigned y) { printf("range %llx to %llx, %d/%u/%u, %d\n", start, end, z, x, y, z_lookup); - struct index *pstart = search(&istart, ix, n, sizeof(struct index), indexcmp); - struct index *pend = search(&iend, ix, n, sizeof(struct index), indexcmp); - - if (pend >= ix + n) { - pend = ix + n - 1; - } - while (pstart > ix && indexcmp(pstart - 1, &istart) == 0) { - pstart--; - } - if (indexcmp(pstart, &istart) < 0) { - pstart++; - } - if (indexcmp(pend, &iend) > 0) { - pend--; - } + struct index *pstart, *pend; + range_search(ix, n, start, end, &pstart, &pend); struct index *i; for (i = pstart; i <= pend; i++) { @@ -365,6 +369,24 @@ void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox) { int z = 14; unsigned x1, y1, x2, y2; + struct enumerate { + struct index *here; + struct index *end; + + struct file *next; + } enums[MAX_ZOOM + 1]; + + int i; + for (i = 0; i < MAX_ZOOM + 1; i++) { + unsigned long long start, end; + struct index *pstart, *pend; + + encode_tile(i, 0, 0, 0, &start, &end); + range_search(ix, n, start, end, &pstart, &pend); + + printf("zoom %d is %llx %llx that's %ld to %ld\n", i, start, end, pstart - ix, pend - ix); + } + if (z == 0) { x1 = y1 = x2 = y2 = 0; } else {