summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec/and_common-inl.h
diff options
context:
space:
mode:
authorHari Khalsa <hkhalsa@10gen.com>2013-07-02 20:01:25 -0400
committerHari Khalsa <hkhalsa@10gen.com>2013-07-05 16:42:23 -0400
commit3ac4551322eb2307e4957b4a1014f03768b17a82 (patch)
treea15f6b319e9a65b0b91672bae2e50d34df311254 /src/mongo/db/exec/and_common-inl.h
parent1961a5d66cee7d9bc102cc2ff6f189c4c4306895 (diff)
downloadmongo-3ac4551322eb2307e4957b4a1014f03768b17a82.tar.gz
SERVER-10026 index intersection hashed and sorted
Diffstat (limited to 'src/mongo/db/exec/and_common-inl.h')
-rw-r--r--src/mongo/db/exec/and_common-inl.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/mongo/db/exec/and_common-inl.h b/src/mongo/db/exec/and_common-inl.h
new file mode 100644
index 00000000000..364936e92e9
--- /dev/null
+++ b/src/mongo/db/exec/and_common-inl.h
@@ -0,0 +1,45 @@
+/**
+ * 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,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace mongo {
+
+ class AndCommon {
+ public:
+ /**
+ * If src has any data dest doesn't, add that data to dest.
+ */
+ static void mergeFrom(WorkingSetMember* dest, WorkingSetMember* src) {
+ verify(dest->hasLoc());
+ verify(src->hasLoc());
+ verify(dest->loc == src->loc);
+
+ // This is N^2 but N is probably pretty small. Easy enough to revisit.
+ // Merge key data.
+ for (size_t i = 0; i < src->keyData.size(); ++i) {
+ bool found = false;
+ for (size_t j = 0; j < dest->keyData.size(); ++j) {
+ if (dest->keyData[j].indexKeyPattern == src->keyData[i].indexKeyPattern) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) { dest->keyData.push_back(src->keyData[i]); }
+ }
+ }
+ };
+
+} // namespace mongo
+