summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2010-08-26 17:28:08 -0400
committerMathias Stearn <mathias@10gen.com>2010-09-02 20:12:37 -0400
commit0acaa65fc7c1302ee7711dbaaecc3f91fbadd38b (patch)
treeaa6b5a5720dced1f8482d4dd750aa2b913077e57
parentc6a123f3e8483f4afc563275648a9a26e57fa5a1 (diff)
downloadmongo-0acaa65fc7c1302ee7711dbaaecc3f91fbadd38b.tar.gz
probably faster to cache farthest() SERVER-1342
-rw-r--r--db/geo/2d.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/db/geo/2d.cpp b/db/geo/2d.cpp
index f95c9b87252..f754b262b09 100644
--- a/db/geo/2d.cpp
+++ b/db/geo/2d.cpp
@@ -727,7 +727,7 @@ namespace mongo {
typedef multiset<GeoPoint> Holder;
GeoHopper( const Geo2dType * g , unsigned max , const Point& n , const BSONObj& filter = BSONObj() , double maxDistance = numeric_limits<double>::max() , GeoDistType type=GEO_PLAIN)
- : GeoAccumulator( g , filter ) , _max( max ) , _near( n ), _maxDistance( maxDistance ), _type( type )
+ : GeoAccumulator( g , filter ) , _max( max ) , _near( n ), _maxDistance( maxDistance ), _type( type ), _farthest(-1)
{}
virtual bool checkDistance( const GeoHash& h , double& d ){
@@ -752,23 +752,27 @@ namespace mongo {
_points.insert( GeoPoint( node.key , node.recordLoc , d ) );
if ( _points.size() > _max ){
_points.erase( --_points.end() );
+
+ Holder::iterator i = _points.end();
+ i--;
+ _farthest = i->_distance;
+ } else {
+ if (d > _farthest)
+ _farthest = d;
}
}
double farthest() const {
- if (_points.empty())
- return -1;
-
- Holder::iterator i = _points.end();
- i--;
- return i->_distance;
+ return _farthest;
}
+
unsigned _max;
Point _near;
Holder _points;
double _maxDistance;
GeoDistType _type;
+ double _farthest;
};
struct BtreeLocation {