assert( i<j );
p->aPoint[i] = p->aPoint[j];
p->aPoint[j] = t;
- if( i<RTREE_CACHE_SZ-1 ){
- if( j>=RTREE_CACHE_SZ-1 ){
- nodeRelease(RTREE_OF_CURSOR(p), p->aNode[i+1]);
- p->aNode[i+1] = 0;
+ i++; j++;
+ if( i<RTREE_CACHE_SZ ){
+ if( j>=RTREE_CACHE_SZ ){
+ nodeRelease(RTREE_OF_CURSOR(p), p->aNode[i]);
+ p->aNode[i] = 0;
}else{
- RtreeNode *pTemp = p->aNode[i+i];
- p->aNode[i+1] = p->aNode[j+1];
- p->aNode[j+1] = pTemp;
+ RtreeNode *pTemp = p->aNode[i];
+ p->aNode[i] = p->aNode[j];
+ p->aNode[j] = pTemp;
}
}
}
|| (pFirst->rScore==rScore && pFirst->iLevel>iLevel)
){
if( pCur->bPoint ){
+ int ii;
pNew = rtreeEnqueue(pCur, rScore, iLevel);
if( pNew==0 ) return 0;
- assert( pCur->aNode[1]==0 );
- pCur->aNode[1] = pCur->aNode[0];
+ ii = (int)(pNew - pCur->aPoint) + 1;
+ if( ii<RTREE_CACHE_SZ ){
+ assert( pCur->aNode[ii]==0 );
+ pCur->aNode[ii] = pCur->aNode[0];
+ }else{
+ nodeRelease(RTREE_OF_CURSOR(pCur), pCur->aNode[0]);
+ }
pCur->aNode[0] = 0;
*pNew = pCur->sPoint;
}
}
}
-static void traceTop(RtreeCursor *pCur, const char *zPrefix){
- RtreeSearchPoint *p = rtreeSearchPointFirst(pCur);
- if( p ){
- printf("=== %6s id=%lld lvl=%d iCell=%d rScore=%g eWithin=%d\n",
- zPrefix, p->id, p->iLevel, p->iCell, p->rScore, p->eWithin);
+#if 0
+/* Tracing routines for the RtreeSearchPoint queue */
+static void tracePoint(RtreeSearchPoint *p, int idx, RtreeCursor *pCur){
+ if( idx<0 ){ printf(" s"); }else{ printf("%2d", idx); }
+ printf(" %d.%05lld.%02d %g %d",
+ p->iLevel, p->id, p->iCell, p->rScore, p->eWithin
+ );
+ idx++;
+ if( idx<RTREE_CACHE_SZ ){
+ printf(" %p\n", pCur->aNode[idx]);
+ }else{
+ printf("\n");
+ }
+}
+static void traceQueue(RtreeCursor *pCur, const char *zPrefix){
+ int ii;
+ printf("=== %9s ", zPrefix);
+ if( pCur->bPoint ){
+ tracePoint(&pCur->sPoint, -1, pCur);
+ }
+ for(ii=0; ii<pCur->nPoint; ii++){
+ if( ii>0 || pCur->bPoint ) printf(" ");
+ tracePoint(&pCur->aPoint[ii], ii, pCur);
}
}
+#else
+# define RTREE_QUEUE_TRACE(A,B) /* no-op */
+#endif
/* Remove the search point with the lowest current score.
*/
}else if( p->nPoint ){
n = --p->nPoint;
p->aPoint[0] = p->aPoint[n];
+ if( n<RTREE_CACHE_SZ-1 ){
+ p->aNode[1] = p->aNode[n+1];
+ p->aNode[n+1] = 0;
+ }
i = 0;
while( (j = i*2+1)<n ){
k = j+1;
if( rc ) return rc;
x = *p;
p->iCell++;
+ if( eWithin==NOT_WITHIN ) continue;
if( p->iCell>=nCell ){
-traceTop(pCur, "POP:");
+ RTREE_QUEUE_TRACE(pCur, "POP-S:");
rtreeSearchPointPop(pCur);
}
- if( eWithin==NOT_WITHIN ) continue;
pNew = rtreeSearchPointNew(pCur, /*rScore*/0.0, x.iLevel-1);
if( pNew==0 ) return SQLITE_NOMEM;
pNew->eWithin = eWithin;
pNew->id = x.id;
pNew->iCell = x.iCell;
}
-traceTop(pCur, "PUSH:");
+ p = pNew;
+ RTREE_QUEUE_TRACE(pCur, "PUSH-S:");
break;
}
+ if( p->iCell>=nCell ){
+ RTREE_QUEUE_TRACE(pCur, "POP-Se:");
+ rtreeSearchPointPop(pCur);
+ }
}
pCur->atEOF = p==0;
return SQLITE_OK;
int rc = SQLITE_OK;
/* Move to the next entry that matches the configured constraints. */
-traceTop(pCsr, "POP:");
+ RTREE_QUEUE_TRACE(pCsr, "POP-Nx:");
rtreeSearchPointPop(pCsr);
rtreeStepToLeaf(pCsr);
return rc;
p->eWithin = PARTLY_WITHIN;
if( rc ) rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
p->iCell = iCell;
-traceTop(pCsr, "PUSH:");
+ RTREE_QUEUE_TRACE(pCsr, "PUSH-F1:");
}else{
/* Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
** with the configured constraints.
pNew->eWithin = PARTLY_WITHIN;
assert( pCsr->bPoint==1 );
pCsr->aNode[0] = pRoot;
-traceTop(pCsr, "PUSH:");
+ RTREE_QUEUE_TRACE(pCsr, "PUSH-Fm:");
rc = rtreeStepToLeaf(pCsr);
}
}
nCell = (int)strlen(zCell);
for(jj=0; jj<tree.nDim*2; jj++){
#ifndef SQLITE_RTREE_INT_ONLY
- sqlite3_snprintf(512-nCell,&zCell[nCell], " %f",
+ sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
(double)cell.aCoord[jj].f);
#else
sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
-C Initial\sattempt\sat\sgetting\sR-Tree\squeries\sto\swork\susing\sa\spriority\squeue.\nThis\scheck-in\scompiles,\sbut\sR-Trees\sdo\snot\swork\swell.\s\sAnd\sthere\sare\ndebugging\sprintf()s\sleft\sin\sthe\scode.\s\sThis\sis\san\sincremental\scheck-in.
-D 2014-04-15T21:06:14.359
+C Bug\sfixes\sto\sthe\spriority-queue\simplementation\sfor\sR-Trees.\s\sImproved\stracing\ncapability.\s\sSome\squeries\swork\snow,\sbut\sstill\smany\sproblems.
+D 2014-04-16T13:00:08.915
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in e4ee6d36cdf6136aee0158675a3b24dd3bf31a5a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F ext/misc/vtshim.c babb0dc2bf116029e3e7c9a618b8a1377045303e
F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
-F ext/rtree/rtree.c 2f4d35a0689d588698cd0dd7d513761dff20c8fa
+F ext/rtree/rtree.c 3105c5514d6dbf99c39aceac84c4c0f9e00f90ea
F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e
F ext/rtree/rtree1.test cf679265ecafff494a768ac9c2f43a70915a6290
F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P ade5b986e8baab9df7bdaf7ccfaee2d6ba55fa3c
-R 52e87385ec75daf64fa5f31a0250db29
-T *branch * rtree-queue
-T *sym-rtree-queue *
-T -sym-rtree-enhancements *
+P 53688a25c23c394278a357829793889970aa4157
+R 67a30187386908beb1eb82f50c3b2dfd
U drh
-Z d0176a391caa75c92333b568fa6cbbbf
+Z ba82d149b9f56c655f1e6f2a959cfc71