Changeset: 3996d471c1bc for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3996d471c1bc
Modified Files:
geom/monetdb5/grid.c
Branch: grid
Log Message:
clean up
diffs (172 lines):
diff --git a/geom/monetdb5/grid.c b/geom/monetdb5/grid.c
--- a/geom/monetdb5/grid.c
+++ b/geom/monetdb5/grid.c
@@ -931,168 +931,3 @@ distancejoin_fail:
if (r2) BBPunfix(r2->batCacheid);
goto distancejoin_clean;
}
-
-#if 0
-/* The commented version below:
- * - does not use a bit vector for storing the results
- * - does not use candidates
- * - ignores the anti parameter
- * - the index is stored as an OID array */
-str
-GRIDdistancesubselect(bat * res, bat * x1, bat * y1, bat * cand1, lng * x2,
lng * y2, int * d, bit * anti)
-{
- size_t minCellx, minCelly, maxCellx, maxCelly, cellx, celly;
- size_t *borderCells, *internalCells;
- size_t borderCellsNum, internalCellsNum, totalCellsNum;
- size_t i, j;
- double fxa, fxb, fya, fyb;
- BAT *x1BAT = NULL, *y1BAT = NULL;
- lng * x1Vals = NULL, * y1Vals = NULL, * resVals = NULL;
- grid * g = NULL;
- mbr mbb = (mbr) {.xmin = *x2 - *d, .ymin = *y2 - *d, .xmax = *x2 + *d,
.ymax = *y2 + *d};
- BAT *r;
- BUN resNum = 0;
- assert (*d > 0);
-
- (void)anti; //TODO: anti
-
- /* get the X and Y BATs*/
- if((x1BAT = BATdescriptor(*x1)) == NULL)
- throw(MAL, "grid.distance", RUNTIME_OBJECT_MISSING);
- if((y1BAT = BATdescriptor(*y1)) == NULL) {
- BBPunfix(x1BAT->batCacheid);
- throw(MAL, "grid.distance", RUNTIME_OBJECT_MISSING);
- }
- x1Vals = (lng*)Tloc(x1BAT, BUNfirst(x1BAT));
- y1Vals = (lng*)Tloc(y1BAT, BUNfirst(y1BAT));
-
- /* check if the BATs have dense heads and are aligned */
- if (!BAThdense(x1BAT) || !BAThdense(y1BAT)) {
- BBPunfix(x1BAT->batCacheid);
- BBPunfix(y1BAT->batCacheid);
- return createException(MAL, "grid.distance", "BATs must have
dense heads");
- }
- if(x1BAT->hseqbase != y1BAT->hseqbase || BATcount(x1BAT) !=
BATcount(y1BAT)) {
- BBPunfix(x1BAT->batCacheid);
- BBPunfix(y1BAT->batCacheid);
- return createException(MAL, "grid.distance", "BATs must be
aligned");
- }
-
- /* compute the grid index */
- if((g = grid_create(x1BAT, y1BAT)) == NULL) {
- BBPunfix(x1BAT->batCacheid);
- BBPunfix(y1BAT->batCacheid);
- return createException(MAL, "grid.distance", "Could not compute
the grid index");
- }
-
- /* find which cells have to be examined */
- fxa = ((double)g->cellsPerAxis/(double)(g->xmax-g->xmin));
- fxb = (double)g->xmin*fxa;
- fya = ((double)g->cellsPerAxis/(double)(g->ymax-g->ymin));
- fyb = (double)g->ymin*fya;
-
- minCellx = (double)(mbb.xmin<g->xmin?g->xmin:mbb.xmin)*fxa - fxb;
- maxCellx = (double)(mbb.xmax>g->xmax?g->xmax:mbb.xmax)*fxa - fxb;
- minCelly = (double)(mbb.ymin<g->ymin?g->ymin:mbb.ymin)*fya - fyb;
- maxCelly = (double)(mbb.ymax>g->ymax?g->ymax:mbb.ymax)*fya - fyb;
-
- /* split the cells in border and internal ones */
- totalCellsNum = (maxCellx - minCellx + 1)*(maxCelly - minCelly + 1);
- borderCellsNum = (maxCellx - minCellx + 1) + (maxCelly - minCelly + 1)
- 1; /* per axis, remove the corner cell that has been added twice */
- if(maxCellx > minCellx && maxCelly > minCelly)
- borderCellsNum = borderCellsNum*2 - 2; /* subtract the two
corner cells that have been added twice */
- internalCellsNum = totalCellsNum - borderCellsNum;
-
- if((borderCells = (size_t*)GDKmalloc((borderCellsNum + 1) *
sizeof(size_t*))) == NULL) {
- BBPunfix(x1BAT->batCacheid);
- BBPunfix(y1BAT->batCacheid);
- return createException(MAL, "grid.distance", MAL_MALLOC_FAIL);
- }
- if((internalCells = (size_t*)GDKmalloc((internalCellsNum + 1) *
sizeof(size_t*))) == NULL) {
- BBPunfix(x1BAT->batCacheid);
- BBPunfix(y1BAT->batCacheid);
- GDKfree(borderCells);
- return createException(MAL, "grid.distance", MAL_MALLOC_FAIL);
- }
-
- borderCellsNum = 0;
- internalCellsNum = 0;
- for(cellx = minCellx ; cellx <= maxCellx; cellx++) {
- for(celly = minCelly ; celly <= maxCelly ; celly++) {
- size_t cellId = (cellx << g->shift) | celly;
- unsigned short border = (cellx == minCellx) | (cellx ==
maxCellx) | (celly == minCelly) | (celly == maxCelly);
- borderCells[borderCellsNum] = cellId;
- internalCells[internalCellsNum] = cellId;
- borderCellsNum += border;
- internalCellsNum += 1 - border;
- }
- }
-
- /* count number of results from internal cells */
- for (i = 0; i < internalCellsNum; i++)
- resNum += g->dir[i+1] - g->dir[i];
-
- /* count number of results from border cells */
- for (i = 0; i < borderCellsNum; i++) {
- size_t cellId = borderCells[i];
- size_t offsetStartIdx = g->dir[cellId];
- size_t offsetEndIdx = g->dir[cellId+1]; /* exclusive */
- for(j = offsetStartIdx; j < offsetEndIdx; j++) {
- size_t oid = g->oids[j];
- resNum += (mbb.xmin <= x1Vals[oid]) & (mbb.xmax
>= x1Vals[oid]) &
- (mbb.ymin <= y1Vals[oid]) &
(mbb.ymax >= y1Vals[oid]);
- }
- }
-
- /* allocate a BAT for the results */
- if ((r = BATnew(TYPE_void, TYPE_oid, resNum, TRANSIENT)) == NULL) {
- BBPunfix(x1BAT->batCacheid);
- BBPunfix(y1BAT->batCacheid);
- GDKfree(borderCells);
- GDKfree(internalCells);
- return createException(MAL, "grid.distance", "could not create
a BAT for storing the results");
- }
- resVals = (lng*)Tloc(r, BUNfirst(r));
-
- /* process cells along the border */
- resNum = 0;
- for (i = 0; i < borderCellsNum; i++) {
- size_t cellId = borderCells[i];
- size_t offsetStartIdx = g->dir[cellId];
- size_t offsetEndIdx = g->dir[cellId+1]; /* exclusive */
- for(j = offsetStartIdx; j < offsetEndIdx; j++) {
- size_t oid = g->oids[j];
- resVals[resNum] = oid;
- resNum += (mbb.xmin <= x1Vals[oid]) & (mbb.xmax
>= x1Vals[oid]) &
- (mbb.ymin <= y1Vals[oid]) &
(mbb.ymax >= y1Vals[oid]);
- }
- }
-
- /* process internal cells */
- for (i = 0; i < internalCellsNum; i++) {
- size_t cellId = internalCells[i];
- size_t offsetStartIdx = g->dir[cellId];
- size_t offsetEndIdx = g->dir[cellId+1]; /* exclusive */
- memcpy(resVals+resNum, g->oids+offsetStartIdx,
(offsetEndIdx-offsetStartIdx)*sizeof(oid));
- }
- GDKqsort(resVals, NULL, NULL, (size_t) resNum, sizeof(oid), 0,
TYPE_oid);
- BATsetcount(r, resNum);
-
- /* clean up */
- BBPunfix(x1BAT->batCacheid);
- BBPunfix(y1BAT->batCacheid);
- GDKfree(borderCells);
- GDKfree(internalCells);
- GDKfree(g->oids);
- GDKfree(g->dir);
- GDKfree(g);
- //BATderiveProps(r, false);
- r->tsorted = true;
- r->trevsorted = false;
- *res = r->batCacheid;
- BBPkeepref(*res);
-
-
- return MAL_SUCCEED;
-}
-#endif
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list