diff options
author | Bernard Gorman <bernard.gorman@gmail.com> | 2018-09-21 04:12:00 +0100 |
---|---|---|
committer | Bernard Gorman <bernard.gorman@gmail.com> | 2018-09-22 01:09:31 +0100 |
commit | 10a0d12e9ea977660eb247143b09ecfdc51d05ea (patch) | |
tree | b7cacf5ae9fc8d81f1905cdf4969ce57fb167c1b /src/mongo/db/field_ref.cpp | |
parent | a8995601144d16fe6c762624f64f5690b5caf684 (diff) | |
download | mongo-10a0d12e9ea977660eb247143b09ecfdc51d05ea.tar.gz |
SERVER-35493 Planning support for "field name or array index" path components in wildcard indexes
Diffstat (limited to 'src/mongo/db/field_ref.cpp')
-rw-r--r-- | src/mongo/db/field_ref.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/mongo/db/field_ref.cpp b/src/mongo/db/field_ref.cpp index 2e905090307..1bce17b20e7 100644 --- a/src/mongo/db/field_ref.cpp +++ b/src/mongo/db/field_ref.cpp @@ -26,9 +26,12 @@ * it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/db/field_ref.h" -#include <algorithm> // for min +#include <algorithm> +#include <cctype> #include "mongo/util/assert_util.h" @@ -226,6 +229,10 @@ bool FieldRef::isPrefixOf(const FieldRef& other) const { return common == _size && other._size > common; } +bool FieldRef::isPrefixOfOrEqualTo(const FieldRef& other) const { + return isPrefixOf(other) || *this == other; +} + size_t FieldRef::commonPrefixSize(const FieldRef& other) const { if (_size == 0 || other._size == 0) { return 0; @@ -244,6 +251,32 @@ size_t FieldRef::commonPrefixSize(const FieldRef& other) const { return prefixSize; } +bool FieldRef::isNumericPathComponent(StringData component) { + return !component.empty() && !(component.size() > 1 && component[0] == '0') && + std::all_of(component.begin(), component.end(), [](auto c) { return std::isdigit(c); }); +} + +bool FieldRef::isNumericPathComponent(size_t i) const { + return FieldRef::isNumericPathComponent(getPart(i)); +} + +bool FieldRef::hasNumericPathComponents() const { + for (size_t i = 0; i < numParts(); ++i) { + if (isNumericPathComponent(i)) + return true; + } + return false; +} + +std::set<size_t> FieldRef::getNumericPathComponents(size_t startPart) const { + std::set<size_t> numericPathComponents; + for (auto i = startPart; i < numParts(); ++i) { + if (isNumericPathComponent(i)) + numericPathComponents.insert(i); + } + return numericPathComponents; +} + StringData FieldRef::dottedField(size_t offset) const { return dottedSubstring(offset, numParts()); } |