From 9929838e62d9c17647d74be54af5853e8b613c4b Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 16 Jan 2015 15:20:49 +0100 Subject: validate function for Domain::Descriptor. --- src/core/RangeSet.hpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'src/core/RangeSet.hpp') diff --git a/src/core/RangeSet.hpp b/src/core/RangeSet.hpp index 3b351c3..2c138dc 100644 --- a/src/core/RangeSet.hpp +++ b/src/core/RangeSet.hpp @@ -205,7 +205,7 @@ protected: * end of the list if no such element was found. */ typename std::set, RangeComp>::iterator firstOverlapping( - const Range &r, const bool allowNeighbours) + const Range &r, const bool allowNeighbours) const { // Find the element with the next larger start value compared to the // start value given in r. @@ -265,7 +265,7 @@ public: * @param r is the range for which the containment should be checked. * @return true if the above condition is met, false otherwise. */ - bool contains(const Range &r) + bool contains(const Range &r) const { auto it = firstOverlapping(r, false); if (it != ranges.end()) { @@ -274,13 +274,30 @@ public: return false; } + /** + * Checks whether this range Set S contains a given value v, which is + * the case if at least one contained range R contains v. + * + * @param v is some value. + * @return true if at least one Range r returns true for r.inRange(v) + */ + bool contains(const T &v) const + { + for (auto &r : ranges) { + if (r.inRange(v)) { + return true; + } + } + return false; + } + /** * Checks whether this range set S1 contains the given range set S2: * * @param s is the range for which the containment should be checked. * @return true if the above condition is met, false otherwise. */ - bool contains(const RangeSet &s) + bool contains(const RangeSet &s) const { bool res = true; for (Range &r : s.ranges) { @@ -289,6 +306,29 @@ public: return res; } + /** + * Returns the minimum value that is still covered by this RangeSet. + * + * @return the minimum value that is still covered by this RangeSet. + */ + T min() const { return ranges.begin()->start; } + + /** + * Returns the maximum value that is still covered by this RangeSet. + * + * @return the maximum value that is still covered by this RangeSet. + */ + T max() const + { + T max = ranges.begin()->end; + for (Range &r : ranges) { + if (r.end > max) { + max = r.end; + } + } + return std::move(max); + } + /** * Empties the set. */ @@ -297,7 +337,10 @@ public: /** * Returns the current list of ranges as a const reference. */ - const std::set, RangeComp> &getRanges() { return this->ranges; } + const std::set, RangeComp> &getRanges() const + { + return this->ranges; + } }; } -- cgit v1.2.3