summaryrefslogtreecommitdiff
path: root/src/core/RangeSet.hpp
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-16 15:20:49 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-16 15:20:49 +0100
commit9929838e62d9c17647d74be54af5853e8b613c4b (patch)
tree732446f234419a0f1baa5208722e9236affd74bc /src/core/RangeSet.hpp
parent8cf24170a4998e316c1b9c9bfd2b56e266c544cd (diff)
validate function for Domain::Descriptor.
Diffstat (limited to 'src/core/RangeSet.hpp')
-rw-r--r--src/core/RangeSet.hpp51
1 files changed, 47 insertions, 4 deletions
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<Range<T>, RangeComp<T>>::iterator firstOverlapping(
- const Range<T> &r, const bool allowNeighbours)
+ const Range<T> &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<T> &r)
+ bool contains(const Range<T> &r) const
{
auto it = firstOverlapping(r, false);
if (it != ranges.end()) {
@@ -275,12 +275,29 @@ public:
}
/**
+ * 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<T> &s)
+ bool contains(const RangeSet<T> &s) const
{
bool res = true;
for (Range<T> &r : s.ranges) {
@@ -290,6 +307,29 @@ public:
}
/**
+ * 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<T> &r : ranges) {
+ if (r.end > max) {
+ max = r.end;
+ }
+ }
+ return std::move(max);
+ }
+
+ /**
* Empties the set.
*/
void clear() { ranges.clear(); }
@@ -297,7 +337,10 @@ public:
/**
* Returns the current list of ranges as a const reference.
*/
- const std::set<Range<T>, RangeComp<T>> &getRanges() { return this->ranges; }
+ const std::set<Range<T>, RangeComp<T>> &getRanges() const
+ {
+ return this->ranges;
+ }
};
}