* A type that denotes an index
* range.
*/
- typedef std::pair<unsigned int, unsigned int> ContiguousRange;
+ typedef std::pair<unsigned int, unsigned int> Range;
/**
* A structure that provides an
*/
struct RangeComparison
{
- bool operator() (const ContiguousRange &range_1,
- const ContiguousRange &range_2) const;
+ bool operator() (const Range &range_1,
+ const Range &range_2) const;
};
/**
* representation of this index
* set.
*/
- mutable std::set<ContiguousRange, RangeComparison> contiguous_ranges;
+ mutable std::set<Range, RangeComparison> ranges;
/**
* The overall size of the index
inline
bool
-IndexSet::RangeComparison::operator() (const ContiguousRange &range_1,
- const ContiguousRange &range_2) const
+IndexSet::RangeComparison::operator() (const Range &range_1,
+ const Range &range_2) const
{
return ((range_1.first < range_2.first)
||
void
IndexSet::set_size (const unsigned int sz)
{
- Assert (contiguous_ranges.size() == 0,
+ Assert (ranges.size() == 0,
ExcMessage ("This function can only be called if the current "
"object does not yet contain any elements."));
index_space_size = sz;
if (end == begin+1)
add_index (begin);
else
- contiguous_ranges.insert (ContiguousRange(begin,end));
+ ranges.insert (Range(begin,end));
}
}
Assert (index < index_space_size,
ExcIndexRange (index, 0, index_space_size));
- contiguous_ranges.insert (ContiguousRange(index, index+1));
+ ranges.insert (Range(index, index+1));
}
//TODO: since the list of ranges is sorted, we be faster here by doing a binary search
// if not, we need to walk the list
// of contiguous ranges:
- if (contiguous_ranges.size() > 0)
- for (std::set<ContiguousRange, RangeComparison>::const_iterator
- i = contiguous_ranges.begin();
- i != contiguous_ranges.end();
+ if (ranges.size() > 0)
+ for (std::set<Range, RangeComparison>::const_iterator
+ i = ranges.begin();
+ i != ranges.end();
++i)
if ((index >= i->first) && (index < i->second))
return true;
IndexSet::is_contiguous () const
{
compress ();
- return (contiguous_ranges.size() <= 1);
+ return (ranges.size() <= 1);
}
compress ();
unsigned int s = 0;
- for (std::set<ContiguousRange, RangeComparison>::iterator
- range = contiguous_ranges.begin();
- range != contiguous_ranges.end();
+ for (std::set<Range, RangeComparison>::iterator
+ range = ranges.begin();
+ range != ranges.end();
++range)
s += (range->second - range->first);
Assert (n < n_elements(), ExcIndexRange (n, 0, n_elements()));
Assert (is_contiguous(), ExcNotImplemented());
- return (n+contiguous_ranges.begin()->first);
+ return (n+ranges.begin()->first);
}
Assert (n < size(), ExcIndexRange (n, 0, size()));
Assert (is_contiguous(), ExcNotImplemented());
- return (n-contiguous_ranges.begin()->first);
+ return (n-ranges.begin()->first);
}
// merged. since they are sorted by
// their first index, determining
// overlap isn't all that hard
- for (std::set<ContiguousRange, RangeComparison>::iterator
- i = contiguous_ranges.begin();
- i != contiguous_ranges.end();
+ for (std::set<Range, RangeComparison>::iterator
+ i = ranges.begin();
+ i != ranges.end();
++i)
{
- std::set<ContiguousRange, RangeComparison>::const_iterator
+ std::set<Range, RangeComparison>::const_iterator
next = i;
++next;
// see if we can merge any of
// the following ranges
bool can_merge = false;
- while (next != contiguous_ranges.end() &&
+ while (next != ranges.end() &&
(next->first <= last_index))
{
last_index = next->second;
// delete the old
// ranges and insert the
// new range
- contiguous_ranges.erase (i, next);
- contiguous_ranges.insert (ContiguousRange(first_index,
- last_index));
+ ranges.erase (i, next);
+ ranges.insert (Range(first_index,
+ last_index));
// then set iterator to
// the same position as
// sure we gobble up as
// many of the following
// ranges as possible
- i = contiguous_ranges.lower_bound (ContiguousRange(first_index,
- last_index));
+ i = ranges.lower_bound (Range(first_index,
+ last_index));
}
}
}