summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2013-02-27 13:14:40 -0500
committerEliot Horowitz <eliot@10gen.com>2013-02-28 16:44:11 -0500
commitb91edafaec04c2b131a5bca03f05da55fa28c90a (patch)
tree7a6b36fb121b3a8876b568a09fcd2f5a4d1039bf /src
parent9d638fd65a8010d3d357b2cd0bb11e099a222ae8 (diff)
downloadmongo-b91edafaec04c2b131a5bca03f05da55fa28c90a.tar.gz
SERVER-8758 : make IndexSet a set rather than a vector
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/index_set.cpp56
-rw-r--r--src/mongo/db/index_set.h6
2 files changed, 15 insertions, 47 deletions
diff --git a/src/mongo/db/index_set.cpp b/src/mongo/db/index_set.cpp
index f63e404429a..dce6f6d516e 100644
--- a/src/mongo/db/index_set.cpp
+++ b/src/mongo/db/index_set.cpp
@@ -1,7 +1,7 @@
-// index_set.h
+// index_set.cpp
/**
-* Copyright (C) 2008 10gen Inc.
+* Copyright (C) 2013 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
@@ -24,10 +24,10 @@ namespace mongo {
void IndexPathSet::addPath( const StringData& path ) {
string s;
if ( getCanonicalIndexField( path, &s ) ) {
- _canonical.push_back( s );
+ _canonical.insert( s );
}
else {
- _canonical.push_back( path.toString() );
+ _canonical.insert( path.toString() );
}
}
@@ -39,10 +39,13 @@ namespace mongo {
StringData use = path;
string x;
if ( getCanonicalIndexField( path, &x ) )
- use = StringData(x);
+ use = StringData( x );
- for ( unsigned i = 0; i < _canonical.size(); i++ ) {
- StringData idx( _canonical[i] );
+ for ( std::set<string>::const_iterator i = _canonical.begin();
+ i != _canonical.end();
+ ++i ) {
+
+ StringData idx( *i );
if ( use.startsWith( idx ) )
return true;
@@ -56,6 +59,8 @@ namespace mongo {
bool getCanonicalIndexField( const StringData& fullName, string* out ) {
// check if fieldName contains ".$" or ".###" substrings (#=digit) and skip them
+ // however do not skip the first field even if it meets these criteria
+
if ( fullName.find( '.' ) == string::npos )
return false;
@@ -106,40 +111,3 @@ namespace mongo {
}
-#if 0
- /**
- * checks if mod is in the index by inspecting fieldName, and removing
- * .$ or .### substrings (#=digit) with any number of digits.
- *
- * @return true iff the mod is indexed
- */
- bool isIndexed( const set<string>& idxKeys ) const {
-
- // first, check if full name is in idxKeys
- if ( isIndexed( fieldName , idxKeys ) )
- return true;
-
- string x;
- if ( getCanonicalIndexField( fieldName, &x ) ) {
- if ( isIndexed( x, idxKeys ) )
- return true;
- }
-
- return false;
- }
-
-
- static bool isIndexed( const string& fullName , const set<string>& idxKeys ) {
- const char * fieldName = fullName.c_str();
- // check if there is an index key that is a parent of mod
- for( const char* dot = strchr( fieldName, '.' ); dot; dot = strchr( dot + 1, '.' ) )
- if ( idxKeys.count( string( fieldName, dot - fieldName ) ) )
- return true;
-
- // check if there is an index key equal to mod
- if ( idxKeys.count(fullName) )
- return true;
-
- return false;
- }
-#endif
diff --git a/src/mongo/db/index_set.h b/src/mongo/db/index_set.h
index 51e941c2033..24717750e9a 100644
--- a/src/mongo/db/index_set.h
+++ b/src/mongo/db/index_set.h
@@ -1,7 +1,7 @@
// index_set.h
/**
-* Copyright (C) 2008 10gen Inc.
+* Copyright (C) 2013 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
@@ -18,7 +18,7 @@
#pragma once
-#include <vector>
+#include <set>
#include "mongo/base/string_data.h"
@@ -39,7 +39,7 @@ namespace mongo {
bool mightBeIndexed( const StringData& path ) const;
private:
- std::vector<std::string> _canonical;
+ std::set<std::string> _canonical;
};
}