diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/query/interval.h | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/query/interval.h')
-rw-r--r-- | src/mongo/db/query/interval.h | 275 |
1 files changed, 136 insertions, 139 deletions
diff --git a/src/mongo/db/query/interval.h b/src/mongo/db/query/interval.h index e4f82da8088..88309d33e05 100644 --- a/src/mongo/db/query/interval.h +++ b/src/mongo/db/query/interval.h @@ -33,164 +33,161 @@ namespace mongo { - /** A range of values for one field. */ - struct Interval { - - // No BSONValue means we have to keep a BSONObj and pointers (BSONElement) into it. - // 'start' may not point at the first field in _intervalData. - // 'end' may not point at the last field in _intervalData. - // 'start' and 'end' may point at the same field. - BSONObj _intervalData; - - // Start and End must be ordered according to the index order. - BSONElement start; - bool startInclusive; - - BSONElement end; - bool endInclusive; - - /** Creates an empty interval */ - Interval(); - - std::string toString() const { - mongoutils::str::stream ss; - if (startInclusive) { - ss << "["; - } - else { - ss << "("; - } - // false means omit the field name - ss << start.toString(false); - ss << ", "; - ss << end.toString(false); - if (endInclusive) { - ss << "]"; - } - else { - ss << ")"; - } - return ss; +/** A range of values for one field. */ +struct Interval { + // No BSONValue means we have to keep a BSONObj and pointers (BSONElement) into it. + // 'start' may not point at the first field in _intervalData. + // 'end' may not point at the last field in _intervalData. + // 'start' and 'end' may point at the same field. + BSONObj _intervalData; + + // Start and End must be ordered according to the index order. + BSONElement start; + bool startInclusive; + + BSONElement end; + bool endInclusive; + + /** Creates an empty interval */ + Interval(); + + std::string toString() const { + mongoutils::str::stream ss; + if (startInclusive) { + ss << "["; + } else { + ss << "("; } + // false means omit the field name + ss << start.toString(false); + ss << ", "; + ss << end.toString(false); + if (endInclusive) { + ss << "]"; + } else { + ss << ")"; + } + return ss; + } - /** - * Creates an interval that starts at the first field of 'base' and ends at the second - * field of 'base'. (In other words, 'base' is a bsonobj with at least two elements, of - * which we don't care about field names.) - * - * The interval's extremities are closed or not depending on whether - * 'start'/'endIncluded' are true or not. - */ - Interval(BSONObj base, bool startIncluded, bool endIncluded); - - /** Sets the current interval to the given values (see constructor) */ - void init(BSONObj base, bool startIncluded, bool endIncluded); - - /** - * Returns true if an empty-constructed interval hasn't been init()-ialized yet - */ - bool isEmpty() const; - - /** - * Does this interval represent exactly one point? - */ - bool isPoint() const; - - /** - * Returns true if start is same as end and interval is open at either end - */ - bool isNull() const; - + /** + * Creates an interval that starts at the first field of 'base' and ends at the second + * field of 'base'. (In other words, 'base' is a bsonobj with at least two elements, of + * which we don't care about field names.) + * + * The interval's extremities are closed or not depending on whether + * 'start'/'endIncluded' are true or not. + */ + Interval(BSONObj base, bool startIncluded, bool endIncluded); + + /** Sets the current interval to the given values (see constructor) */ + void init(BSONObj base, bool startIncluded, bool endIncluded); + + /** + * Returns true if an empty-constructed interval hasn't been init()-ialized yet + */ + bool isEmpty() const; + + /** + * Does this interval represent exactly one point? + */ + bool isPoint() const; + + /** + * Returns true if start is same as end and interval is open at either end + */ + bool isNull() const; + + // + // Comparison with other intervals + // + + /** + * Returns true if 'this' is the same interval as 'other' + */ + bool equals(const Interval& other) const; + + /** + * Returns true if 'this' overlaps with 'other', false otherwise. + */ + bool intersects(const Interval& rhs) const; + + /** + * Returns true if 'this' is within 'other', false otherwise. + */ + bool within(const Interval& other) const; + + /** + * Returns true if 'this' is located before 'other', false otherwise. + */ + bool precedes(const Interval& other) const; + + /** Returns how 'this' compares to 'other' */ + enum IntervalComparison { // - // Comparison with other intervals + // There is some intersection. // - /** - * Returns true if 'this' is the same interval as 'other' - */ - bool equals(const Interval& other) const; - - /** - * Returns true if 'this' overlaps with 'other', false otherwise. - */ - bool intersects(const Interval& rhs) const; + // The two intervals are *exactly* equal. + INTERVAL_EQUALS, - /** - * Returns true if 'this' is within 'other', false otherwise. - */ - bool within(const Interval& other) const; + // 'this' contains the other interval. + INTERVAL_CONTAINS, - /** - * Returns true if 'this' is located before 'other', false otherwise. - */ - bool precedes(const Interval& other) const; + // 'this' is contained by the other interval. + INTERVAL_WITHIN, - /** Returns how 'this' compares to 'other' */ - enum IntervalComparison { - // - // There is some intersection. - // + // The two intervals intersect and 'this' is before the other interval. + INTERVAL_OVERLAPS_BEFORE, - // The two intervals are *exactly* equal. - INTERVAL_EQUALS, + // The two intervals intersect and 'this is after the other interval. + INTERVAL_OVERLAPS_AFTER, - // 'this' contains the other interval. - INTERVAL_CONTAINS, - - // 'this' is contained by the other interval. - INTERVAL_WITHIN, - - // The two intervals intersect and 'this' is before the other interval. - INTERVAL_OVERLAPS_BEFORE, + // + // There is no intersection. + // - // The two intervals intersect and 'this is after the other interval. - INTERVAL_OVERLAPS_AFTER, + INTERVAL_PRECEDES, - // - // There is no intersection. - // + // This happens if we have [a,b) [b,c] + INTERVAL_PRECEDES_COULD_UNION, - INTERVAL_PRECEDES, + INTERVAL_SUCCEEDS, - // This happens if we have [a,b) [b,c] - INTERVAL_PRECEDES_COULD_UNION, + INTERVAL_UNKNOWN + }; - INTERVAL_SUCCEEDS, + IntervalComparison compare(const Interval& other) const; - INTERVAL_UNKNOWN - }; + /** + * toString for IntervalComparison + */ + static std::string cmpstr(IntervalComparison c); - IntervalComparison compare(const Interval& other) const; + // + // Mutation of intervals + // - /** - * toString for IntervalComparison - */ - static std::string cmpstr(IntervalComparison c); + /** + * Swap start and end points of interval. + */ + void reverse(); - // - // Mutation of intervals - // + /** + * Updates 'this' with the intersection of 'this' and 'other'. If 'this' and 'other' + * have been compare()d before, that result can be optionally passed in 'cmp' + */ + void intersect(const Interval& other, IntervalComparison cmp = INTERVAL_UNKNOWN); - /** - * Swap start and end points of interval. - */ - void reverse(); - - /** - * Updates 'this' with the intersection of 'this' and 'other'. If 'this' and 'other' - * have been compare()d before, that result can be optionally passed in 'cmp' - */ - void intersect(const Interval& other, IntervalComparison cmp = INTERVAL_UNKNOWN); - - /** - * Updates 'this" with the union of 'this' and 'other'. If 'this' and 'other' have - * been compare()d before, that result can be optionaly passed in 'cmp'. - */ - void combine(const Interval& other, IntervalComparison cmp = INTERVAL_UNKNOWN); - }; + /** + * Updates 'this" with the union of 'this' and 'other'. If 'this' and 'other' have + * been compare()d before, that result can be optionaly passed in 'cmp'. + */ + void combine(const Interval& other, IntervalComparison cmp = INTERVAL_UNKNOWN); +}; - inline bool operator==(const Interval& lhs, const Interval& rhs) { - return lhs.compare(rhs) == Interval::INTERVAL_EQUALS; - } +inline bool operator==(const Interval& lhs, const Interval& rhs) { + return lhs.compare(rhs) == Interval::INTERVAL_EQUALS; +} -} // namespace mongo +} // namespace mongo |