summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/index_bounds.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2014-03-11 10:41:47 -0400
committerBenety Goh <benety@mongodb.com>2014-03-12 10:03:55 -0400
commit79624f53393bc94cff490153f6bc6939ccd076c8 (patch)
tree9625e8b4b57e9548b23f643dde11d004f72fd82f /src/mongo/db/query/index_bounds.cpp
parent057a542daf11a62c1f57b3b406cb8fd33804a831 (diff)
downloadmongo-79624f53393bc94cff490153f6bc6939ccd076c8.tar.gz
SERVER-13100 added test cases for IndexBoundsChecker::findIntervalForField. moved intervalCmp out of header.
Diffstat (limited to 'src/mongo/db/query/index_bounds.cpp')
-rw-r--r--src/mongo/db/query/index_bounds.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/mongo/db/query/index_bounds.cpp b/src/mongo/db/query/index_bounds.cpp
index c6199b1d351..0d3d65ebb0c 100644
--- a/src/mongo/db/query/index_bounds.cpp
+++ b/src/mongo/db/query/index_bounds.cpp
@@ -39,6 +39,26 @@ namespace mongo {
return i > 0 ? 1 : -1;
}
+ /**
+ * Returns BEHIND if the key is behind the interval.
+ * Returns WITHIN if the key is within the interval.
+ * Returns AHEAD if the key is ahead the interval.
+ *
+ * All directions are oriented along 'direction'.
+ */
+ IndexBoundsChecker::Location intervalCmp(const Interval& interval, const BSONElement& key,
+ const int expectedDirection) {
+ int cmp = sgn(key.woCompare(interval.start, false));
+ bool startOK = (cmp == expectedDirection) || (cmp == 0 && interval.startInclusive);
+ if (!startOK) { return IndexBoundsChecker::BEHIND; }
+
+ cmp = sgn(key.woCompare(interval.end, false));
+ bool endOK = (cmp == -expectedDirection) || (cmp == 0 && interval.endInclusive);
+ if (!endOK) { return IndexBoundsChecker::AHEAD; }
+
+ return IndexBoundsChecker::WITHIN;
+ }
+
} // namespace
// For debugging.
@@ -494,21 +514,6 @@ namespace mongo {
}
// static
- IndexBoundsChecker::Location IndexBoundsChecker::intervalCmp(const Interval& interval,
- const BSONElement& key,
- const int expectedDirection) {
- int cmp = sgn(key.woCompare(interval.start, false));
- bool startOK = (cmp == expectedDirection) || (cmp == 0 && interval.startInclusive);
- if (!startOK) { return BEHIND; }
-
- cmp = sgn(key.woCompare(interval.end, false));
- bool endOK = (cmp == -expectedDirection) || (cmp == 0 && interval.endInclusive);
- if (!endOK) { return AHEAD; }
-
- return WITHIN;
- }
-
- // static
IndexBoundsChecker::Location IndexBoundsChecker::findIntervalForField(const BSONElement& elt,
const OrderedIntervalList& oil, const int expectedDirection, size_t* newIntervalIndex) {