summaryrefslogtreecommitdiff
path: root/src/mongo/db/field_ref_set.cpp
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2013-11-07 12:42:20 -0500
committerScott Hernandez <scotthernandez@gmail.com>2013-11-13 19:30:18 -0500
commitb98712c551e8ab27c33e1a5e7c694fa36c3334ce (patch)
treef4d54911a8fb171ff1275896a1d733eac657e2fb /src/mongo/db/field_ref_set.cpp
parenta87e0ed4ec30725e3ffd7de75c0f204ca0f42b45 (diff)
downloadmongo-b98712c551e8ab27c33e1a5e7c694fa36c3334ce.tar.gz
SERVER-11531, SERVER-10489, SERVER-6835, SERVER-4830: Refactor update system to support immutable fields, consolodate storage validation, and misc issues.
Diffstat (limited to 'src/mongo/db/field_ref_set.cpp')
-rw-r--r--src/mongo/db/field_ref_set.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mongo/db/field_ref_set.cpp b/src/mongo/db/field_ref_set.cpp
index c1a3c79cff5..64c5e178b7a 100644
--- a/src/mongo/db/field_ref_set.cpp
+++ b/src/mongo/db/field_ref_set.cpp
@@ -29,9 +29,12 @@
#include "mongo/db/field_ref_set.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/mongoutils/str.h"
namespace mongo {
+ namespace str = mongoutils::str;
+
namespace {
// For legacy purposes, we must handle empty fieldnames, which FieldRef clearly
@@ -78,6 +81,19 @@ namespace mongo {
}
}
+ void FieldRefSet::keepShortest(const FieldRef* toInsert) {
+ const FieldRef* conflict;
+ if ( !insert(toInsert, &conflict) && (toInsert->numParts() < (conflict->numParts()))) {
+ _fieldSet.erase(conflict);
+ keepShortest(toInsert);
+ }
+ }
+
+ void FieldRefSet::fillFrom(const std::vector<FieldRef*>& fields) {
+ dassert(_fieldSet.empty());
+ _fieldSet.insert(fields.begin(), fields.end());
+ }
+
bool FieldRefSet::insert(const FieldRef* toInsert, const FieldRef** conflict) {
// We can determine if two fields conflict by checking their common prefix.
@@ -118,4 +134,17 @@ namespace mongo {
return true;
}
+ const std::string FieldRefSet::toString() const {
+ str::stream res;
+ res << "Fields:[ ";
+ FieldRefSet::const_iterator where = _fieldSet.begin();
+ const FieldRefSet::const_iterator end = _fieldSet.end();
+ for( ; where != end; ++where ) {
+ const FieldRef& current = **where;
+ res << current.dottedField() << ",";
+ }
+ res << "]";
+ return res;
+ }
+
} // namespace mongo