diff options
author | Aaron <aaron@10gen.com> | 2010-06-08 00:33:56 -0700 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2010-06-08 00:33:56 -0700 |
commit | 15179bc5917f7635293c92c93095e4982d370281 (patch) | |
tree | 8933cffa4c97cf296dff1f75f6ab52d771b8c951 /db/queryutil.cpp | |
parent | 1f84e41c344d4ef0e8caa02ed7bf00fcf8cf3b76 (diff) | |
download | mongo-15179bc5917f7635293c92c93095e4982d370281.tar.gz |
SERVER-109 begin interval diff
Diffstat (limited to 'db/queryutil.cpp')
-rw-r--r-- | db/queryutil.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/db/queryutil.cpp b/db/queryutil.cpp index 9e17b44bdd6..385bfa98817 100644 --- a/db/queryutil.cpp +++ b/db/queryutil.cpp @@ -442,26 +442,44 @@ namespace mongo { return *this; } + //TODO finish const FieldRange &FieldRange::operator-=( const FieldRange &other ) { - // TODO implement - return *this; - - vector< FieldInterval > newIntervals; - vector< FieldInterval >::const_iterator i = _intervals.begin(); + vector< FieldInterval >::iterator i = _intervals.begin(); vector< FieldInterval >::const_iterator j = other._intervals.begin(); while( i != _intervals.end() && j != other._intervals.end() ) { + // TODO endpoints int cmp = i->_lower._bound.woCompare( j->_lower._bound, false ); if ( cmp < 0 ) { int cmp2 = i->_upper._bound.woCompare( j->_lower._bound, false ); - if ( cmp2 < 0 ) { - + if ( cmp2 <= 0 ) { + ++i; + } else { + int cmp3 = i->_upper._bound.woCompare( j->_upper._bound, false ); + if ( cmp3 <= 0 ) { + i->_upper = j->_lower; + i->_upper.flipInclusive(); + ++i; + } else { + ++j; + } } + } else { + int cmp2 = i->_lower._bound.woCompare( j->_upper._bound, false ); + if ( cmp2 > 0 ) { + ++j; + } else { + int cmp3 = i->_upper._bound.woCompare( j->_upper._bound, false ); + if ( cmp3 < 0 ) { + i = _intervals.erase( i ); + } else { + i->_lower = j->_upper; + i->_lower.flipInclusive(); + ++j; + } + } } } - while( i != _intervals.end() ) { - newIntervals.push_back( *i ); - } - finishOperation( newIntervals, other ); + finishOperation( _intervals, other ); return *this; } |