From: Wolfgang Bangerth Date: Thu, 15 Oct 2009 21:18:28 +0000 (+0000) Subject: Make Range a type of its own. X-Git-Tag: v8.0.0~6896 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29d43cd7471884cf995b6004fca007fed3c4836c;p=dealii.git Make Range a type of its own. git-svn-id: https://svn.dealii.org/trunk@19891 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/index_set.h b/deal.II/base/include/base/index_set.h index 0a565c5b5b..2232fe23ef 100644 --- a/deal.II/base/include/base/index_set.h +++ b/deal.II/base/include/base/index_set.h @@ -151,19 +151,28 @@ class IndexSet private: /** - * A type that denotes an index - * range. - */ - typedef std::pair Range; - - /** - * A structure that provides an - * ordering to ranges. + * A type that denotes the half + * open index range + * [begin,end). */ - struct RangeComparison + struct Range { - bool operator() (const Range &range_1, - const Range &range_2) const; + unsigned int begin; + unsigned int end; + + Range (const unsigned int i1, + const unsigned int i2); + + friend + inline bool operator< (const Range &range_1, + const Range &range_2) + { + return ((range_1.begin < range_2.begin) + || + ((range_1.begin == range_2.begin) + && + (range_1.end < range_2.end))); + } }; /** @@ -179,7 +188,7 @@ class IndexSet * representation of this index * set. */ - mutable std::set ranges; + mutable std::set ranges; /** * True if compress() has been @@ -209,16 +218,12 @@ class IndexSet /* ------------------ inline functions ------------------ */ inline -bool -IndexSet::RangeComparison::operator() (const Range &range_1, - const Range &range_2) const -{ - return ((range_1.first < range_2.first) - || - ((range_1.first == range_2.first) - && - (range_1.second < range_2.second))); -} +IndexSet::Range::Range (const unsigned int i1, + const unsigned int i2) + : + begin(i1), + end(i2) +{} @@ -332,11 +337,11 @@ IndexSet::is_element (const unsigned int index) const // if not, we need to walk the list // of contiguous ranges: if (ranges.size() > 0) - for (std::set::const_iterator + for (std::set::const_iterator i = ranges.begin(); i != ranges.end(); ++i) - if ((index >= i->first) && (index < i->second)) + if ((index >= i->begin) && (index < i->end)) return true; // didn't find this index, so it's @@ -366,11 +371,10 @@ IndexSet::n_elements () const compress (); unsigned int s = 0; - for (std::set::iterator - range = ranges.begin(); + for (std::set::iterator range = ranges.begin(); range != ranges.end(); ++range) - s += (range->second - range->first); + s += (range->end - range->begin); return s; } @@ -384,7 +388,7 @@ IndexSet::nth_index_in_set (const unsigned int n) const Assert (n < n_elements(), ExcIndexRange (n, 0, n_elements())); Assert (is_contiguous(), ExcNotImplemented()); - return (n+ranges.begin()->first); + return (n+ranges.begin()->begin); } @@ -398,7 +402,7 @@ IndexSet::index_within_set (const unsigned int n) const Assert (n < size(), ExcIndexRange (n, 0, size())); Assert (is_contiguous(), ExcNotImplemented()); - return (n-ranges.begin()->first); + return (n-ranges.begin()->begin); } diff --git a/deal.II/base/source/index_set.cc b/deal.II/base/source/index_set.cc index 3b24d41360..618a29067b 100644 --- a/deal.II/base/source/index_set.cc +++ b/deal.II/base/source/index_set.cc @@ -25,25 +25,25 @@ IndexSet::compress () const // merged. since they are sorted by // their first index, determining // overlap isn't all that hard - for (std::set::iterator + for (std::set::iterator i = ranges.begin(); i != ranges.end(); ++i) { - std::set::const_iterator + std::set::const_iterator next = i; ++next; - unsigned int first_index = i->first; - unsigned int last_index = i->second; + unsigned int first_index = i->begin; + unsigned int last_index = i->end; // see if we can merge any of // the following ranges bool can_merge = false; while (next != ranges.end() && - (next->first <= last_index)) + (next->begin <= last_index)) { - last_index = next->second; + last_index = next->end; ++next; can_merge = true; }