Changeset: c92b20d9bc24 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c92b20d9bc24 Added Files: geom/monetdb5/31_grid_hge.mal geom/monetdb5/grid_hge.mal geom/monetdb5/grid_impl.h geom/sql/41_grid_hge.sql Modified Files: geom/monetdb5/Makefile.ag geom/monetdb5/grid.c geom/monetdb5/grid.h geom/monetdb5/grid.mal geom/sql/41_grid.sql geom/sql/Makefile.ag Branch: grid Log Message:
Instantiated the grid filter function for all numeric data types diffs (truncated from 1285 to 300 lines): diff --git a/geom/monetdb5/31_grid_hge.mal b/geom/monetdb5/31_grid_hge.mal new file mode 100644 --- /dev/null +++ b/geom/monetdb5/31_grid_hge.mal @@ -0,0 +1,9 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. + +# This loads the MonetDB/GIS module +library geom; +include grid_hge; diff --git a/geom/monetdb5/Makefile.ag b/geom/monetdb5/Makefile.ag --- a/geom/monetdb5/Makefile.ag +++ b/geom/monetdb5/Makefile.ag @@ -15,7 +15,7 @@ INCLUDES = ../lib \ lib__geom = { MODULE DIR = libdir/monetdb5 - SOURCES = geom.h geom.c geomBulk.c geom_upgrade.c grid.h grid.c + SOURCES = geom.h geom.c geomBulk.c geom_upgrade.c grid.h grid_impl.h grid.c LIBS = ../lib/libgeom \ ../../gdk/libbat \ ../../common/stream/libstream \ @@ -47,4 +47,18 @@ headers_autoload_grid = { SOURCES = 31_grid.mal } +headers_mal_grid_hge = { + COND = HAVE_HGE + HEADERS = mal + DIR = libdir/monetdb5 + SOURCES = grid_hge.mal +} + +headers_autoload_grid_hge = { + COND = HAVE_HGE + HEADERS = mal + DIR = libdir/monetdb5/autoload + SOURCES = 31_grid_hge.mal +} + EXTRA_DIST = 30_geom.mal geom.mal 31_grid.mal grid.mal diff --git a/geom/monetdb5/grid.c b/geom/monetdb5/grid.c --- a/geom/monetdb5/grid.c +++ b/geom/monetdb5/grid.c @@ -13,27 +13,44 @@ #include "grid.h" -#define GRID_VERSION 1 -#define POINTSPERCELL 100000 +static size_t +countSetBits(uint64_t *resBitvector, size_t vectorSize) +{ + size_t num = 0 ; + for(size_t k = 0; k < vectorSize; k++) { + uint64_t b = resBitvector[k]; + for(uint64_t j = 0; j < BITSNUM; j++) { + num += b & 0x01; + b >>= 1; + } + } -#define BITSNUM 64 -#define SHIFT 6 /* division with 64 */ -#define ONES ((1<<(SHIFT))-1) /* 63 */ -#define get(bitVector, bitPos) (((bitVector) >> (bitPos)) & 0x01) -#define set(bitVector, bitPos, value) ((bitVector) |= ((value)<<(bitPos))) -#define setbv(bitVector, bitPos, value) set((bitVector)[(bitPos) >> SHIFT], (bitPos) & ONES, (value)) -#define unset(bitVector, bitPos) ((bitVector) &= ~((uint64_t)1<<(bitPos))) -#define common(bitVector, bitPos, value) ((bitVector) &= (0xFFFFFFFFFFFFFFFF ^ (((1-value))<<(bitPos)))) -#define GRIDcount(g, c) (g)->dir[(c)+1] - (g)->dir[(c)] + return num; +} -#define maximumNumberOfCells(max, bitsNum, add) \ -do { \ - int i = 0; \ - size_t res = 0; \ - for(i = 0; i < bitsNum; i++) \ - res = (res << 1) | 1; \ - max = res + add; \ -} while (0) +#define TP bte +#include "grid_impl.h" +#undef TP +#define TP sht +#include "grid_impl.h" +#undef TP +#define TP int +#include "grid_impl.h" +#undef TP +#define TP lng +#include "grid_impl.h" +#undef TP +#ifdef HAVE_HGE +#define TP hge +#include "grid_impl.h" +#undef TP +#endif +#define TP flt +#include "grid_impl.h" +#undef TP +#define TP dbl +#include "grid_impl.h" +#undef TP #define GRIDextend(g1, g2, cellR, cellS, r1, r2, msg) \ do { \ @@ -65,32 +82,37 @@ do { (r2b) += ddist <= distsqr; \ } while(0) -#define GRIDcmp(x1Vals, y1Vals, g1, \ - x2Vals, y2Vals, g2, \ +#define GRIDcmp(tpe, x1BAT, y1BAT, g1, \ + x2BAT, y2BAT, g2, \ cellR, cellS, r1, r2, seq1, seq2, msg) \ do { \ BUN r1b, r2b; \ + tpe *x1Vals, *y1Vals, *x2Vals, *y2Vals; \ + oid *r1Vals, *r2Vals; \ oid m; \ - lng * r1Vals, * r2Vals; \ if ((cellR) >= (g1)->cellsNum || (cellS) >= (g2)->cellsNum) \ continue; \ GRIDextend(g1, g2, cellR, cellS, r1, r2, msg); \ - r1Vals = (lng*)Tloc(r1, BUNfirst(r1)); \ - r2Vals = (lng*)Tloc(r2, BUNfirst(r2)); \ + x1Vals = (tpe*)Tloc(x1BAT, BUNfirst(x1BAT)); \ + y1Vals = (tpe*)Tloc(y1BAT, BUNfirst(y1BAT)); \ + x2Vals = (tpe*)Tloc(x2BAT, BUNfirst(x2BAT)); \ + y2Vals = (tpe*)Tloc(y2BAT, BUNfirst(y2BAT)); \ + r1Vals = (oid*)Tloc(r1, BUNfirst(r1)); \ + r2Vals = (oid*)Tloc(r2, BUNfirst(r2)); \ r1b = BATcount(r1); \ r2b = BATcount(r2); \ m = (g1)->dir[(cellR)]; \ if (GRIDcount(g1, cellR) > 16) { \ /* compare points of R in cellR with points of S in cellS */ \ - for (; m < (g1)->dir[(cellR)+1]-16; m+=16) { \ + for (; m < (g1)->dir[(cellR)+1]-16; m+=16) { \ for (oid n = (g2)->dir[(cellS)]; n < (g2)->dir[(cellS)+1]; n++) { \ oid oid2 = (g2)->oids[n]; \ - lng x2v = (x2Vals)[oid2]; \ - lng y2v = (y2Vals)[oid2]; \ + tpe x2v = (x2Vals)[oid2]; \ + tpe y2v = (y2Vals)[oid2]; \ for(oid o1 = m; o1 < m+16; o1++) { \ oid oid1 = (g1)->oids[o1]; \ - lng x1v = (x1Vals)[oid1]; \ - lng y1v = (y1Vals)[oid1]; \ + tpe x1v = (x1Vals)[oid1]; \ + tpe y1v = (y1Vals)[oid1]; \ GRIDdist(r1Vals, oid1, seq1, r1b, x1v, y1v, \ r2Vals, oid2, seq2, r2b, x2v, y2v); \ } \ @@ -99,12 +121,12 @@ do { } \ for (; m < (g1)->dir[(cellR)+1]; m++) { \ oid oid1 = (g1)->oids[m]; \ - lng x1v = (x1Vals)[oid1]; \ - lng y1v = (y1Vals)[oid1]; \ + tpe x1v = (x1Vals)[oid1]; \ + tpe y1v = (y1Vals)[oid1]; \ for (oid n = (g2)->dir[(cellS)]; n < (g2)->dir[(cellS)+1]; n++) { \ oid oid2 = (g2)->oids[n]; \ - lng x2v = (x2Vals)[oid2]; \ - lng y2v = (y2Vals)[oid2]; \ + tpe x2v = (x2Vals)[oid2]; \ + tpe y2v = (y2Vals)[oid2]; \ GRIDdist(r1Vals, oid1, seq1, r1b, x1v, y1v, \ r2Vals, oid2, seq2, r2b, x2v, y2v); \ } \ @@ -113,38 +135,30 @@ do { BATsetcount(r2, r2b); \ } while (0) -typedef struct Grid Grid; -struct Grid { - dbl xmin; /* minimum X value of input BATs */ - dbl ymin; /* minimum Y value of input BATs */ - dbl xmax; /* maximum X value of input BATs */ - dbl ymax; /* maximum Y value of input BATs */ - mbr mbb; /* grid universe (might differ from the input values) */ - bte shift; - size_t cellsNum; /* number of cells */ - size_t cellsPerAxis;/* number of cells per axis */ - size_t cellsX; /* number of cells in X axis */ - size_t cellsY; /* number of cells in Y axis */ - bat xbat; /* bat id for X coordinates */ - bat ybat; /* bat id for Y coordinates */ - oid * dir; /* the grid directory */ - oid * oids; /* heap where the index is stored */ -}; +#define GRIDjoin(tpe, \ + x1BAT, y1BAT, g1, x2BAT, y2BAT, g2, \ + R, S, r1, r2, seq1, seq2, msg) \ +do { \ + /* perform the distance join */ \ + for (size_t i = minCellx; i <= maxCellx; i++) { \ + for (size_t j = minCelly; j <= maxCelly; j++) { \ + /* define which cells should be compared */ \ + size_t min = i + g1->cellsX*j; \ + size_t R[] = {min, min, min, min, min+1, min+g1->cellsX, min+g1->cellsX+1}; \ + size_t S[] = {min+g1->cellsX, min+g1->cellsX+1, min+1, min, min, min, min }; \ + for (size_t k = 0; k < 7; k++) { \ + if (GRIDcount(g1,R[k]) > GRIDcount(g2,S[k])) { \ + GRIDcmp(tpe, x1BAT, y1BAT, g1, x2BAT, y2BAT, \ + g2, R[k], S[k], r1, r2, seq1, seq2, msg); \ + } else { \ + GRIDcmp(tpe, x2BAT, y2BAT, g2, x1BAT, y1BAT, \ + g1, S[k], R[k], r2, r1, seq2, seq1, msg); \ + } \ + } \ + } \ + } \ +} while(0) -static size_t -countSetBits(uint64_t *resBitvector, size_t vectorSize) -{ - size_t num = 0 ; - for(size_t k = 0; k < vectorSize; k++) { - uint64_t b = resBitvector[k]; - for(uint64_t j = 0; j < BITSNUM; j++) { - num += b & 0x01; - b >>= 1; - } - } - - return num; -} #if 0 static void grid_print(Grid * g) @@ -202,109 +216,6 @@ grid_print(Grid * g) } #endif -static Grid * -grid_create(BAT *bx, BAT *by) -{ - Grid * g; - lng *xVals, *yVals; - size_t i, cnt; - dbl fxa, fxb, fya, fyb; - - assert(BATcount(bx) == BATcount(by)); - assert(BATcount(bx) > 0); - - if ((g = GDKmalloc(sizeof(Grid))) == NULL) - return g; - - g->xbat = bx->batCacheid; - g->ybat = by->batCacheid; - xVals = (lng*)Tloc(bx, BUNfirst(bx)); - yVals = (lng*)Tloc(by, BUNfirst(by)); - - /* determine the appropriate number of cells */ - g->shift = 2; - maximumNumberOfCells(g->cellsNum, g->shift*2, 1); - maximumNumberOfCells(g->cellsPerAxis, g->shift, 0); - - cnt = BATcount(bx); - while(cnt/g->cellsNum > POINTSPERCELL) { - /* use one more bit per axis */ - g->shift++; - maximumNumberOfCells(g->cellsNum, g->shift*2, 1); - maximumNumberOfCells(g->cellsPerAxis, g->shift, 0); - } - - /* find min and max values for X and y coordinates */ - g->xmin = g->xmax = xVals[0]; - for (i = 1; i < cnt; i++) { - lng val = xVals[i]; - if(g->xmin > val) - g->xmin = val; - if(g->xmax < val) - g->xmax = val; - } - g->ymin = g->ymax = yVals[0]; - for (i = 1; i < cnt; i++) { - lng val = yVals[i]; - if(g->ymin > val) - g->ymin = val; - if(g->ymax < val) - g->ymax = val; - } - - /* allocate space for the directory */ - if ((g->dir = GDKmalloc((g->cellsNum+1)*sizeof(oid))) == NULL) { - GDKfree(g); - g = NULL; - return g; - } - for (i = 0; i < g->cellsNum; i++) _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list