diff options
Diffstat (limited to 'Firestore/core/src/firebase/firestore/model/field_mask.h')
-rw-r--r-- | Firestore/core/src/firebase/firestore/model/field_mask.h | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Firestore/core/src/firebase/firestore/model/field_mask.h b/Firestore/core/src/firebase/firestore/model/field_mask.h index b895ab3..431e05a 100644 --- a/Firestore/core/src/firebase/firestore/model/field_mask.h +++ b/Firestore/core/src/firebase/firestore/model/field_mask.h @@ -23,6 +23,7 @@ #include <vector> #include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/util/hashing.h" namespace firebase { namespace firestore { @@ -55,6 +56,22 @@ class FieldMask { return fields_.end(); } + /** + * Verifies that `fieldPath` is included by at least one field in this field + * mask. + * + * This is an O(n) operation, where `n` is the size of the field mask. + */ + bool covers(const FieldPath& fieldPath) const { + for (const FieldPath& fieldMaskPath : fields_) { + if (fieldMaskPath.IsPrefixOf(fieldPath)) { + return true; + } + } + + return false; + } + std::string ToString() const { // Ideally, one should use a string builder. Since this is only non-critical // code for logging and debugging, the logic is kept simple here. @@ -70,11 +87,7 @@ class FieldMask { } NSUInteger Hash() const { - NSUInteger hashResult = 0; - for (const FieldPath& field : fields_) { - hashResult = hashResult * 31u + field.Hash(); - } - return hashResult; + return util::Hash(fields_); } #endif |