[geos-commits] r2410 - in trunk/source: headers/geos/index/quadtree
index/quadtree
svn_geos at osgeo.org
svn_geos at osgeo.org
Mon Apr 27 11:30:52 EDT 2009
Author: strk
Date: 2009-04-27 11:30:52 -0400 (Mon, 27 Apr 2009)
New Revision: 2410
Modified:
trunk/source/headers/geos/index/quadtree/Quadtree.h
trunk/source/index/quadtree/Quadtree.cpp
Log:
Sync to JTS-1.10, reduce heap allocations and pointers usage. Includes a bugfix in collectStats.
Modified: trunk/source/headers/geos/index/quadtree/Quadtree.h
===================================================================
--- trunk/source/headers/geos/index/quadtree/Quadtree.h 2009-04-27 15:00:53 UTC (rev 2409)
+++ trunk/source/headers/geos/index/quadtree/Quadtree.h 2009-04-27 15:30:52 UTC (rev 2410)
@@ -13,7 +13,7 @@
*
**********************************************************************
*
- * Last port: index/quadtree/Quadtree.java rev. 1.14
+ * Last port: index/quadtree/Quadtree.java rev. 1.16 (JTS-1.10)
*
**********************************************************************/
@@ -21,7 +21,7 @@
#define GEOS_IDX_QUADTREE_QUADTREE_H
#include <geos/index/SpatialIndex.h> // for inheritance
-#include <geos/index/quadtree/Root.h> // for inline
+#include <geos/index/quadtree/Root.h> // for composition
#include <vector>
#include <string>
@@ -70,9 +70,9 @@
std::vector<geom::Envelope *> newEnvelopes;
- void collectStats(const geom::Envelope *itemEnv);
+ void collectStats(const geom::Envelope& itemEnv);
- Root *root;
+ Root root;
/**
* Statistics
@@ -104,7 +104,7 @@
*/
Quadtree()
:
- root(new Root()),
+ root(),
minExtent(1.0)
{}
@@ -118,22 +118,57 @@
void insert(const geom::Envelope *itemEnv, void *item);
+ /** \brief
+ * Queries the tree and returns items which may lie
+ * in the given search envelope.
+ *
+ * Precisely, the items that are returned are all items in the tree
+ * whose envelope <b>may</b> intersect the search Envelope.
+ * Note that some items with non-intersecting envelopes may be
+ * returned as well;
+ * the client is responsible for filtering these out.
+ * In most situations there will be many items in the tree which do not
+ * intersect the search envelope and which are not returned - thus
+ * providing improved performance over a simple linear scan.
+ *
+ * @param searchEnv the envelope of the desired query area.
+ * @param ret a vector where items which may intersect the
+ * search envelope are pushed
+ */
void query(const geom::Envelope *searchEnv, std::vector<void*>& ret);
- void query(const geom::Envelope *searchEnv, ItemVisitor& visitor) {
+
+ /** \brief
+ * Queries the tree and visits items which may lie in
+ * the given search envelope.
+ *
+ * Precisely, the items that are visited are all items in the tree
+ * whose envelope <b>may</b> intersect the search Envelope.
+ * Note that some items with non-intersecting envelopes may be
+ * visited as well;
+ * the client is responsible for filtering these out.
+ * In most situations there will be many items in the tree which do not
+ * intersect the search envelope and which are not visited - thus
+ * providing improved performance over a simple linear scan.
+ *
+ * @param searchEnv the envelope of the desired query area.
+ * @param visitor a visitor object which is passed the visited items
+ */
+ void query(const geom::Envelope *searchEnv, ItemVisitor& visitor)
+ {
/*
* the items that are matched are the items in quads which
* overlap the search envelope
*/
- root->visit(searchEnv, visitor);
+ root.visit(searchEnv, visitor);
}
/**
* Removes a single item from the tree.
*
- * @param itemEnv the Envelope of the item to remove
+ * @param itemEnv the Envelope of the item to be removed
* @param item the item to remove
- * @return <code>true</code> if the item was found
+ * @return <code>true</code> if the item was found (and thus removed)
*/
bool remove(const geom::Envelope* itemEnv, void* item);
Modified: trunk/source/index/quadtree/Quadtree.cpp
===================================================================
--- trunk/source/index/quadtree/Quadtree.cpp 2009-04-27 15:00:53 UTC (rev 2409)
+++ trunk/source/index/quadtree/Quadtree.cpp 2009-04-27 15:30:52 UTC (rev 2410)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: index/quadtree/Quadtree.java rev. 1.14
+ * Last port: index/quadtree/Quadtree.java rev. 1.16 (JTS-1.10)
*
**********************************************************************/
@@ -71,41 +71,35 @@
{
for (unsigned int i=0; i<newEnvelopes.size(); i++)
delete newEnvelopes[i];
- delete root;
}
/*public*/
int
Quadtree::depth()
{
- //I don't think it's possible for root to be null. Perhaps we should
- //remove the check. [Jon Aquino]
- //Or make an assertion [Jon Aquino 10/29/2003]
- if (root!=NULL) return root->depth();
- return 0;
+ return root.depth();
}
/*public*/
int
Quadtree::size()
{
- assert(root!=NULL);
- return root->size();
+ return root.size();
}
/*public*/
void
Quadtree::insert(const Envelope *itemEnv, void* item)
{
- collectStats(itemEnv);
+ collectStats(*itemEnv);
Envelope *insertEnv=ensureExtent(itemEnv,minExtent);
if ( insertEnv != itemEnv ) newEnvelopes.push_back(insertEnv);
- root->insert(insertEnv,item);
+ root.insert(insertEnv,item);
#if GEOS_DEBUG
cerr<<"Quadtree::insert("<<itemEnv->toString()<<", "<<item<<")"<<endl;
cerr<<" insertEnv:"<<insertEnv->toString()<<endl;
- cerr<<" tree:"<<endl<<root->toString()<<endl;
+ cerr<<" tree:"<<endl<<root.toString()<<endl;
#endif
}
@@ -119,12 +113,12 @@
* the items that are matched are the items in quads which
* overlap the search envelope
*/
- root->addAllItemsFromOverlapping(*searchEnv, foundItems);
+ root.addAllItemsFromOverlapping(*searchEnv, foundItems);
#if GEOS_DEBUG
cerr<<"Quadtree::query returning "<<foundItems.size()
<<" items over "<<size()
<<" items in index (of depth: "<<depth()<<")"<<endl;
- cerr<<" Root:\n"<<root->toString()<<endl;
+ cerr<<" Root:\n"<<root.toString()<<endl;
#endif
}
@@ -133,7 +127,7 @@
Quadtree::queryAll()
{
vector<void*> *foundItems=new vector<void*>();
- root->addAllItems(*foundItems);
+ root.addAllItems(*foundItems);
return foundItems;
}
@@ -142,28 +136,29 @@
Quadtree::remove(const Envelope* itemEnv, void* item)
{
Envelope* posEnv = ensureExtent(itemEnv, minExtent);
- bool ret = root->remove(posEnv, item);
+ bool ret = root.remove(posEnv, item);
if ( posEnv != itemEnv ) delete posEnv;
return ret;
}
/*private*/
void
-Quadtree::collectStats(const Envelope *itemEnv)
+Quadtree::collectStats(const Envelope& itemEnv)
{
- double delX=itemEnv->getWidth();
- if (delX<minExtent && delX>0.0)
- minExtent=delX;
- double delY=itemEnv->getWidth();
- if (delY<minExtent && delY>0.0)
- minExtent=delY;
+ double delX = itemEnv.getWidth();
+ if (delX < minExtent && delX > 0.0)
+ minExtent = delX;
+
+ double delY = itemEnv.getHeight();
+ if (delY < minExtent && delY > 0.0)
+ minExtent = delY;
}
/*public*/
string
Quadtree::toString() const
{
- string ret = root->toString();
+ string ret = root.toString();
return ret;
}
More information about the geos-commits
mailing list