private:
/**
- * A type that denotes an index
- * range.
- */
- typedef std::pair<unsigned int, unsigned int> Range;
-
- /**
- * A structure that provides an
- * ordering to ranges.
+ * A type that denotes the half
+ * open index range
+ * <code>[begin,end)</code>.
*/
- 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)));
+ }
};
/**
* representation of this index
* set.
*/
- mutable std::set<Range, RangeComparison> ranges;
+ mutable std::set<Range> ranges;
/**
* True if compress() has been
/* ------------------ 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)
+{}
// if not, we need to walk the list
// of contiguous ranges:
if (ranges.size() > 0)
- for (std::set<Range, RangeComparison>::const_iterator
+ for (std::set<Range>::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
compress ();
unsigned int s = 0;
- for (std::set<Range, RangeComparison>::iterator
- range = ranges.begin();
+ for (std::set<Range>::iterator range = ranges.begin();
range != ranges.end();
++range)
- s += (range->second - range->first);
+ s += (range->end - range->begin);
return s;
}
Assert (n < n_elements(), ExcIndexRange (n, 0, n_elements()));
Assert (is_contiguous(), ExcNotImplemented());
- return (n+ranges.begin()->first);
+ return (n+ranges.begin()->begin);
}
Assert (n < size(), ExcIndexRange (n, 0, size()));
Assert (is_contiguous(), ExcNotImplemented());
- return (n-ranges.begin()->first);
+ return (n-ranges.begin()->begin);
}
// merged. since they are sorted by
// their first index, determining
// overlap isn't all that hard
- for (std::set<Range, RangeComparison>::iterator
+ for (std::set<Range>::iterator
i = ranges.begin();
i != ranges.end();
++i)
{
- std::set<Range, RangeComparison>::const_iterator
+ std::set<Range>::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;
}