From 0b0fd9cd61a31a600534f563dc03574b76ac033c Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 1 Jun 2010 12:36:34 -0700 Subject: SERVER-109 construct index matcher from full doc matcher --- db/matcher.h | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'db/matcher.h') diff --git a/db/matcher.h b/db/matcher.h index d57f3c43684..c9e7896a88c 100644 --- a/db/matcher.h +++ b/db/matcher.h @@ -138,6 +138,8 @@ namespace mongo { // index keys having empty string field names. Matcher(const BSONObj &pattern, const BSONObj &constrainIndexKey = BSONObj(), bool subMatcher = false); + Matcher( const Matcher &other, const BSONObj &constrainIndexKey ); + ~Matcher(); bool matches(const BSONObj& j, MatchDetails * details = 0 ); @@ -153,11 +155,44 @@ namespace mongo { return jsobj.toString(); } -// void popOr() { -// massert( 13261, "no or to pop", !_orMatchers.empty() ); -// _norMatchers.push_back( _orMatchers.front() ); -// _orMatchers.pop_front(); -// } + void popOr() { + massert( 13261, "no or to pop", !_orMatchers.empty() ); + _norMatchers.push_back( _orMatchers.front() ); + _orMatchers.pop_front(); + } + + bool sameCriteriaCount( const Matcher &other ) const { + if ( !( basics.size() == other.basics.size() && nRegex == other.nRegex && !where == !other.where ) ) { + return false; + } + if ( _norMatchers.size() != other._norMatchers.size() ) { + return false; + } + if ( _orMatchers.size() != other._orMatchers.size() ) { + return false; + } + { + list< shared_ptr< Matcher > >::const_iterator i = _norMatchers.begin(); + list< shared_ptr< Matcher > >::const_iterator j = other._norMatchers.begin(); + while( i != _norMatchers.end() ) { + if ( !(*i)->sameCriteriaCount( **j ) ) { + return false; + } + ++i; ++j; + } + } + { + list< shared_ptr< Matcher > >::const_iterator i = _orMatchers.begin(); + list< shared_ptr< Matcher > >::const_iterator j = other._orMatchers.begin(); + while( i != _orMatchers.end() ) { + if ( !(*i)->sameCriteriaCount( **j ) ) { + return false; + } + ++i; ++j; + } + } + return true; + } private: void addBasic(const BSONElement &e, int c, bool isNot) { @@ -213,8 +248,8 @@ namespace mongo { Matcher& docMatcher() { return _docMatcher; } private: - Matcher _keyMatcher; Matcher _docMatcher; + Matcher _keyMatcher; bool _needRecord; }; -- cgit v1.2.1