summaryrefslogtreecommitdiff
path: root/src/mongo/db/field_ref_set.h
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-09-19 13:30:00 -0400
committerGreg Studer <greg@10gen.com>2014-10-16 18:38:12 -0400
commit22f8b6259602a76f8d22cba8b1098f9e3c90a36f (patch)
tree7cf4bd3d8b5439c4e42ca1be7ee6161a69af73a2 /src/mongo/db/field_ref_set.h
parent02c1c52514c7d6b54ff2d6dd6a3c564c3543f0a5 (diff)
downloadmongo-22f8b6259602a76f8d22cba8b1098f9e3c90a36f.tar.gz
SERVER-14973 consolidate shard key parsing, cleanup shard key patterns
Diffstat (limited to 'src/mongo/db/field_ref_set.h')
-rw-r--r--src/mongo/db/field_ref_set.h25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/mongo/db/field_ref_set.h b/src/mongo/db/field_ref_set.h
index e7258c2a184..0403f9265b2 100644
--- a/src/mongo/db/field_ref_set.h
+++ b/src/mongo/db/field_ref_set.h
@@ -29,6 +29,7 @@
#pragma once
#include <set>
+#include <vector>
#include "mongo/base/disallow_copying.h"
#include "mongo/base/owned_pointer_vector.h"
@@ -38,9 +39,14 @@
namespace mongo {
/**
- * A FieldRefSet holds a set of FieldRefs's that do not conflict with one another, that is,
- * they target different subtrees of a given document. Two fieldRef's would conflict if they
- * are equal or one is prefix of the other.
+ * A FieldRefSet holds a number of unique FieldRefs - a set of dotted paths into a document.
+ *
+ * The FieldRefSet provides helpful functions for efficiently finding conflicts between field
+ * ref paths - field ref paths conflict if they are equal to each other or if one is a prefix.
+ * To maintain a FieldRefSet of non-conflicting paths, always use the insert method which
+ * returns conflicting FieldRefs.
+ *
+ * FieldRefSets do not own the FieldRef paths they contain.
*/
class FieldRefSet {
MONGO_DISALLOW_COPYING(FieldRefSet);
@@ -57,6 +63,8 @@ namespace mongo {
FieldRefSet();
+ FieldRefSet(const std::vector<FieldRef*>& paths);
+
/** Returns 'true' if the set is empty */
bool empty() const {
return _fieldSet.empty();
@@ -71,6 +79,15 @@ namespace mongo {
}
/**
+ * Returns true if the path does not already exist in the set, false otherwise.
+ *
+ * Note that *no* conflict resolution occurs - any path can be inserted into a set.
+ */
+ inline bool insert(const FieldRef* path) {
+ return _fieldSet.insert(path).second;
+ }
+
+ /**
* Returns true if the field 'toInsert' can be added in the set without
* conflicts. Otherwise returns false and fill in '*conflict' with the field 'toInsert'
* clashed with.
@@ -83,6 +100,8 @@ namespace mongo {
/**
* Fills the set with the supplied FieldRef*s
+ *
+ * Note that *no* conflict resolution occurs here.
*/
void fillFrom(const std::vector<FieldRef*>& fields);