From 28bc9da57bcb187adb4ef4c48d34840f12efbc30 Mon Sep 17 00:00:00 2001 From: bangerth Date: Sat, 10 Oct 2009 02:34:25 +0000 Subject: [PATCH] Further along with merging ranges. git-svn-id: https://svn.dealii.org/trunk@19798 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/source/index_set.cc | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/deal.II/base/source/index_set.cc b/deal.II/base/source/index_set.cc index be02d748cc..f19984c9b2 100644 --- a/deal.II/base/source/index_set.cc +++ b/deal.II/base/source/index_set.cc @@ -57,9 +57,45 @@ IndexSet::compress () const } - // we can roll any of + // next see if we can roll any of // the individual entries into the // contiguous ranges + + + // finally see if any of the + // contiguous ranges can be + // merged. since they are sorted by + // their first index, determining + // overlap isn't all that hard + for (std::set::iterator + i = contiguous_ranges.begin(); + i != contiguous_ranges.end(); + ++i) + { + std::set::const_iterator + next = i; + ++next; + + if (next != contiguous_ranges.end()) + if (next->first <= i->second) + { + const unsigned int first_index = i->first; + const unsigned int last_index = next->second; + + // delete the two old + // ranges and insert the + // new range + contiguous_ranges.erase (i, ++next); + contiguous_ranges.insert (ContiguousRange(first_index, + last_index)); + + // then set iterator to + // the same position as + // before + i = contiguous_ranges.lower_bound (ContiguousRange(first_index, + last_index)); + } + } } -- 2.39.5