summaryrefslogtreecommitdiff
path: root/db/matcher.h
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-06-01 12:36:34 -0700
committerAaron <aaron@10gen.com>2010-06-01 12:36:34 -0700
commit0b0fd9cd61a31a600534f563dc03574b76ac033c (patch)
tree6df8bb78b1f313f2827a00b6cdb0cd56b328bcde /db/matcher.h
parente40db913fc43fa3eff61099ed312c1391b4cea9b (diff)
downloadmongo-0b0fd9cd61a31a600534f563dc03574b76ac033c.tar.gz
SERVER-109 construct index matcher from full doc matcher
Diffstat (limited to 'db/matcher.h')
-rw-r--r--db/matcher.h47
1 files changed, 41 insertions, 6 deletions
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;
};