1
0
Fork 0

Cursors seem to be working

This commit is contained in:
Richard Parker 2015-12-16 08:50:12 +00:00
parent c96599b7ce
commit 93c59c81b1
2 changed files with 63 additions and 10 deletions

View File

@ -1,4 +1,4 @@
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// @brief geo index
///
/// @file
@ -123,6 +123,17 @@ int GCMASS (GeoCoordinates * gc, int ct, int hash) {
j=j*7;
j=j%123456791;
}
if(hash!=j)
{
for(i=0;i<(int) gc->length;i++)
{
printf("long %14.9f",gc->coordinates[i].longitude);
printf(" lat %14.9f",gc->coordinates[i].latitude);
printf(" dat %4d",(int)((char *)gc->coordinates[i].data-ix));
printf(" dist %12.1f \n",gc->distances[i]);
}
printf("Correct hash is %d\n",j);
}
GeoIndex_CoordinatesFree(gc);
return hash == j ? 1 : 0;
@ -265,6 +276,51 @@ BOOST_FIXTURE_TEST_SUITE(GeoIndexTest, GeoIndexSetup)
/* 3 is Auckland -36.916667 +174.783333 */
/* 4 is Jo'burg -26.166667 +28.033333 */
/***********************************/
/* 1000-1100 first tests on cursor */
BOOST_AUTO_TEST_CASE (tst_geo1000) {
gi=GeoIndex_new();
la=41.23456789;
lo=39.87654321;
for(j=1;j<50;j++)
{
gcp.latitude = la;
gcp.longitude= lo;
gcp.data = &ix[j];
r = GeoIndex_insert(gi,&gcp);
icheck(1000,0,r);
la+=19.5396157761;
if(la>90.0) la-=180.0;
lo+=17.2329155421;
if(lo>180) lo-=360.0;
}
gcp.latitude = 0.0;
gcp.longitude= 25.5;
gcr = GeoIndex_NewCursor(gi,&gcp);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1001,list1,5, 87399654);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1002,list1,5, 97583446);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1003,list1,5, 30565728);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1004,list1,5, 77530526);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1005,list1,5, 38005425);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1006,list1,5, 106050772);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1007,list1,5, 51101201);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1008,list1,5, 83277910);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1009,list1,5, 53245966);
list1 = GeoIndex_ReadCursor(gcr,5);
gcmass(1010,list1,4, 86589238);
MyFree(gi);
}
/***************************************/
BOOST_AUTO_TEST_CASE (tst_geo1) {
gcp1.latitude = 51.5;
gcp1.longitude = -0.166666;
@ -1287,6 +1343,7 @@ BOOST_AUTO_TEST_CASE (tst_geo900) {
MyFree(gi);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief generate tests
////////////////////////////////////////////////////////////////////////////////

View File

@ -2158,7 +2158,7 @@ typedef struct {
bool hpotcompare(hpot a, hpot b)
{
if(a.dist<b.dist) return true;
if(a.dist>b.dist) return true;
else return false;
}
@ -2169,7 +2169,7 @@ typedef struct {
bool hslotcompare(hslot a, hslot b)
{
if(a.snmd<b.snmd) return true;
if(a.snmd>b.snmd) return true;
else return false;
}
@ -2193,7 +2193,6 @@ GeoFix makedist(GeoPot * pot, GeoDetailedPoint * gd)
d1=gd->fixdist[i]-pot->maxdist[i];
else d1=0;
if(d1>dist) dist=d1;
printf("makedist %d %u %u %u\n",i,dist,gd->fixdist[i],pot->maxdist[i]);
}
return dist;
}
@ -2242,22 +2241,17 @@ GeoCoordinates * GeoIndex_ReadCursor(GeoCursor * gc, int count)
if(gr==NULL) return NULL;
while(gr->pointsct<count)
{
printf("pots %10.8f points %10.8f\n",gcr->potsnmd,gcr->slotsnmd);
if(gcr->potsnmd < gcr->slotsnmd*1.000001)
{
// smash top pot - if there is one
if(gcr->potheap.size()==0) break; // that's all there is
printf("potheapsiz1 is %ld\n",gcr->potheap.size()); // that's all there is
pot=*((gcr->Ix)->pots+(gcr->potheap.front().pot));
// anyway remove top from heap
printf("potheapsiz2 is %ld\n",gcr->potheap.size()); // that's all there is
std::pop_heap(gcr->potheap.begin(),
gcr->potheap.end(),hpotcompare);
gcr->potheap.pop_back();
printf("potheapsiz3 is %ld\n",gcr->potheap.size()); // that's all there is
if(pot.LorLeaf==0)
{
printf("Leaf pot\n");
// leaf pot - put all the points into the points heap
for(i=0;i<pot.RorPoints;i++)
{
@ -2277,7 +2271,6 @@ printf("Leaf pot\n");
}
else
{
printf("Non-leaf pot\n");
hp.pot=pot.LorLeaf;
hp.dist = makedist((gcr->Ix)->pots+pot.LorLeaf,&(gcr->gd));
gcr->potheap.push_back(hp);
@ -2313,6 +2306,9 @@ printf("Non-leaf pot\n");
gr->snmd[gr->pointsct]=tsnmd;
gr->pointsct++;
gcr->slotsnmd=5.0;
std::pop_heap(gcr->slotheap.begin(),
gcr->slotheap.end(),hslotcompare);
gcr->slotheap.pop_back();
if(gcr->slotheap.size()!=0)
{
slox=gcr->slotheap.front().slot;